Skip to content

Commit 1d9d94c

Browse files
authored
Merge pull request #58 from sbillinge/tweaks
dont inadvertently overwrite attributes on insert_scattering_quantity
2 parents 494f4c4 + 11852f8 commit 1d9d94c

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

news/tweaks.rst

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* fixed inadvertent overwrite of attributes on self.insert_scattering_quantity()
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/utils/scattering_objects/diffraction_objects.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __init__(self, name='', wavelength=None):
1919
self.on_tth = [np.empty(1), np.empty(1)]
2020
self.on_d = [np.empty(1), np.empty(1)]
2121
self._all_arrays = [self.on_q, self.on_tth]
22+
self.metadata = {}
2223

2324
def __add__(self, other):
2425
summed = deepcopy(self)
@@ -221,7 +222,8 @@ def get_angle_index(self, angle):
221222
if count >= len(self.angles):
222223
raise IndexError(f"WARNING: no angle {angle} found in angles list")
223224

224-
def insert_scattering_quantity(self, xarray, yarray, xtype, metadata={}):
225+
def insert_scattering_quantity(self, xarray, yarray, xtype, metadata={},
226+
scat_quantity=None, name=None, wavelength=None):
225227
f"""
226228
insert a new scattering quantity into the scattering object
227229
@@ -241,7 +243,12 @@ def insert_scattering_quantity(self, xarray, yarray, xtype, metadata={}):
241243
242244
"""
243245
self.input_xtype = xtype
244-
self.metadata = metadata
246+
# empty attributes have been defined in the __init__ method so only
247+
# set the attributes that are not empty to avoid emptying them by mistake
248+
if metadata: self.metadata = metadata
249+
if scat_quantity is not None: self.scat_quantity = scat_quantity
250+
if name is not None: self.name = name
251+
if wavelength is not None: self.wavelength = wavelength
245252
if xtype.lower() in QQUANTITIES:
246253
self.on_q = [np.array(xarray),np.array(yarray)]
247254
elif xtype.lower() in ANGLEQUANTITIES:
@@ -284,7 +291,7 @@ def q_to_tth(self):
284291
q = np.asarray(q)
285292
wavelength = float(self.wavelength)
286293
pre_factor = wavelength / (4 * np.pi)
287-
return np.rad2deg(2 * np.arcsin(q * pre_factor))
294+
return np.rad2deg(2. * np.arcsin(q * pre_factor))
288295

289296
def tth_to_q(self):
290297
r"""

0 commit comments

Comments
 (0)