Commit 445add7e authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline

Add first version of dump_eiger_calib, generating EDF files

parent 75d79cb9
#!/usr/bin/env python
import sys
import os
import stat
import numpy as np
dacs = [
'vsvp',
'vtr',
'vrf',
'vrs',
'vsvn',
'vtgstv',
'vcmp_ll',
'vcmp_lr',
'vcall',
'vcmp_rl',
'rxb_rb',
'rxb_lb',
'vcmp_rr',
'vcp',
'vcn',
'vis',
'iodelay'
]
dtype = np.dtype('uint32')
head_keys = dacs + ['tau']
nb_head_vals = len(head_keys)
chip_size = 256
chip_pixels = chip_size ** 2
nb_chips = 4
val_bytes = dtype.itemsize
def usage():
prog_name = os.path.basename(sys.argv[0])
print "Usage %s <config_fname> <energy> <output_dir>" % prog_name
exit(1)
try:
config_fname = sys.argv[1]
energy = sys.argv[2]
output_dir = sys.argv[3]
except:
usage()
host_names = None
settings_dir = None
config_file = open(config_fname)
for l in config_file.readlines():
token = l.strip().split()
if not token or token[0].startswith('#'):
continue
if token[0] == 'hostname':
host_names = token[1].split('+')[:-1]
elif token[0] == 'settingsdir':
settings_dir = token[1]
if None in [host_names, settings_dir]:
raise RuntimeError('Invalid config: %s' % config_file)
nb_det_mod = len(host_names)
sn_list = [n[-3:] for n in host_names]
cal_fnames = ['noise.sn%s' % sn for sn in sn_list]
cal_dir = os.path.join(settings_dir, 'standard', '%seV' % energy)
trim_arr = np.zeros((nb_det_mod, chip_size, nb_chips * chip_size), dtype)
dacs_arr = [[] for i in range(nb_head_vals)]
for i, fname in enumerate(cal_fnames):
cal_fname = os.path.join(cal_dir, fname)
size = os.stat(cal_fname).st_size
ok = (size % val_bytes == 0)
if ok:
nb_val = size / val_bytes
ok = (nb_val == nb_head_vals + chip_pixels * nb_chips)
if not ok:
raise RuntimeError('Invalid %s size: %s' % (cal_fname, size))
cal_file = open(cal_fname)
s = cal_file.read(size)
d = np.fromstring(s, dtype)
dac_vals, trim_vals = np.split(d, np.array((nb_head_vals,)))
for dac_val, dac_list in zip(dac_vals, dacs_arr):
dac_list.append(dac_val)
trim_bits = trim_vals.reshape((chip_size, nb_chips * chip_size))
trim_arr[i] = trim_bits[::-1]
from EdfFile import EdfFile
fname = 'Trimbits_%seV_beb%s-%s.edf' % (energy, sn_list[0], sn_list[-1])
ocal_fname = os.path.join(output_dir, fname)
if os.path.exists(ocal_fname):
os.unlink(ocal_fname)
ocal_head = {'host_names': str(host_names),
'config_file': config_fname,
'settings_dir': settings_dir,
'energy': energy}
ocal_head.update([(n, str(l)) for n, l in zip(head_keys, dacs_arr)])
ocal_file = EdfFile(ocal_fname)
final_shape = (nb_det_mod * chip_size, nb_chips * chip_size)
ocal_file.WriteImage(ocal_head, trim_arr.reshape(final_shape))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment