Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absorption correction #649

Merged
merged 50 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
75cef15
New packaging for performing absorption corrections
saransh13 Sep 27, 2023
7785d0c
define some properties.
saransh13 Oct 2, 2023
1b02400
added some description
saransh13 Mar 1, 2024
540c7fc
start adding code for sample+window absorption correction
saransh13 Mar 1, 2024
036e0d9
add more code. almost done with this code now
saransh13 Mar 1, 2024
08454ec
adding final few attributes
saransh13 Mar 1, 2024
5953137
filterpack tested. still. need to test sample and window absorptions
saransh13 Mar 1, 2024
430ebba
functions work, but does not look physical at the moment
saransh13 Mar 2, 2024
b74b437
fixed the transformation
saransh13 Apr 25, 2024
8b0b6de
many more helper routines to compute the absorption length based on f…
saransh13 Apr 26, 2024
57b34bb
switching back to the old Anomalous.h5 file.
saransh13 Apr 26, 2024
3a86f0b
filter and coating definitions are now on the detector class itself.
saransh13 Apr 26, 2024
00f5a99
fixed the signs and moved all absorption calculations to the instrume…
saransh13 Apr 27, 2024
bf67fd9
everything in the instrument class now. everything runs. coating+filt…
saransh13 Apr 28, 2024
e6cb3a1
calculate overall transmission
saransh13 Apr 29, 2024
4188f66
add effective pinhole area correction
saransh13 Apr 29, 2024
c1e1642
added phosphor absorption
saransh13 Apr 29, 2024
f5e3fb4
fix typo
saransh13 Apr 29, 2024
1abbf08
new class for sample, pinhole, filter, coatings etc.
saransh13 May 24, 2024
f62e751
make everything tie back to the abstractlayer class, and add absorpti…
saransh13 May 24, 2024
6233315
tested code for physics package
saransh13 May 25, 2024
a7af3fc
tested initialization of instrument with default values. Still need t…
saransh13 May 25, 2024
0c4bf36
tested transmission functions.
saransh13 May 25, 2024
2e9eb9a
remove unnecessary properties and fix the ones that need to be modified
saransh13 May 25, 2024
8fa823f
Use identity by default for rMat_s in transmission
psavery Jun 21, 2024
4783872
Some minor bug fixes
Jul 3, 2024
e0d24d9
Add setters where needed
Aug 14, 2024
056d02a
Correct const capitalization
Sep 7, 2024
e96980c
Minor code cleanup
Sep 7, 2024
171d952
Add chemparse to conda requirements
Sep 7, 2024
c7fc097
Do not use global defaults
Sep 7, 2024
55213d7
Move contants to their own file
Sep 7, 2024
57454b3
Combine pinhole with physics package
Sep 7, 2024
caac83e
Move physics package to instrument level
Sep 15, 2024
d902388
Rename sample.py -> physics_package.py; move to instrument
Sep 15, 2024
a2da4c0
Separate physics package from detector coatings
Sep 15, 2024
907fd5a
Allow physics package to be None
Sep 15, 2024
0ff675f
Remove left over debug statement
Sep 17, 2024
687add5
Set physics package and detecor coatings from config if provided
Sep 17, 2024
137da0e
Add missing setters for phosphor
Sep 19, 2024
df313e7
Explicitly list attributes to serialize
Sep 19, 2024
d1a3b30
Fix default arguments for physics package classes
Sep 19, 2024
7168d35
Fix some incorrectly resolved conflicts
Sep 19, 2024
530d497
Keep all resource files in HEXRD
Sep 20, 2024
cd721e0
Disable codecov GitHub annotations
psavery Sep 23, 2024
ed5fd60
Add some type annotations and improve docstring
psavery Sep 23, 2024
5c1ed3d
Use AbstractPhysicsPackage for type annotations
psavery Sep 23, 2024
126001f
Add a test for absorption correction
psavery Sep 25, 2024
2cabfe9
Add some annotations and alphabetize dependencies
psavery Sep 25, 2024
b528b11
Pin h5py version to less than 3.12
psavery Sep 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage:
status:
patch: false
1 change: 1 addition & 0 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ requirements:

