66import numpy as np
77
88from diffpy .utils .tools import get_package_info
9- from diffpy .utils .transforms import d_to_q , d_to_tth , q_to_d , q_to_tth , tth_to_d , tth_to_q
9+ from diffpy .utils .transforms import (
10+ d_to_q ,
11+ d_to_tth ,
12+ q_to_d ,
13+ q_to_tth ,
14+ tth_to_d ,
15+ tth_to_q ,
16+ )
1017
1118QQUANTITIES = ["q" ]
1219ANGLEQUANTITIES = ["angle" , "tth" , "twotheta" , "2theta" ]
1320DQUANTITIES = ["d" , "dspace" ]
1421XQUANTITIES = ANGLEQUANTITIES + DQUANTITIES + QQUANTITIES
15- XUNITS = ["degrees" , "radians" , "rad" , "deg" , "inv_angs" , "inv_nm" , "nm-1" , "A-1" ]
22+ XUNITS = [
23+ "degrees" ,
24+ "radians" ,
25+ "rad" ,
26+ "deg" ,
27+ "inv_angs" ,
28+ "inv_nm" ,
29+ "nm-1" ,
30+ "A-1" ,
31+ ]
1632
1733x_values_not_equal_emsg = (
1834 "The two objects have different values in x arrays (my_do.all_arrays[:, [1, 2, 3]]). "
@@ -129,9 +145,13 @@ def __init__(
129145 """
130146
131147 self ._uuid = uuid .uuid4 ()
132- self ._input_data (xarray , yarray , xtype , wavelength , scat_quantity , name , metadata )
148+ self ._input_data (
149+ xarray , yarray , xtype , wavelength , scat_quantity , name , metadata
150+ )
133151
134- def _input_data (self , xarray , yarray , xtype , wavelength , scat_quantity , name , metadata ):
152+ def _input_data (
153+ self , xarray , yarray , xtype , wavelength , scat_quantity , name , metadata
154+ ):
135155 if xtype not in XQUANTITIES :
136156 raise ValueError (_xtype_wmsg (xtype ))
137157 if len (xarray ) != len (yarray ):
@@ -152,8 +172,12 @@ def _input_data(self, xarray, yarray, xtype, wavelength, scat_quantity, name, me
152172 def __eq__ (self , other ):
153173 if not isinstance (other , DiffractionObject ):
154174 return NotImplemented
155- self_attributes = [key for key in self .__dict__ if not key .startswith ("_" )]
156- other_attributes = [key for key in other .__dict__ if not key .startswith ("_" )]
175+ self_attributes = [
176+ key for key in self .__dict__ if not key .startswith ("_" )
177+ ]
178+ other_attributes = [
179+ key for key in other .__dict__ if not key .startswith ("_" )
180+ ]
157181 if not sorted (self_attributes ) == sorted (other_attributes ):
158182 return False
159183 for key in self_attributes :
@@ -167,8 +191,13 @@ def __eq__(self, other):
167191 or not np .isclose (value , other_value , rtol = 1e-5 )
168192 ):
169193 return False
170- elif isinstance (value , list ) and all (isinstance (i , np .ndarray ) for i in value ):
171- if not all (np .allclose (i , j , rtol = 1e-5 ) for i , j in zip (value , other_value )):
194+ elif isinstance (value , list ) and all (
195+ isinstance (i , np .ndarray ) for i in value
196+ ):
197+ if not all (
198+ np .allclose (i , j , rtol = 1e-5 )
199+ for i , j in zip (value , other_value )
200+ ):
172201 return False
173202 else :
174203 if value != other_value :
@@ -303,7 +332,9 @@ def _check_operation_compatibility(self, other):
303332 if isinstance (other , DiffractionObject ):
304333 if self .all_arrays .shape != other .all_arrays .shape :
305334 raise ValueError (x_values_not_equal_emsg )
306- if not np .allclose (self .all_arrays [:, [1 , 2 , 3 ]], other .all_arrays [:, [1 , 2 , 3 ]]):
335+ if not np .allclose (
336+ self .all_arrays [:, [1 , 2 , 3 ]], other .all_arrays [:, [1 , 2 , 3 ]]
337+ ):
307338 raise ValueError (x_values_not_equal_emsg )
308339
309340 @property
@@ -381,7 +412,9 @@ def get_array_index(self, xtype, xvalue):
381412 xtype = self ._input_xtype
382413 xarray = self .on_xtype (xtype )[0 ]
383414 if len (xarray ) == 0 :
384- raise ValueError (f"The '{ xtype } ' array is empty. Please ensure it is initialized." )
415+ raise ValueError (
416+ f"The '{ xtype } ' array is empty. Please ensure it is initialized."
417+ )
385418 index = (np .abs (xarray - xvalue )).argmin ()
386419 return index
387420
@@ -447,7 +480,9 @@ def on_d(self):
447480 """
448481 return [self .all_arrays [:, 3 ], self .all_arrays [:, 0 ]]
449482
450- def scale_to (self , target_diff_object , q = None , tth = None , d = None , offset = None ):
483+ def scale_to (
484+ self , target_diff_object , q = None , tth = None , d = None , offset = None
485+ ):
451486 """Return a new diffraction object which is the current object but
452487 rescaled in y to the target.
453488
@@ -486,7 +521,10 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
486521 if count == 0 :
487522 q_target_max = max (target_diff_object .on_q ()[1 ])
488523 q_self_max = max (self .on_q ()[1 ])
489- scaled_do ._all_arrays [:, 0 ] = scaled_do ._all_arrays [:, 0 ] * q_target_max / q_self_max + offset
524+ scaled_do ._all_arrays [:, 0 ] = (
525+ scaled_do ._all_arrays [:, 0 ] * q_target_max / q_self_max
526+ + offset
527+ )
490528 return scaled_do
491529
492530 xtype = "q" if q is not None else "tth" if tth is not None else "d"
@@ -497,7 +535,9 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None):
497535
498536 xindex_data = (np .abs (data [0 ] - xvalue )).argmin ()
499537 xindex_target = (np .abs (target [0 ] - xvalue )).argmin ()
500- scaled_do ._all_arrays [:, 0 ] = data [1 ] * target [1 ][xindex_target ] / data [1 ][xindex_data ] + offset
538+ scaled_do ._all_arrays [:, 0 ] = (
539+ data [1 ] * target [1 ][xindex_target ] / data [1 ][xindex_data ] + offset
540+ )
501541 return scaled_do
502542
503543 def on_xtype (self , xtype ):
@@ -561,12 +601,16 @@ def dump(self, filepath, xtype=None):
561601 if xtype in QQUANTITIES :
562602 data_to_save = np .column_stack ((self .on_q ()[0 ], self .on_q ()[1 ]))
563603 elif xtype in ANGLEQUANTITIES :
564- data_to_save = np .column_stack ((self .on_tth ()[0 ], self .on_tth ()[1 ]))
604+ data_to_save = np .column_stack (
605+ (self .on_tth ()[0 ], self .on_tth ()[1 ])
606+ )
565607 elif xtype in DQUANTITIES :
566608 data_to_save = np .column_stack ((self .on_d ()[0 ], self .on_d ()[1 ]))
567609 else :
568610 warnings .warn (_xtype_wmsg (xtype ))
569- self .metadata .update (get_package_info ("diffpy.utils" , metadata = self .metadata ))
611+ self .metadata .update (
612+ get_package_info ("diffpy.utils" , metadata = self .metadata )
613+ )
570614 self .metadata ["creation_time" ] = datetime .datetime .now ()
571615
572616 with open (filepath , "w" ) as f :
0 commit comments