Skip to content
Snippets Groups Projects
Commit 44f691ca authored by Laurent Mercadier's avatar Laurent Mercadier
Browse files

Merge branch 'pes_voltages' into 'master'

Adds pes_get_voltages(), updates pes_get_params()

See merge request !143
parents 467828f7 bda0d31f
No related branches found
No related tags found
1 merge request!143Adds pes_get_voltages(), updates pes_get_params()
...@@ -10,6 +10,7 @@ import logging ...@@ -10,6 +10,7 @@ import logging
import numpy as np import numpy as np
import xarray as xr import xarray as xr
import extra_data as ed import extra_data as ed
import re
from ..misc.bunch_pattern_external import is_sase_3 from ..misc.bunch_pattern_external import is_sase_3
from ..mnemonics_machinery import (mnemonics_to_process, from ..mnemonics_machinery import (mnemonics_to_process,
...@@ -119,10 +120,10 @@ def get_pes_tof(run, mnemonics=None, merge_with=None, ...@@ -119,10 +120,10 @@ def get_pes_tof(run, mnemonics=None, merge_with=None,
else: else:
arr = run.get_array(*run_mnemonics[m].values(), name=m) arr = run.get_array(*run_mnemonics[m].values(), name=m)
if arr.sizes['PESsampleId'] < npulses*period*440 + start + width: if arr.sizes['PESsampleId'] < npulses*period*440 + start + width:
log.warning('Not all pulses were recorded. The number of samples on ' log.warning('Not all pulses were recorded. The number of samples '
f'the digitizer {arr.sizes["PESsampleId"]} is not enough ' f'on the digitizer {arr.sizes["PESsampleId"]} is not '
f'to cover the {npulses} spectra. Missing spectra will be ' f'enough to cover the {npulses} spectra. Missing '
'filled with NaNs.') 'spectra will be filled with NaNs.')
spectra = [] spectra = []
for p in range(npulses): for p in range(npulses):
begin = p*period*440 + start begin = p*period*440 + start
...@@ -134,14 +135,15 @@ def get_pes_tof(run, mnemonics=None, merge_with=None, ...@@ -134,14 +135,15 @@ def get_pes_tof(run, mnemonics=None, merge_with=None,
baseBegin = p*period*440 + baseStart baseBegin = p*period*440 + baseStart
baseEnd = baseBegin + baseWidth baseEnd = baseBegin + baseWidth
bl = arr.isel( bl = arr.isel(
PESsampleId=slice(baseBegin, baseEnd)).mean(dim='PESsampleId') PESsampleId=slice(baseBegin, baseEnd)).mean(dim='PESsampleId')
pes = pes - bl pes = pes - bl
spectra.append(pes) spectra.append(pes)
spectra = xr.concat(spectra, spectra = xr.concat(spectra,
dim='sa3_pId').rename(m.replace('raw', 'tof')) dim='sa3_pId').rename(m.replace('raw', 'tof'))
ds = ds.merge(spectra) ds = ds.merge(spectra)
if len(ds.variables) > 0: if len(ds.variables) > 0:
ds = ds.assign_coords({'sa3_pId': mask_on['pulse_slot'][:ds.sizes['sa3_pId']].values}) ds = ds.assign_coords(
{'sa3_pId': mask_on['pulse_slot'][:ds.sizes['sa3_pId']].values})
ds = ds.rename({'PESsampleId': 'time_ns'}) ds = ds.rename({'PESsampleId': 'time_ns'})
ds = ds.assign_coords({'time_ns': time_ns}) ds = ds.assign_coords({'time_ns': time_ns})
if bool(merge_with): if bool(merge_with):
...@@ -154,7 +156,7 @@ def get_pes_tof(run, mnemonics=None, merge_with=None, ...@@ -154,7 +156,7 @@ def get_pes_tof(run, mnemonics=None, merge_with=None,
def get_pes_params(run): def get_pes_params(run):
""" """
Extract PES parameters for a given extra_data DataCollection. Extract PES parameters for a given extra_data DataCollection.
Parameters are gas, retardation voltage. Parameters are gas, binding energy, voltages of the MPOD.
Parameters Parameters
---------- ----------
...@@ -168,7 +170,6 @@ def get_pes_params(run): ...@@ -168,7 +170,6 @@ def get_pes_params(run):
""" """
params = {} params = {}
sel = run.select_trains(ed.by_index[:20]) sel = run.select_trains(ed.by_index[:20])
mnemonics = mnemonics_for_run(run)
gas_dict = {'N2': 409.9, 'Ne': 870.2, 'Kr': 1921, 'Xe': 1148.7} gas_dict = {'N2': 409.9, 'Ne': 870.2, 'Kr': 1921, 'Xe': 1148.7}
for gas in gas_dict.keys(): for gas in gas_dict.keys():
mnemo = _mnemonics[f'PES_{gas}'][0] mnemo = _mnemonics[f'PES_{gas}'][0]
...@@ -180,6 +181,31 @@ def get_pes_params(run): ...@@ -180,6 +181,31 @@ def get_pes_params(run):
if 'gas' not in params: if 'gas' not in params:
params['gas'] = 'unknown' params['gas'] = 'unknown'
log.warning('Could not find which PES gas was used.') log.warning('Could not find which PES gas was used.')
arr = sel.get_array(*mnemonics['PES_RV'].values()) voltages = get_pes_voltages(run)
params['ret_voltage'] = float(arr[0].values) params.update(voltages)
return params return params
def get_pes_voltages(run, device='SA3_XTD10_PES/MDL/DAQ_MPOD'):
"""
Extract PES voltages read by the MDL watchdog of the MPOD device.
Parameters
----------
run: extra_data.DataCollection
DataCollection containing PES data.
device: string
Name of the device containing the voltage data.
Returns
-------
voltages: dict
dictionnary of voltages
"""
a = re.compile('[u]\d{3}.value')
tid, da = run.train_from_index(0, devices=device)
voltages = {}
for k in da[device]:
if len(a.findall(k)) == 1:
voltages[k.split('.')[0]] = da[device][k]
return voltages
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment