1111XQUANTITIES = ANGLEQUANTITIES + DQUANTITIES + QQUANTITIES
1212XUNITS = ["degrees" , "radians" , "rad" , "deg" , "inv_angs" , "inv_nm" , "nm-1" , "A-1" ]
1313
14+ x_grid_emsg = (
15+ "objects are not on the same x-grid. You may add them using the self.add method "
16+ "and specifying how to handle the mismatch."
17+ )
18+
1419
1520class Diffraction_object :
1621 def __init__ (self , name = "" , wavelength = None ):
@@ -57,10 +62,7 @@ def __add__(self, other):
5762 elif not isinstance (other , Diffraction_object ):
5863 raise TypeError ("I only know how to sum two Diffraction_object objects" )
5964 elif self .on_tth [0 ].all () != other .on_tth [0 ].all ():
60- raise RuntimeError (
61- "objects are not on the same x-grid. You may add them using the self.add method and"
62- "specifying how to handle the mismatch."
63- )
65+ raise RuntimeError (x_grid_emsg )
6466 else :
6567 summed .on_tth [1 ] = self .on_tth [1 ] + other .on_tth [1 ]
6668 summed .on_q [1 ] = self .on_q [1 ] + other .on_q [1 ]
@@ -74,10 +76,7 @@ def __radd__(self, other):
7476 elif not isinstance (other , Diffraction_object ):
7577 raise TypeError ("I only know how to sum two Scattering_object objects" )
7678 elif self .on_tth [0 ].all () != other .on_tth [0 ].all ():
77- raise RuntimeError (
78- "objects are not on the same x-grid. You may add them using the self.add method and"
79- "specifying how to handle the mismatch."
80- )
79+ raise RuntimeError (x_grid_emsg )
8180 else :
8281 summed .on_tth [1 ] = self .on_tth [1 ] + other .on_tth [1 ]
8382 summed .on_q [1 ] = self .on_q [1 ] + other .on_q [1 ]
@@ -91,10 +90,7 @@ def __sub__(self, other):
9190 elif not isinstance (other , Diffraction_object ):
9291 raise TypeError ("I only know how to subtract two Scattering_object objects" )
9392 elif self .on_tth [0 ].all () != other .on_tth [0 ].all ():
94- raise RuntimeError (
95- "objects are not on the same x-grid. You may subtract them using the self.add method and"
96- "specifying how to handle the mismatch."
97- )
93+ raise RuntimeError (x_grid_emsg )
9894 else :
9995 subtracted .on_tth [1 ] = self .on_tth [1 ] - other .on_tth [1 ]
10096 subtracted .on_q [1 ] = self .on_q [1 ] - other .on_q [1 ]
@@ -108,10 +104,7 @@ def __rsub__(self, other):
108104 elif not isinstance (other , Diffraction_object ):
109105 raise TypeError ("I only know how to subtract two Scattering_object objects" )
110106 elif self .on_tth [0 ].all () != other .on_tth [0 ].all ():
111- raise RuntimeError (
112- "objects are not on the same x-grid. You may subtract them using the self.add method and"
113- "specifying how to handle the mismatch."
114- )
107+ raise RuntimeError (x_grid_emsg )
115108 else :
116109 subtracted .on_tth [1 ] = other .on_tth [1 ] - self .on_tth [1 ]
117110 subtracted .on_q [1 ] = other .on_q [1 ] - self .on_q [1 ]
@@ -125,10 +118,7 @@ def __mul__(self, other):
125118 elif not isinstance (other , Diffraction_object ):
126119 raise TypeError ("I only know how to multiply two Scattering_object objects" )
127120 elif self .on_tth [0 ].all () != other .on_tth [0 ].all ():
128- raise RuntimeError (
129- "objects are not on the same x-grid. You may multiply them using the self.add method and"
130- "specifying how to handle the mismatch."
131- )
121+ raise RuntimeError (x_grid_emsg )
132122 else :
133123 multiplied .on_tth [1 ] = self .on_tth [1 ] * other .on_tth [1 ]
134124 multiplied .on_q [1 ] = self .on_q [1 ] * other .on_q [1 ]
@@ -140,10 +130,7 @@ def __rmul__(self, other):
140130 multiplied .on_tth [1 ] = other * self .on_tth [1 ]
141131 multiplied .on_q [1 ] = other * self .on_q [1 ]
142132 elif self .on_tth [0 ].all () != other .on_tth [0 ].all ():
143- raise RuntimeError (
144- "objects are not on the same x-grid. You may multiply them using the self.add method and"
145- "specifying how to handle the mismatch."
146- )
133+ raise RuntimeError (x_grid_emsg )
147134 else :
148135 multiplied .on_tth [1 ] = self .on_tth [1 ] * other .on_tth [1 ]
149136 multiplied .on_q [1 ] = self .on_q [1 ] * other .on_q [1 ]
@@ -157,10 +144,7 @@ def __truediv__(self, other):
157144 elif not isinstance (other , Diffraction_object ):
158145 raise TypeError ("I only know how to multiply two Scattering_object objects" )
159146 elif self .on_tth [0 ].all () != other .on_tth [0 ].all ():
160- raise RuntimeError (
161- "objects are not on the same x-grid. You may multiply them using the self.add method and"
162- "specifying how to handle the mismatch."
163- )
147+ raise RuntimeError (x_grid_emsg )
164148 else :
165149 divided .on_tth [1 ] = self .on_tth [1 ] / other .on_tth [1 ]
166150 divided .on_q [1 ] = self .on_q [1 ] / other .on_q [1 ]
@@ -172,10 +156,7 @@ def __rtruediv__(self, other):
172156 divided .on_tth [1 ] = other / self .on_tth [1 ]
173157 divided .on_q [1 ] = other / self .on_q [1 ]
174158 elif self .on_tth [0 ].all () != other .on_tth [0 ].all ():
175- raise RuntimeError (
176- "Diffraction objects are not on the same x-grid. You may multiply them using the self.add"
177- "method and specifying how to handle the mismatch."
178- )
159+ raise RuntimeError (x_grid_emsg )
179160 else :
180161 divided .on_tth [1 ] = other .on_tth [1 ] / self .on_tth [1 ]
181162 divided .on_q [1 ] = other .on_q [1 ] / self .on_q [1 ]
0 commit comments