From 0ab7193e771585ea4ffcdcbb4f4991e2df297e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Le=20Guyader?= <loic.le.guyader@xfel.eu> Date: Thu, 2 May 2019 13:56:24 +0200 Subject: [PATCH] Fix the calculation of XAS spectra with bins number or bins width --- XAS.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/XAS.py b/XAS.py index 092fe4f..a7bab50 100644 --- a/XAS.py +++ b/XAS.py @@ -102,7 +102,8 @@ def xas(nrun, bins=None, Iokey='SCS_XGM', Itkey='MCP3apd', nrjkey='nrj', Iooffse Inputs: nrun: xarray of SCS data - bins: array of bin-edges or number of desired bins + bins: an array of bin-edges or an integer number of + desired bins or a float for the desired bin width. Iokey: string for the Io fields, typically 'SCS_XGM' Itkey: string for the It fields, typically 'MCP3apd' NRJkey: string for the nrj fields, typically 'nrj' @@ -140,6 +141,12 @@ def xas(nrun, bins=None, Iokey='SCS_XGM', Itkey='MCP3apd', nrjkey='nrj', Iooffse num_bins = 80 energy_limits = [np.min(nrj), np.max(nrj)] bins = np.linspace(energy_limits[0], energy_limits[1], num_bins+1) + elif type(bins) == int: + energy_limits = [np.min(nrj), np.max(nrj)] + bins = np.linspace(energy_limits[0], energy_limits[1], bins+1) + elif type(bins) == float: + energy_limits = [np.min(nrj), np.max(nrj)] + bins = np.arange(energy_limits[0], energy_limits[1], bins) dummy, nosample = binning(rundata['nrj'], rundata, whichIo, bins) muA = nosample['muA'] -- GitLab