run:
- appdirs
- chemparse
- fabio >=0.11
# fabio uses lxml, and lxml 4.9.1 has some crashing issue on Windows
# so, make sure lxml >= 4.9.2 is being used
Expand Down
95 changes: 85 additions & 10 deletions hexrd/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,17 @@ def is_writable_file(path):


# some physical constants
cAvogadro = 6.02214076E23
cBoltzmann = 1.380649E-23
cCharge = 1.602176634E-19
cJ2eV = 1.602176565E-19
cLight = 299792458.0
cMoment = 9.2740100707E-24
cPermea = 1.2566370616E-6
cPermit = 8.8541878163E-12
cPlanck = 6.62607015E-34
cRestmass = 9.1093837090E-31
cAvogadro = 6.02214076E23 # Avogadro's constant Na
cBoltzmann = 1.380649E-23 # Boltzmann's constant, K
cCharge = 1.602176634E-19 # charge of electron
cJ2eV = 1.602176565E-19 # joule to ev, JperkeV*1e-3
cLight = 299792458.0 # speed of light, same as c above but name is more descriptive
cMoment = 9.2740100707E-24 # magnetic moment of electron
cPermea = 1.2566370616E-6 # permeability of free space
cPermit = 8.8541878163E-12 # permittivity of free space
cPlanck = 6.62607015E-34 # same as h above but name is more descriptive
cRestmass = 9.1093837090E-31 # rest mass of electron
cClassicalelectronRad = 2.8179403e-6 # classical electron radius in nm

