Skip to content
Snippets Groups Projects
Commit 6aecae71 authored by Valerio Mariani's avatar Valerio Mariani
Browse files

Fixed parsing of dim entries in load_crystfel_geometry

parent 42c528bf
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,8 @@ import copy ...@@ -27,6 +27,8 @@ import copy
import math import math
import re import re
from future.utils import viewitems
def _assplode_algebraic(value): def _assplode_algebraic(value):
# Reimplementation of assplode_algegraic from # Reimplementation of assplode_algegraic from
...@@ -112,6 +114,7 @@ def _set_dim_structure_entry(key, value, panel): ...@@ -112,6 +114,7 @@ def _set_dim_structure_entry(key, value, panel):
dim[dim_index] = int(value) dim[dim_index] = int(value)
else: else:
raise RuntimeError("Invalid dim entry: {}.".format(value)) raise RuntimeError("Invalid dim entry: {}.".format(value))
panel['dim_structure'] = dim
def _parse_field_for_panel(key, value, panel): def _parse_field_for_panel(key, value, panel):
...@@ -229,7 +232,7 @@ def _parse_field_for_panel(key, value, panel): ...@@ -229,7 +232,7 @@ def _parse_field_for_panel(key, value, panel):
panel=panel panel=panel
) )
else: else:
raise RuntimeError("Unrecognised field: {}".format(key)) RuntimeError("Unrecognised field: {}".format(key))
def _parse_toplevel(key, value, detector, beam, panel): def _parse_toplevel(key, value, detector, beam, panel):
...@@ -464,7 +467,6 @@ def load_crystfel_geometry(filename): ...@@ -464,7 +467,6 @@ def load_crystfel_geometry(filename):
'satmap_file': None, 'satmap_file': None,
'data': None, 'data': None,
'dim_structure': None, 'dim_structure': None,
'name': ''
} }
default_bad_region = { default_bad_region = {
...@@ -477,7 +479,6 @@ def load_crystfel_geometry(filename): ...@@ -477,7 +479,6 @@ def load_crystfel_geometry(filename):
'min_ss': 0, 'min_ss': 0,
'max_ss': 0, 'max_ss': 0,
'is_fsss': 99, 'is_fsss': 99,
'name': ''
} }
default_dim = [ default_dim = [
...@@ -552,7 +553,7 @@ def load_crystfel_geometry(filename): ...@@ -552,7 +553,7 @@ def load_crystfel_geometry(filename):
num_placeholders_in_panels = None num_placeholders_in_panels = None
for panel in detector['panels'].values(): for panel in detector['panels'].values():
if panel['dim_structure'] is not None: if panel['dim_structure'] is not None:
curr_num_placeholders = panel['dim_structure'].values().count('%') curr_num_placeholders = panel['dim_structure'].count('%')
else: else:
curr_num_placeholders = 0 curr_num_placeholders = 0
...@@ -588,7 +589,7 @@ def load_crystfel_geometry(filename): ...@@ -588,7 +589,7 @@ def load_crystfel_geometry(filename):
) )
dim_length = None dim_length = None
for panel in detector['panels'].values(): for panel_name, panel in viewitems(detector['panels']):
if panel['dim_structure'] is None: if panel['dim_structure'] is None:
panel['dim_structure'] = copy.deepcopy(default_dim) panel['dim_structure'] = copy.deepcopy(default_dim)
...@@ -600,40 +601,41 @@ def load_crystfel_geometry(filename): ...@@ -600,40 +601,41 @@ def load_crystfel_geometry(filename):
raise RuntimeError( raise RuntimeError(
"Dimension {} for panel {} is undefined.".format( "Dimension {} for panel {} is undefined.".format(
dim_index, dim_index,
panel['name'] panel_name
) )
) )
elif entry == 'ss': elif entry == 'ss':
found_ss += 1 found_ss += 1
if found_ss != 1:
raise RuntimeError(
"Exactly one slow scan dim coordinate is needed "
"(found {} for panel {})".format(
found_ss,
panel['name']
)
)
elif entry == 'fs': elif entry == 'fs':
found_fs += 1 found_fs += 1
if found_fs != 1:
raise RuntimeError(
"Exactly one fast scan dim coordinate is needed "
"(found {} for panel {})".format(
found_fs,
panel['name']
)
)
elif entry == '%': elif entry == '%':
found_placeholder += 1 found_placeholder += 1
if found_placeholder != 1:
raise RuntimeError( if found_ss != 1:
"Only one placeholder dim coordinate is allowed." raise RuntimeError(
"Maximum one placeholder dim coordinate is " "Exactly one slow scan dim coordinate is needed "
"allowed (found {} for panel {})".format( "(found {} for panel {})".format(
found_placeholder, found_ss,
panel['name'] panel_name
) )
) )
if found_fs != 1:
raise RuntimeError(
"Exactly one fast scan dim coordinate is needed "
"(found {} for panel {})".format(
found_fs,
panel_name
)
)
if found_placeholder != 1:
raise RuntimeError(
"Only one placeholder dim coordinate is allowed."
"Maximum one placeholder dim coordinate is "
"allowed (found {} for panel {})".format(
found_placeholder,
panel_name
)
)
if dim_length is None: if dim_length is None:
dim_length = len(panel['dim_structure']) dim_length = len(panel['dim_structure'])
...@@ -647,59 +649,59 @@ def load_crystfel_geometry(filename): ...@@ -647,59 +649,59 @@ def load_crystfel_geometry(filename):
"Number of dim coordinates must be at least two." "Number of dim coordinates must be at least two."
) )
for panel in detector['panels'].values(): for panel_name, panel in viewitems(detector['panels']):
if panel['origin_min_fs'] < 0: if panel['origin_min_fs'] < 0:
raise RuntimeError( raise RuntimeError(
"Please specify the minimum fs coordinate for " "Please specify the minimum fs coordinate for "
"panel {}.".format(panel['name']) "panel {}.".format(panel_name)
) )
if panel['origin_max_fs'] < 0: if panel['origin_max_fs'] < 0:
raise RuntimeError( raise RuntimeError(
"Please specify the maximum fs coordinate for " "Please specify the maximum fs coordinate for "
"panel {}.".format(panel['name']) "panel {}.".format(panel_name)
) )
if panel['origin_min_ss'] < 0: if panel['origin_min_ss'] < 0:
raise RuntimeError( raise RuntimeError(
"Please specify the minimum ss coordinate for " "Please specify the minimum ss coordinate for "
"panel {}.".format(panel['name']) "panel {}.".format(panel_name)
) )
if panel['origin_max_ss'] < 0: if panel['origin_max_ss'] < 0:
raise RuntimeError( raise RuntimeError(
"Please specify the maximum ss coordinate for " "Please specify the maximum ss coordinate for "
"panel {}.".format(panel['name']) "panel {}.".format(panel_name)
) )
if panel['cnx'] is None: if panel['cnx'] is None:
raise RuntimeError( raise RuntimeError(
"Please specify the corner X coordinate for " "Please specify the corner X coordinate for "
"panel {}.".format(panel['name']) "panel {}.".format(panel_name)
) )
if panel['clen'] is None and panel['clen_from'] is None: if panel['clen'] is None and panel['clen_from'] is None:
raise RuntimeError( raise RuntimeError(
"Please specify the camera length for " "Please specify the camera length for "
"panel {}.".format(panel['name']) "panel {}.".format(panel_name)
) )
if panel['res'] < 0: if panel['res'] < 0:
raise RuntimeError( raise RuntimeError(
"Please specify the resolution or " "Please specify the resolution or "
"panel {}.".format(panel['name']) "panel {}.".format(panel_name)
) )
if panel['adu_per_eV'] is None and panel['adu_per_photon'] is None: if panel['adu_per_eV'] is None and panel['adu_per_photon'] is None:
raise RuntimeError( raise RuntimeError(
"Please specify either adu_per_eV or adu_per_photon " "Please specify either adu_per_eV or adu_per_photon "
"for panel {}.".format(panel['name']) "for panel {}.".format(panel_name)
) )
if panel['clen_for_centering'] is None and panel['rail_x'] is not None: if panel['clen_for_centering'] is None and panel['rail_x'] is not None:
raise RuntimeError( raise RuntimeError(
"You must specify clen_for_centering if you specify the " "You must specify clen_for_centering if you specify the "
"rail direction (panel {})".format(panel['name']) "rail direction (panel {})".format(panel_name)
) )
if panel['rail_x'] is None: if panel['rail_x'] is None:
...@@ -713,11 +715,11 @@ def load_crystfel_geometry(filename): ...@@ -713,11 +715,11 @@ def load_crystfel_geometry(filename):
panel['w'] = panel['origin_max_fs'] - panel['origin_min_fs'] + 1 panel['w'] = panel['origin_max_fs'] - panel['origin_min_fs'] + 1
panel['h'] = panel['origin_max_ss'] - panel['origin_min_ss'] + 1 panel['h'] = panel['origin_max_ss'] - panel['origin_min_ss'] + 1
for bad_region in detector['bad'].values(): for bad_region_name, bad_region in viewitems(detector['bad']):
if bad_region['is_fsss'] == 99: if bad_region['is_fsss'] == 99:
raise RuntimeError( raise RuntimeError(
"Please specify the coordinate ranges for bad " "Please specify the coordinate ranges for bad "
"region {}.".format(bad_region['name']) "region {}.".format(bad_region_name)
) )
for group in detector['rigid_groups']: for group in detector['rigid_groups']:
......
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