Commit a78f1f56 authored by Thomas Vincent's avatar Thomas Vincent

Save used mask in h5 qspace file

parent 94acd206
......@@ -175,6 +175,16 @@ class QSpaceH5(XsocsH5Base):
return [entry.decode() for entry in entries]
return []
@property
def mask(self):
"""Returns the mask selecting pixels in images.
Non-zero value means that the pixel is masked.
:rtype: Union[numpy.ndarray, None]
"""
return self._get_array_data(self.params_path + '/image_mask')
@property
def image_normalizer(self):
"""Returns the image normalizer used when converting to q space.
......@@ -401,6 +411,15 @@ class QSpaceH5Writer(QSpaceH5):
path = self.entries_path + '/has_shift'
self._set_scalar_data(path, has_shift)
def set_image_mask(self, mask):
"""Stores the image mask used when converting to q space
:param numpy.ndarray mask: Mask as a 2D image
"""
if mask is not None:
path = self.params_path + '/image_mask'
self._create_dataset(path, data=mask)
def set_image_normalizer(self, normalizer):
"""Stores the image normalizer used when converting to q space
......
......@@ -818,8 +818,9 @@ class QSpaceConverter(object):
'be of the same type. Found {0} and {1}.'
''.format(img_dtype, entry_dtype))
# Mark masked pixels (i.e., non zero in the mask) with NaN
q_ar[:, mask.reshape(-1) != 0, :] = np.nan
if mask is not None:
# Mark masked pixels (i.e., non zero in the mask) with NaN
q_ar[:, mask.reshape(-1) != 0, :] = np.nan
# custom bins range to have the same histo as
# xrayutilities.gridder3d
......@@ -933,7 +934,8 @@ class QSpaceConverter(object):
beam_energy=beam_energy,
direct_beam=center_chan,
channels_per_degree=chan_per_deg,
normalizer=normalizer)
normalizer=normalizer,
mask=mask)
manager = mp.Manager()
self.__term_evt = term_evt = manager.Event()
......@@ -1210,7 +1212,8 @@ def _create_result_file(h5_fn,
beam_energy=None,
direct_beam=None,
channels_per_degree=None,
normalizer=''):
normalizer='',
mask=None):
"""
Initializes the output file.
:param h5_fn: name of the file to initialize
......@@ -1236,6 +1239,8 @@ def _create_result_file(h5_fn,
:param channels_per_degree: Channels per degree calibration
:param str normalizer:
Name of measurement group dataset used for normalization
:param Union[numpy.ndarray, None] mask:
Mask used to discard pixels in images
"""
if not overwrite:
......@@ -1270,6 +1275,9 @@ def _create_result_file(h5_fn,
normalizer = ''
qspace_h5.set_image_normalizer(normalizer)
if mask is not None:
qspace_h5.set_image_mask(mask)
if shiftH5:
sample_shifts = []
grid_shifts = []
......
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