'''
adding another parametrization of the
Expand Down Expand Up @@ -708,6 +709,80 @@ def is_writable_file(path):
231.03588, 238.02891, 237.0, 244.0, 243.0,
247.0, 247.0, 251.0])

"""
dictionary of atomic weights
"""
ATOM_WEIGHTS_DICT = {'H': 1.00794,'He': 4.002602,'Li': 6.941,
'Be': 9.012182,'B': 10.811,'C': 12.0107,
'N': 14.0067,'O': 15.9994,'F': 18.9984032,
'Ne': 20.1797,'Na': 22.98976928,'Mg': 24.305,
'Al': 26.9815386,'Si': 28.0855,'P': 30.973762,
'S': 32.065,'Cl': 35.453,'Ar': 39.948,
'K': 39.0983,'Ca': 40.078,'Sc': 44.955912,
'Ti': 47.867,'V': 50.9415,'Cr': 51.9961,
'Mn': 54.938045,'Fe': 55.845,'Co': 58.933195,
'Ni': 58.6934,'Cu': 63.546,'Zn': 65.38,
'Ga': 69.723,'Ge': 72.64,'As': 74.9216,
'Se': 78.96,'Br': 79.904,'Kr': 83.798,
'Rb': 85.4678,'Sr': 87.62,'Y': 88.90585,
'Zr': 91.224,'Nb': 92.90638,'Mo': 95.96,
'Tc': 98.9062,'Ru': 101.07,'Rh': 102.9055,
'Pd': 106.42,'Ag': 107.8682,'Cd': 112.411,
'In': 114.818,'Sn': 118.71,'Sb': 121.76,
'Te': 127.6,'I': 126.90447,'Xe': 131.293,
'Cs': 132.9054519,'Ba': 137.327,'La': 138.90547,
'Ce': 140.116,'Pr': 140.90765,'Nd': 144.242,
'Pm': 145.0,'Sm': 150.36,'Eu': 151.964,
'Gd': 157.25,'Tb': 158.92535,'Dy': 162.5,
'Ho': 164.93032,'Er': 167.259,'Tm': 168.93421,
'Yb': 173.054,'Lu': 174.9668,'Hf': 178.49,
'Ta': 180.94788,'W': 183.84,'Re': 186.207,
'Os': 190.23,'Ir': 192.217,'Pt': 195.084,
'Au': 196.966569,'Hg': 200.59,'Tl': 204.3833,
'Pb': 207.2,'Bi': 208.9804,'Po': 209.0,
'At': 210.0,'Rn': 222.0,'Fr': 223.0,'Ra': 226.0,
'Ac': 227.0,'Th': 232.0377,'Pa': 231.03588,
'U': 238.02891,'Np': 237.0,'Pu': 244.0,
'Am': 243.0,'Cm': 247.0,'Bk': 247.0,
'Cf': 251.0}

"""
densities of elements in g/cc
"""
DENSITY = {'H': 8.99e-05,'He': 0.0001785,'Li': 0.535,'Be': 1.848,
'B': 2.46,'C': 2.26,'N': 0.001251,'O': 0.001429,
'F': 0.001696,'Ne': 0.0009,'Na': 0.968,'Mg': 1.738,
'Al': 2.7,'Si': 2.33,'P': 1.823,'S': 1.96,'Cl': 0.003214,
'Ar': 0.001784,'K': 0.856,'Ca': 1.55,'Sc': 2.985,
'Ti': 4.507,'V': 6.11,'Cr': 7.14,'Mn': 7.47,'Fe': 7.874,
'Co': 8.9,'Ni': 8.908,'Cu': 8.92,'Zn': 7.14,'Ga': 5.904,
'Ge': 5.323,'As': 5.727,'Se': 4.819,'Br': 3.12,'Kr': 0.00375,
'Rb': 1.532,'Sr': 2.63,'Y': 4.472,'Zr': 6.511,
'Nb': 8.57,'Mo': 10.28,'Tc': 11.5,'Ru': 12.37,
'Rh': 12.45,'Pd': 12.023,'Ag': 10.49,'Cd': 8.65,
'In': 7.31,'Sn': 7.31,'Sb': 6.697,'Te': 6.24,
'I': 4.94,'Xe': 0.0059,'Cs': 1.879,'Ba': 3.51,
'La': 6.146,'Ce': 6.689,'Pr': 6.64,'Nd': 7.01,
'Pm': 7.264,'Sm': 7.353,'Eu': 5.244,'Gd': 7.901,
'Tb': 8.219,'Dy': 8.551,'Ho': 8.795,'Er': 9.066,
'Tm': 9.321,'Yb': 6.57,'Lu': 9.841,'Hf': 13.31,
'Ta': 16.65,'W': 19.25,'Re': 21.02,'Os': 22.59,
'Ir': 22.56,'Pt': 21.09,'Au': 19.3,'Hg': 13.534,
'Tl': 11.85,'Pb': 11.34,'Bi': 9.78,'Po': 9.196,
'At': None,'Rn': 0.00973,'Fr': None,'Ra': 5.0,
'Ac': 10.07,'Th': 11.724,'Pa': 15.37,'U': 19.05,
'Np': 20.45,'Pu': 19.816,'Am': 13.67,'Cm': 13.51,
'Bk': 14.78,'Cf': 15.1}

# some polymer densities commonly used in hexrd
DENSITY_COMPOUNDS = {
'C10H8O4': 1.4,
'Ba2263F2263Br1923I339C741H1730N247O494': 3.3,
'LiF': 2.64,
'quartz': 2.65,
'diamond': 3.5,
}

'''
dictionary of atomic numbers with element symbol as keys
used in I/O from cif file
Expand Down
64 changes: 64 additions & 0 deletions hexrd/instrument/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from hexrd.constants import DENSITY, DENSITY_COMPOUNDS


# default filter and coating materials
class FILTER_DEFAULTS:
TARDIS = {
'material': 'Ge',
'density' : DENSITY['Ge'],
'thickness' : 10 # microns
}
PXRDIP = {
'material': 'Cu',
'density' : DENSITY['Cu'],
'thickness' : 10 # microns
}

COATING_DEFAULT = {
'material': 'C10H8O4',
'density': DENSITY_COMPOUNDS['C10H8O4'],
'thickness': 9 # microns
}

PHOSPHOR_DEFAULT = {
'material': 'Ba2263F2263Br1923I339C741H1730N247O494',
'density': DENSITY_COMPOUNDS['Ba2263F2263Br1923I339C741H1730N247O494'], # g/cc
'thickness': 115, # microns
'readout_length': 222, #microns
'pre_U0': 0.695
}


