Commit 6f5f6924 authored by Thomas Vincent's avatar Thomas Vincent

Add maxipix correction to qspace conversion

parent d591ec74
...@@ -170,6 +170,9 @@ class QSpaceConverter(object): ...@@ -170,6 +170,9 @@ class QSpaceConverter(object):
'direct_beam': None, 'direct_beam': None,
'channels_per_degree': None} 'channels_per_degree': None}
self.maxipix_correction = False
"""Whether or not to apply Maxipix module edges correction (bool)"""
self.__callback = callback self.__callback = callback
self.__n_proc = None self.__n_proc = None
self.__overwrite = False self.__overwrite = False
...@@ -628,6 +631,11 @@ class QSpaceConverter(object): ...@@ -628,6 +631,11 @@ class QSpaceConverter(object):
if mask.shape != img_size: if mask.shape != img_size:
raise ValueError('Invalid mask size') raise ValueError('Invalid mask size')
# TODO image ROI correction
if self.maxipix_correction and (img_size[0] > 516 or img_size[1] > 516):
# Maxipix correction for something else
raise ValueError('Invalid image size for Maxipix correction')
shiftH5 = self.__shiftH5 shiftH5 = self.__shiftH5
if shiftH5: if shiftH5:
...@@ -653,6 +661,7 @@ class QSpaceConverter(object): ...@@ -653,6 +661,7 @@ class QSpaceConverter(object):
print('\t- center channel : {0}'.format(center_chan)) print('\t- center channel : {0}'.format(center_chan))
print('\t- image roi offset : {0}'.format(image_roi_offset)) print('\t- image roi offset : {0}'.format(image_roi_offset))
print('\t- channel per degree : {0}'.format(chan_per_deg)) print('\t- channel per degree : {0}'.format(chan_per_deg))
print('\t- maxipix correction : {0}'.format(self.maxipix_correction))
print('\t- mask : {0}'.format( print('\t- mask : {0}'.format(
'Yes' if mask is not None else 'No')) 'Yes' if mask is not None else 'No'))
print('\t- normalizer : {0}'.format(normalizer)) print('\t- normalizer : {0}'.format(normalizer))
...@@ -856,7 +865,8 @@ class QSpaceConverter(object): ...@@ -856,7 +865,8 @@ class QSpaceConverter(object):
direct_beam=center_chan, direct_beam=center_chan,
channels_per_degree=chan_per_deg, channels_per_degree=chan_per_deg,
normalizer=normalizer, normalizer=normalizer,
mask=mask) mask=mask,
maxipix_correction=self.maxipix_correction)
manager = mp.Manager() manager = mp.Manager()
self.__term_evt = term_evt = manager.Event() self.__term_evt = term_evt = manager.Event()
...@@ -941,6 +951,7 @@ class QSpaceConverter(object): ...@@ -941,6 +951,7 @@ class QSpaceConverter(object):
entries, entries,
img_size, img_size,
output_f, output_f,
self.maxipix_correction,
normalizer, normalizer,
medfilt_dims, medfilt_dims,
img_dtype) img_dtype)
...@@ -1132,7 +1143,8 @@ def _create_result_file(h5_fn, ...@@ -1132,7 +1143,8 @@ def _create_result_file(h5_fn,
direct_beam=None, direct_beam=None,
channels_per_degree=None, channels_per_degree=None,
normalizer='', normalizer='',
mask=None): mask=None,
maxipix_correction=False):
""" """
Initializes the output file. Initializes the output file.
:param h5_fn: name of the file to initialize :param h5_fn: name of the file to initialize
...@@ -1159,6 +1171,8 @@ def _create_result_file(h5_fn, ...@@ -1159,6 +1171,8 @@ def _create_result_file(h5_fn,
Name of measurement group dataset used for normalization Name of measurement group dataset used for normalization
:param Union[numpy.ndarray, None] mask: :param Union[numpy.ndarray, None] mask:
Mask used to discard pixels in images Mask used to discard pixels in images
:param bool maxipix_correction:
Whether or not to apply a correction for maxipix module edges
""" """
if not overwrite: if not overwrite:
...@@ -1187,6 +1201,7 @@ def _create_result_file(h5_fn, ...@@ -1187,6 +1201,7 @@ def _create_result_file(h5_fn,
qspace_h5.set_beam_energy(beam_energy) qspace_h5.set_beam_energy(beam_energy)
qspace_h5.set_direct_beam(direct_beam) qspace_h5.set_direct_beam(direct_beam)
qspace_h5.set_channels_per_degree(channels_per_degree) qspace_h5.set_channels_per_degree(channels_per_degree)
qspace_h5.set_maxipix_correction(maxipix_correction)
if normalizer is None: if normalizer is None:
normalizer = '' normalizer = ''
...@@ -1224,6 +1239,7 @@ def _to_qspace(th_idx, ...@@ -1224,6 +1239,7 @@ def _to_qspace(th_idx,
entries, entries,
img_size, img_size,
output_fn, output_fn,
maxipix_correction,
normalizer, normalizer,
medfilt_dims, medfilt_dims,
img_dtype): img_dtype):
...@@ -1234,6 +1250,8 @@ def _to_qspace(th_idx, ...@@ -1234,6 +1250,8 @@ def _to_qspace(th_idx,
:param entries: :param entries:
:param img_size: :param img_size:
:param output_fn: :param output_fn:
:param bool maxipix_correction:
Whether to apply maxipix correction or not
:param str normalizer: :param str normalizer:
Name of measurement group dataset to use for normalization Name of measurement group dataset to use for normalization
:param medfilt_dims: :param medfilt_dims:
...@@ -1277,7 +1295,7 @@ def _to_qspace(th_idx, ...@@ -1277,7 +1295,7 @@ def _to_qspace(th_idx,
# h_lut.shape = (n_xy, -1) # h_lut.shape = (n_xy, -1)
h_lut = h_lut_shared h_lut = h_lut_shared
if normalizer and img_dtype.kind != 'f': if (maxipix_correction or normalizer) and img_dtype.kind != 'f':
# Force the type to float64 # Force the type to float64
logger.info('Using float64 to perform normalization') logger.info('Using float64 to perform normalization')
img_dtype = np.float64 img_dtype = np.float64
...@@ -1342,6 +1360,15 @@ def _to_qspace(th_idx, ...@@ -1342,6 +1360,15 @@ def _to_qspace(th_idx,
t_read += time.time() - t0 t_read += time.time() - t0
t0 = time.time() t0 = time.time()
# Apply maxipix correction
if maxipix_correction:
# TODO handle image ROI
img[255:258] = img[255] / 3
img[258:261] = img[260] / 3
img[:, 255:258] = (img[:, 255] / 3)[:, None]
img[:, 258:261] = (img[:, 260] / 3)[:, None]
# Apply normalization # Apply normalization
if normalizer: if normalizer:
......
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