2121
2222def _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
2929class 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