From ba0d6d8325c33d43a53924a9a0154dcade33edd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Le=20Guyader?= <loic.le.guyader@xfel.eu> Date: Sun, 20 Oct 2019 13:49:17 +0200 Subject: [PATCH] Adds line scan plots --- DSSC.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/DSSC.py b/DSSC.py index 015e227..a571613 100644 --- a/DSSC.py +++ b/DSSC.py @@ -501,6 +501,8 @@ class DSSC: azimuthal['delta_q (1/nm)'] = 2e-9 * np.pi * np.sin( np.arctan(azimuthal.distance * self.px_pitch_v*1e-6 / self.distance)) / wl + + azimuthal.attrs = self.binned.attrs self.azimuthal = azimuthal.swap_dims({'distance': 'delta_q (1/nm)'}) @@ -511,12 +513,42 @@ class DSSC: xr.plot.imshow(self.azimuthal.pumped, ax=ax1, robust=True) ax1.set_title('unpumped') + ax1.set_xlabel(self.scan_vname) xr.plot.imshow(self.azimuthal.pumped - self.azimuthal.unpumped, ax=ax2, robust=True) ax2.set_title('pumped - unpumped') ax2.set_xlabel(self.scan_vname) fig.suptitle(f'{self.plot_title}') + def plot_azimuthal_line_cut(self, data, qranges, qwidths): + """ Plot line scans on top of the data. + + inputs: + data: an azimuthal integrated xarray DataArray with 'delta_q (1/nm)' as one of its dimension. + qranges: a list of q-range + qwidth: a list of q-width, same length as qranges + """ + + fig, [ax1, ax2] = plt.subplots(nrows=2, sharex=True, figsize=[8, 7]) + + xr.plot.imshow(data, ax=ax1, robust=True) + + # attributes are not propagated during xarray mathematical operation https://github.com/pydata/xarray/issues/988 + # so we might not have in data the scan vaiable name anymore + ax1.set_xlabel(self.scan_vname) + fig.suptitle(f'{self.plot_title}') + + for i, (qr, qw) in enumerate(zip(qranges, qwidths)): + sel = (data['delta_q (1/nm)'] > (qr - qw/2)) * (data['delta_q (1/nm)'] < (qr + qw/2)) + val = data.where(sel).mean('delta_q (1/nm)') + ax2.plot(data.scan_variable, val, c=f'C{i}', label=f'q = {qr:.2f}') + + ax1.axhline(qr - qw/2, c=f'C{i}', lw=1) + ax1.axhline(qr + qw/2, c=f'C{i}', lw=1) + ax2.legend() + ax2.set_xlabel(self.scan_vname) + + # since 'self' is not pickable, this function has to be outside the DSSC class so that it can be used # by the multiprocessing pool.map function def process_one_module(job): -- GitLab