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