Commit 104643bb authored by Thomas Vincent's avatar Thomas Vincent

Allows to override acquisition parameters in QSpaceConverter

parent 43624f2f
......@@ -80,6 +80,15 @@ class QSpaceConverter(object):
""" Median filter applied to the images after binning (if any)
and before conversion. """
beam_energy = property(lambda self: self.__params['beam_energy'])
"""Beam energy or None to read it from entries"""
direct_beam = property(lambda self: self.__params['direct_beam'])
"""Direct beam calibration position or None to read it from entries"""
channels_per_degree = property(lambda self: self.__params['channels_per_degree'])
"""Channels per degree calibration or None to read it from entries"""
sample_indices = property(lambda self: self.__params['sample_indices'])
""" Indices of sample positions that will be converted. """
......@@ -149,7 +158,10 @@ class QSpaceConverter(object):
'image_binning': None,
'sample_indices': None,
'roi': None,
'entries': sorted(entries)}
'entries': sorted(entries),
'beam_energy': None,
'direct_beam': None,
'channels_per_degree': None}
self.__callback = callback
self.__n_proc = None
......@@ -218,7 +230,10 @@ class QSpaceConverter(object):
msg = 'Invalid parameters.\n{0}'.format('\n'.join(errors))
raise ValueError(msg)
errors = self.check_consistency()
errors = self.check_consistency(
beam_energy_check=self.beam_energy is None,
direct_beam_check=self.direct_beam is None,
channels_per_degree_check=self.channels_per_degree is None)
if len(errors) > 0:
msg = 'Inconsistent input data.\n{0}'.format('\n'.join(errors))
......@@ -330,6 +345,27 @@ class QSpaceConverter(object):
self.__params['medfilt_dims'] = np.array(medfilt_dims_int,
dtype=np.int32)
@beam_energy.setter
def beam_energy(self, beam_energy):
"""Beam energy setter"""
beam_energy = float(beam_energy) if beam_energy is not None else None
self.__params['beam_energy'] = beam_energy
@direct_beam.setter
def direct_beam(self, direct_beam):
"""Direct beam calibration position"""
if direct_beam is not None:
direct_beam = float(direct_beam[0]), float(direct_beam[1])
self.__params['direct_beam'] = direct_beam
@channels_per_degree.setter
def channels_per_degree(self, channels_per_degree):
"""Channels per degree calibration"""
if channels_per_degree is not None:
channels_per_degree = (float(channels_per_degree[0]),
float(channels_per_degree[1]))
self.__params['channels_per_degree'] = channels_per_degree
# @sample_indices.setter
# def sample_indices(self, sample_indices):
# """
......@@ -445,9 +481,8 @@ class QSpaceConverter(object):
or an empty list.
"""
errors = []
image_binning = self.image_binning
qspace_dims = self.qspace_dims
image_binning = self.image_binning
if (image_binning is None
or None in image_binning
or len(image_binning) != 2
......@@ -455,21 +490,30 @@ class QSpaceConverter(object):
errors.append('- "image binning" : must be an array of two'
' strictly positive integers.')
qspace_dims = self.qspace_dims
if (qspace_dims is None
or None in qspace_dims
or len(qspace_dims) != 3
or min(qspace_dims) <= 0):
errors.append('- "qspace size" must be an array of three'
' strictly positive integers.')
return errors
def check_consistency(self):
def check_consistency(self,
beam_energy_check=True,
direct_beam_check=True,
channels_per_degree_check=True):
"""
Check if all entries have the same values plus some other
MINIMAL checks.
This does not check if the parameter values are valid.
Returns a list of strings describing those errors, if any,
or an empty list.
:param bool beam_energy_check: Toggle beam_energy check
:param bool direct_beam_check: Toggle direct_beam check
:param bool channels_per_degree_check: Toggle channels_per_degree check
"""
errors = []
......@@ -489,9 +533,12 @@ class QSpaceConverter(object):
check_values(params, 'n_images', 'Number of images')
check_values(params, 'n_positions', 'Number of X/Y positions')
check_values(params, 'img_size', 'Images size')
check_values(params, 'beam_energy', 'Beam energy')
check_values(params, 'chan_per_deg', 'Chan. per deg.')
check_values(params, 'center_chan', 'Center channel')
if beam_energy_check:
check_values(params, 'beam_energy', 'Beam energy')
if channels_per_degree_check:
check_values(params, 'chan_per_deg', 'Chan. per deg.')
if direct_beam_check:
check_values(params, 'center_chan', 'Center channel')
keys = list(params.keys())
n_images = params[keys[0]]['n_images']
......@@ -522,6 +569,9 @@ class QSpaceConverter(object):
xsocsH5_f = self.xsocsH5_f
output_f = self.output_f
sample_roi = self.__params['roi']
beam_energy = self.__params['beam_energy']
center_chan = self.__params['direct_beam']
chan_per_deg = self.__params['channels_per_degree']
try:
# checking image_binning
......@@ -561,18 +611,21 @@ class QSpaceConverter(object):
first_param = params[entries[0]]
beam_energy = first_param['beam_energy']
if beam_energy is None: # Load it from first entry
beam_energy = first_param['beam_energy']
if beam_energy is None:
raise ValueError('Invalid/missing beam energy : {0}.'
''.format(beam_energy))
chan_per_deg = first_param['chan_per_deg']
if beam_energy is None or len(chan_per_deg) != 2:
if chan_per_deg is None: # Load it from first entry
chan_per_deg = first_param['chan_per_deg']
if chan_per_deg is None or len(chan_per_deg) != 2:
raise ValueError('Invalid/missing chan_per_deg value : {0}.'
''.format(chan_per_deg))
center_chan = first_param['center_chan']
if beam_energy is None or len(center_chan) != 2:
if center_chan is None: # Load it from first entry
center_chan = first_param['center_chan']
if center_chan is None or len(center_chan) != 2:
raise ValueError('Invalid/missing center_chan value : {0}.'
''.format(center_chan))
......
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