55import pandas as pd
66from scipy .interpolate import interp1d
77
8- from diffpy .utils .scattering_objects . diffraction_objects import XQUANTITIES , Diffraction_object
8+ from diffpy .utils .diffraction_objects import XQUANTITIES , DiffractionObject
99
1010RADIUS_MM = 1
1111N_POINTS_ON_DIAMETER = 300
1212TTH_GRID = np .arange (1 , 180.1 , 0.1 )
13+ # Round down the last element if it's slightly above 180 due to floating point precision
14+ TTH_GRID [- 1 ] = 180.00
1315CVE_METHODS = ["brute_force" , "polynomial_interpolation" ]
1416
1517# pre-computed datasets for polynomial interpolation (fast calculation)
@@ -191,14 +193,14 @@ def _cve_brute_force(diffraction_data, mud):
191193 muls = np .array (muls ) / abs_correction .total_points_in_grid
192194 cve = 1 / muls
193195
194- cve_do = Diffraction_object (wavelength = diffraction_data .wavelength )
195- cve_do .insert_scattering_quantity (
196- TTH_GRID ,
197- cve ,
198- "tth" ,
199- metadata = diffraction_data .metadata ,
200- name = f"absorption correction, cve, for { diffraction_data .name } " ,
196+ cve_do = DiffractionObject (
197+ xarray = TTH_GRID ,
198+ yarray = cve ,
199+ xtype = "tth" ,
200+ wavelength = diffraction_data .wavelength ,
201201 scat_quantity = "cve" ,
202+ name = f"absorption correction, cve, for { diffraction_data .name } " ,
203+ metadata = diffraction_data .metadata ,
202204 )
203205 return cve_do
204206
@@ -211,22 +213,22 @@ def _cve_polynomial_interpolation(diffraction_data, mud):
211213 if mud > 6 or mud < 0.5 :
212214 raise ValueError (
213215 f"mu*D is out of the acceptable range (0.5 to 6) for polynomial interpolation. "
214- f"Please rerun with a value within this range or specifying another method from { * CVE_METHODS , } ."
216+ f"Please rerun with a value within this range or specifying another method from { * CVE_METHODS , } ."
215217 )
216218 coeff_a , coeff_b , coeff_c , coeff_d , coeff_e = [
217219 interpolation_function (mud ) for interpolation_function in INTERPOLATION_FUNCTIONS
218220 ]
219221 muls = np .array (coeff_a * MULS ** 4 + coeff_b * MULS ** 3 + coeff_c * MULS ** 2 + coeff_d * MULS + coeff_e )
220222 cve = 1 / muls
221223
222- cve_do = Diffraction_object (wavelength = diffraction_data .wavelength )
223- cve_do .insert_scattering_quantity (
224- TTH_GRID ,
225- cve ,
226- "tth" ,
227- metadata = diffraction_data .metadata ,
228- name = f"absorption correction, cve, for { diffraction_data .name } " ,
224+ cve_do = DiffractionObject (
225+ xarray = TTH_GRID ,
226+ yarray = cve ,
227+ xtype = "tth" ,
228+ wavelength = diffraction_data .wavelength ,
229229 scat_quantity = "cve" ,
230+ name = f"absorption correction, cve, for { diffraction_data .name } " ,
231+ metadata = diffraction_data .metadata ,
230232 )
231233 return cve_do
232234
@@ -257,7 +259,7 @@ def compute_cve(diffraction_data, mud, method="polynomial_interpolation", xtype=
257259 xtype str
258260 the quantity on the independent variable axis, allowed values are { * XQUANTITIES , }
259261 method str
260- the method used to calculate cve, must be one of { * CVE_METHODS , }
262+ the method used to calculate cve, must be one of { * CVE_METHODS , }
261263
262264 Returns
263265 -------
@@ -270,14 +272,14 @@ def compute_cve(diffraction_data, mud, method="polynomial_interpolation", xtype=
270272 global_xtype = cve_do_on_global_grid .on_xtype (xtype )[0 ]
271273 cve_on_global_xtype = cve_do_on_global_grid .on_xtype (xtype )[1 ]
272274 newcve = np .interp (orig_grid , global_xtype , cve_on_global_xtype )
273- cve_do = Diffraction_object (wavelength = diffraction_data .wavelength )
274- cve_do .insert_scattering_quantity (
275- orig_grid ,
276- newcve ,
277- xtype ,
278- metadata = diffraction_data .metadata ,
279- name = f"absorption correction, cve, for { diffraction_data .name } " ,
275+ cve_do = DiffractionObject (
276+ xarray = orig_grid ,
277+ yarray = newcve ,
278+ xtype = xtype ,
279+ wavelength = diffraction_data .wavelength ,
280280 scat_quantity = "cve" ,
281+ name = f"absorption correction, cve, for { diffraction_data .name } " ,
282+ metadata = diffraction_data .metadata ,
281283 )
282284 return cve_do
283285
0 commit comments