class PHYSICS_PACKAGE_DEFAULTS:
# Default physics package for dynamic compression
HED = {
'sample_material': 'Fe',
'sample_density': DENSITY['Fe'],
'sample_thickness': 15, # in microns
'window_material': 'LiF',
'window_density': DENSITY_COMPOUNDS['LiF'],
'window_thickness': 150, # in microns
}
# # Template for HEDM type physics package
# HEDM = {
# 'sample_material': 'Fe',
# 'sample_density': DENSITY['Fe'],
# 'sample_thickness': 1000, # in microns
# 'sample_geometry': 'cylinder'
# }


# Default pinhole area correction parameters
class PINHOLE_DEFAULTS:
TARDIS = {
'pinhole_material' : 'Ta',
'pinhole_diameter' : 400, # in microns
'pinhole_thickness' : 100, # in microns
'pinhole_density' : 16.65, # g/cc
}
PXRDIP = {
'pinhole_material' : 'Ta',
'pinhole_diameter' : 130, # in microns
'pinhole_thickness' : 70, # in microns
'pinhole_density' : 16.65, # g/cc
}
68 changes: 68 additions & 0 deletions hexrd/instrument/cylindrical_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,74 @@ def cart_to_dvecs(self,
def pixel_angles(self, origin=ct.zeros_3):
return _pixel_angles(origin=origin, **self._pixel_angle_kwargs)

def local_normal(self):
"""get the local normal of each pixel in the
cylindrical detector

output will be of shape [nx*ny, 3]
"""
y, x = self.pixel_coords
x = x.flatten()
y = y.flatten()
num = x.shape[0]
naxis = np.cross(self.paxis, self.caxis)

th = x/self.radius
xp = np.sin(th)
xn = -np.cos(th)

pcomp = np.tile(xp, [3, 1]).T * np.tile(self.paxis, [num, 1])
ncomp = np.tile(xn, [3, 1]).T * np.tile(naxis, [num, 1])

cart3d = pcomp + ncomp
return cart3d

def calc_filter_coating_transmission(self, energy):
"""
calculate the transmission after x-ray beam interacts
with the filter and the mylar polymer coating.
Specifications of the polymer coating is taken from:

M. Stoeckl, A. A. Solodov
Readout models for BaFBr0.85I0.15:Eu image plates
Rev. Sci. Instrum. 89, 063101 (2018)

Transmission Formulas are consistent with:

Rygg et al., X-ray diffraction at the National
Ignition Facility, Rev. Sci. Instrum. 91, 043902 (2020)
"""
al_f = self.filter.absorption_length(energy)
al_c = self.coating.absorption_length(energy)
al_p = self.phosphor.energy_absorption_length(energy)

t_f = self.filter.thickness
t_c = self.coating.thickness
t_p = self.phosphor.thickness
L = self.phosphor.readout_length

det_normal = self.local_normal()

y, x = self.pixel_coords
xy_data = np.vstack((x.flatten(), y.flatten())).T
dvecs = self.cart_to_dvecs(xy_data)
dvecs = dvecs/np.tile(np.linalg.norm(dvecs, axis=1), [3, 1]).T

secb = (1./np.sum(dvecs*det_normal, axis=1)).reshape(self.shape)

transmission_filter = self.calc_transmission_generic(secb, t_f, al_f)
transmission_coating = self.calc_transmission_generic(secb, t_c, al_c)
transmission_phosphor = (
self.phosphor.pre_U0 *
self.calc_transmission_phosphor(secb, t_p, al_p, L, energy))

transmission_filter = transmission_filter.reshape(self.shape)
transmission_coating = transmission_coating.reshape(self.shape)
transmission_filter_coating = (
transmission_filter * transmission_coating)

return transmission_filter_coating, transmission_phosphor

@property
def _pixel_angle_kwargs(self):
# kwargs used for pixel angles, pixel_tth_gradient,
Expand Down
Loading
Loading