From 54a4b0339efd0f573bb771de8c1123e05ef566d2 Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Tue, 15 Oct 2024 09:40:02 -0700 Subject: [PATCH 1/3] don't compute if no pinhole --- hexrd/instrument/detector.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/hexrd/instrument/detector.py b/hexrd/instrument/detector.py index 085790b4..da9f40db 100644 --- a/hexrd/instrument/detector.py +++ b/hexrd/instrument/detector.py @@ -1745,22 +1745,28 @@ def calc_transmission_window(self, secb: np.array, energy: np.floating, def calc_effective_pinhole_area(self, physics_package: AbstractPhysicsPackage) -> np.array: """get the effective pinhole area correction """ - hod = (physics_package.pinhole_thickness / - physics_package.pinhole_diameter) - bvec = self.bvec + effective_pinhole_area = np.ones(self.shape) - tth, eta = self.pixel_angles() - angs = np.vstack((tth.flatten(), eta.flatten(), - np.zeros(tth.flatten().shape))).T - dvecs = angles_to_dvec(angs, beam_vec=bvec) + if (physics_package.pinhole_diameter !=0. + and physics_package.pinhole_thickness != 0.): + + hod = (physics_package.pinhole_thickness / + physics_package.pinhole_diameter) + bvec = self.bvec + + tth, eta = self.pixel_angles() + angs = np.vstack((tth.flatten(), eta.flatten(), + np.zeros(tth.flatten().shape))).T + dvecs = angles_to_dvec(angs, beam_vec=bvec) + + cth = -dvecs[:,2].reshape(self.shape) + tanth = np.tan(np.arccos(cth)) + f = hod*tanth + f[np.abs(f) > 1.] = np.nan + asinf = np.arcsin(f) + effective_pinhole_area = ( + (2/np.pi) * cth * (np.pi/2 - asinf - f*np.cos(asinf))) - cth = -dvecs[:,2].reshape(self.shape) - tanth = np.tan(np.arccos(cth)) - f = hod*tanth - f[np.abs(f) > 1.] = np.nan - asinf = np.arcsin(f) - effective_pinhole_area = ( - (2/np.pi) * cth * (np.pi/2 - asinf - f*np.cos(asinf))) return effective_pinhole_area def calc_transmission_generic(self, From 75cf35a40bae6a65af51a4360f101a87efc2616a Mon Sep 17 00:00:00 2001 From: Saransh Singh Date: Mon, 21 Oct 2024 10:28:09 -0700 Subject: [PATCH 2/3] PEP8 --- hexrd/instrument/detector.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/hexrd/instrument/detector.py b/hexrd/instrument/detector.py index da9f40db..64705433 100644 --- a/hexrd/instrument/detector.py +++ b/hexrd/instrument/detector.py @@ -171,7 +171,6 @@ def beam_position(self): """ raise NotImplementedError - @property def extra_config_kwargs(self): return {} @@ -289,7 +288,8 @@ def __init__( self.group = group if detector_filter is None: - detector_filter = detector_coatings.Filter(**FILTER_DEFAULTS.TARDIS) + detector_filter = detector_coatings.Filter( + **FILTER_DEFAULTS.TARDIS) self.filter = detector_filter if detector_coating is None: @@ -1709,7 +1709,7 @@ def calc_physics_package_transmission(self, energy: np.floating, need to consider HED and HEDM samples separately """ bvec = self.bvec - sample_normal = np.dot(rMat_s, [0.,0.,-1.]) + sample_normal = np.dot(rMat_s, [0., 0., -1.]) seca = 1./np.dot(bvec, sample_normal) tth, eta = self.pixel_angles() @@ -1720,7 +1720,8 @@ def calc_physics_package_transmission(self, energy: np.floating, secb = np.abs(1./np.dot(dvecs, sample_normal).reshape(self.shape)) - T_sample = self.calc_transmission_sample(seca, secb, energy, physics_package) + T_sample = self.calc_transmission_sample( + seca, secb, energy, physics_package) T_window = self.calc_transmission_window(secb, energy, physics_package) transmission_physics_package = T_sample * T_window @@ -1729,8 +1730,9 @@ def calc_physics_package_transmission(self, energy: np.floating, def calc_transmission_sample(self, seca: np.array, secb: np.array, energy: np.floating, physics_package: AbstractPhysicsPackage) -> np.array: - thickness_s = physics_package.sample_thickness # in microns - mu_s = 1./physics_package.sample_absorption_length(energy) # in microns^-1 + thickness_s = physics_package.sample_thickness # in microns + # in microns^-1 + mu_s = 1./physics_package.sample_absorption_length(energy) x = (mu_s*thickness_s) pre = 1./x/(secb - seca) num = np.exp(-x*seca) - np.exp(-x*secb) @@ -1738,8 +1740,9 @@ def calc_transmission_sample(self, seca: np.array, def calc_transmission_window(self, secb: np.array, energy: np.floating, physics_package: AbstractPhysicsPackage) -> np.array: - thickness_w = physics_package.window_thickness # in microns - mu_w = 1./physics_package.window_absorption_length(energy) # in microns^-1 + thickness_w = physics_package.window_thickness # in microns + # in microns^-1 + mu_w = 1./physics_package.window_absorption_length(energy) return np.exp(-thickness_w*mu_w*secb) def calc_effective_pinhole_area(self, physics_package: AbstractPhysicsPackage) -> np.array: @@ -1747,8 +1750,8 @@ def calc_effective_pinhole_area(self, physics_package: AbstractPhysicsPackage) - """ effective_pinhole_area = np.ones(self.shape) - if (physics_package.pinhole_diameter !=0. - and physics_package.pinhole_thickness != 0.): + if (physics_package.pinhole_diameter != 0. + and physics_package.pinhole_thickness != 0.): hod = (physics_package.pinhole_thickness / physics_package.pinhole_diameter) @@ -1756,10 +1759,10 @@ def calc_effective_pinhole_area(self, physics_package: AbstractPhysicsPackage) - tth, eta = self.pixel_angles() angs = np.vstack((tth.flatten(), eta.flatten(), - np.zeros(tth.flatten().shape))).T + np.zeros(tth.flatten().shape))).T dvecs = angles_to_dvec(angs, beam_vec=bvec) - cth = -dvecs[:,2].reshape(self.shape) + cth = -dvecs[:, 2].reshape(self.shape) tanth = np.tan(np.arccos(cth)) f = hod*tanth f[np.abs(f) > 1.] = np.nan @@ -1773,7 +1776,7 @@ def calc_transmission_generic(self, secb: np.array, thickness: np.floating, absorption_length: np.floating) -> np.array: - mu = 1./absorption_length # in microns^-1 + mu = 1./absorption_length # in microns^-1 return np.exp(-thickness*mu*secb) def calc_transmission_phosphor(self, From 59a846265e9f9b4787f14cbc06604821204e8609 Mon Sep 17 00:00:00 2001 From: Saransh Date: Thu, 14 Nov 2024 16:14:32 -0800 Subject: [PATCH 3/3] Update hexrd/instrument/detector.py Co-authored-by: Patrick Avery --- hexrd/instrument/detector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hexrd/instrument/detector.py b/hexrd/instrument/detector.py index 64705433..49b4f52e 100644 --- a/hexrd/instrument/detector.py +++ b/hexrd/instrument/detector.py @@ -1750,8 +1750,8 @@ def calc_effective_pinhole_area(self, physics_package: AbstractPhysicsPackage) - """ effective_pinhole_area = np.ones(self.shape) - if (physics_package.pinhole_diameter != 0. - and physics_package.pinhole_thickness != 0.): + if (not np.isclose(physics_package.pinhole_diameter, 0) + and not np.isclose(physics_package.pinhole_thickness, 0)): hod = (physics_package.pinhole_thickness / physics_package.pinhole_diameter)