From 2a85c7c0d218261bda6b10a4d78592369affca13 Mon Sep 17 00:00:00 2001 From: Laurent Mercadier <laurent.mercadier@xfel.eu> Date: Fri, 8 Sep 2023 21:12:59 +0200 Subject: [PATCH] Add flag to choose how to normalize hRIXS data in normalize() --- src/toolbox_scs/detectors/hrixs.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/toolbox_scs/detectors/hrixs.py b/src/toolbox_scs/detectors/hrixs.py index 87ecd84..b8ec6e5 100644 --- a/src/toolbox_scs/detectors/hrixs.py +++ b/src/toolbox_scs/detectors/hrixs.py @@ -596,10 +596,21 @@ class hRIXS: agg = groups.map(h.aggregate) # sum corresponding spectra agg.spectrum[0, :].plot() # plot the spectrum for first value """ - ds['counts'] = xr.ones_like(ds["trainId"]) + ds['counts'] = xr.ones_like(ds[dim]) ret = ds.map(self.aggregator, dim=dim) ret = ret.drop_vars([n for n in ret if n not in self.aggregators]) return ret - def normalize(self, data): - return data.assign(normalized=data["spectrum"] / data["hRIXS_norm"]) + def normalize(self, data, which="hRIXS_norm"): + """ Adds a 'normalized' variable to the dataset defined as the + ration between 'spectrum' and 'which' + + Parameters + ---------- + data: xarray Dataset + the dataset containing hRIXS data + which: string, default="hRIXS_norm" + one of the variables of the dataset, usually "hRIXS_norm" + or "counts" + """ + return data.assign(normalized=data["spectrum"] / data[which]) -- GitLab