Commit 2a66b1d1 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by Generic Bliss account for Control Software
Browse files

[FAI] Improve & reorganize generator scripts

parent 72b5210f
......@@ -7,8 +7,9 @@ parser = argparse.ArgumentParser(description='Decode OpenCL input parameters.')
parser.add_argument('--pixel_map', help='Geometry raw-in-asm pixel map')
parser.add_argument('--occurrence', type=int, default=30,
help='Hot event occurrence, in percent')
parser.add_argument('data', help='input data frames')
parser.add_argument('threshold', type=float, help='threshold value for mask')
parser.add_argument('--data', help='input data frames')
parser.add_argument('--threshold', type=float, help='threshold value for mask',
default=1000.0)
parser.add_argument('mask', help='output mask map')
args = parser.parse_args()
......@@ -21,24 +22,24 @@ if args.pixel_map:
pixel_map = f['/data'][:]
mask = pixel_map < 0
with h5.File(args.data) as f:
in_data = None
for instrument in f[data_location_prefix]:
path = f'{data_location_prefix}/{instrument}/data'
try:
in_data = f[path]
break
except:
pass
else:
raise RuntimeError(f'Could not find data in file {fname}')
if mask is None:
mask = np.zeros(in_data.shape[-2:], 'bool')
min_occ = args.occurrence * len(in_data) / 100
hot_mask = (in_data[:] >= args.threshold).sum(0) >= min_occ
mask |= hot_mask
if args.data:
with h5.File(args.data) as f:
for instrument in f[data_location_prefix]:
path = f'{data_location_prefix}/{instrument}/data'
try:
in_data = f[path]
break
except:
pass
else:
raise RuntimeError(f'Could not find data in file {fname}')
if mask is None:
mask = np.zeros(in_data.shape[-2:], 'bool')
min_occ = args.occurrence * len(in_data) / 100
hot_mask = (in_data[:] >= args.threshold).sum(0) >= min_occ
mask |= hot_mask
with h5.File(args.mask, 'w') as f:
f.create_dataset('/data', data=mask)
......@@ -48,7 +48,7 @@ for g in range(nb_gains):
def ave(first_line):
lines = slice(first_line, first_line + block_lines)
out_data[lines] = np.average(in_data[:,lines] & 0x3FFF, axis=0)
out_data[lines] = np.average(in_data[:,lines], axis=0)
with Pool() as p:
p.map(ave, range(0, height, block_lines))
......
......@@ -31,7 +31,7 @@ ModSize = ChipSize * ModChips
module_shape = np.array(size_2_shape(ModSize))
InterChipGap = np.array((2, 2))
InterModGap = (9, 36)
InterModGap = (8, 36)
J16QuadDisp = 34
pixel_size = 75e-6
......
......@@ -9,13 +9,13 @@ from subprocess import run
parser = argparse.ArgumentParser(description='Generate detector pixel maps.')
parser.add_argument('--verbose', action='store_true', help='Verbose output')
parser.add_argument('--conda_base', help='Conda base directory')
parser.add_argument('--sls_conda_env', help='SlsDetector conda environment')
parser.add_argument('geom_name', help='Geometry name: 500k|4M|16M')
parser.add_argument('conda_base', help='Conda base directory')
parser.add_argument('sls_conda_env', help='SlsDetector conda environment')
parser.add_argument('src_fmt', help='source format: Raw|AsmNG|AsmWG')
parser.add_argument('tgt_fmt', help='target format: Raw|AsmNG|AsmWG')
parser.add_argument('pixel_map', help='output pixel map')
parser.add_argument('map_dim', type=int, help='output map dimentions: 1|2')
parser.add_argument('map_dim', type=int, help='output map dimensions: 1|2')
args = parser.parse_args()
......@@ -54,6 +54,8 @@ def exec_geometry_assembler(det_size, nb_frames = 1, gen_type = '',
prog = 'sls_geometry_assembler'
cmd = ''
if args.sls_conda_env:
if not args.conda_base:
raise RuntimeError('Must specify conda_base with sls_conda_env')
cmd += f'. {args.conda_base}/etc/profile.d/conda.sh && ' \
f'conda activate {args.sls_conda_env} && '
cmd += f'{prog} {prog_args}'
......@@ -84,12 +86,18 @@ def query_geometry_assembler(det_size):
for fmt in ['AsmNG', 'AsmWG']:
out_lines = exec_geometry_assembler(det_size, tgt_fmt=fmt)
dims_line = out_lines[0].strip()
dims = []
for t in dims_line.split():
dims.append(decode_xy(t))
mod_corners_line = out_lines[1].strip()
o, s = mod_corners_line.split()[0].split('x')
def decode_dim_line(l, kind):
header = f'{kind} geometry: '
if not l.startswith(header):
raise RuntimeError(f'Invalid {kind} geometry line header: {l}')
return decode_xy(l[len(header):])
dims = [decode_dim_line(l, k)
for l, k in zip(out_lines[:2], ['Source', 'Target'])]
header = 'Target modules corners: '
l = out_lines[2]
if not l.startswith(header):
raise RuntimeError(f'Invalid module corners line header: {l}')
mod_corners_line = l[len(header):]
all_xy = [decode_xy(p) for x in mod_corners_line.split()
for p in x.split('x')]
mod_corners = list(zip(all_xy[0::2], all_xy[1::2]))
......
Supports Markdown
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