Skip to content

Commit daa9c3f

Browse files
committed
small tweaks and typo fixes
1 parent 828b2a6 commit daa9c3f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

news/constructor.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
* arrays and attributes now can be inserted when a DiffractionObject is instantiated
88
* data are now stored as a (len(x),4) numpy array with intensity in column 0, the q, then tth, then d
9-
* `DiffractionObject.on_q`, on_tth and on_d are now methods and called as DiffractionObject.on_q() etc.`
9+
* `DiffractionObject.on_q`, `...on_tth` and `...on_d` are now methods and called as `DiffractionObject.on_q()` etc.`
1010

1111
**Deprecated:**
1212

src/diffpy/utils/diffraction_objects.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,23 @@
2121

2222
def _xtype_wmsg(xtype):
2323
return (
24-
f"WARNING: I don't know how to handle the xtype, '{xtype}'. Please rerun specifying and "
24+
f"WARNING: I don't know how to handle the xtype, '{xtype}'. Please rerun specifying an "
2525
f"xtype from {*XQUANTITIES, }"
2626
)
2727

2828

2929
class DiffractionObject:
3030
def __init__(
31-
self, name=None, wavelength=None, scat_quantity=None, metadata=None, xarray=None, yarray=None, xtype=""
31+
self, name=None, wavelength=None, scat_quantity=None, metadata=None, xarray=None, yarray=None, xtype=None
3232
):
3333
if name is None:
3434
name = ""
3535
self.name = name
3636
if metadata is None:
3737
metadata = {}
3838
self.metadata = metadata
39+
if xtype is None:
40+
xtype = ""
3941
self.scat_quantity = scat_quantity
4042
self.wavelength = wavelength
4143

@@ -282,6 +284,10 @@ def insert_scattering_quantity(
282284
xarray,
283285
yarray,
284286
xtype,
287+
metadata={},
288+
scat_quantity=None,
289+
name=None,
290+
wavelength=None,
285291
):
286292
f"""
287293
insert a new scattering quantity into the scattering object
@@ -294,14 +300,27 @@ def insert_scattering_quantity(
294300
the dependent variable array
295301
xtype string
296302
the type of quantity for the independent variable from {*XQUANTITIES, }
303+
metadata, scat_quantity, name and wavelength are optional. They have the same
304+
meaning as in the constructor. Values will only be overwritten if non-empty values are passed.
297305
298306
Returns
299307
-------
308+
Nothing. Updates the object in place.
300309
301310
"""
302311
self._set_xarrays(xarray, xtype)
303312
self.all_arrays[:, 0] = yarray
304313
self.input_xtype = xtype
314+
# only update these optional values if non-empty quantities are passed to avoid overwriting
315+
# valid data inadvertently
316+
if metadata:
317+
self.metadata = metadata
318+
if scat_quantity is not None:
319+
self.scat_quantity = scat_quantity
320+
if name is not None:
321+
self.name = name
322+
if wavelength is not None:
323+
self.wavelength = wavelength
305324

306325
def _get_original_array(self):
307326
if self.input_xtype in QQUANTITIES:

0 commit comments

Comments
 (0)