Skip to content

Commit

Permalink
Pass a normal array is masking turned off
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysgt committed Apr 24, 2024
1 parent d2fc3b9 commit 4ba91e5
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions defdap/hrdic.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,6 @@ def set_crop(self, *, left=None, right=None, top=None, bottom=None,
y_dim = self.ydim - self.crop_dists[1, 0] - self.crop_dists[1, 1]
self.shape = (y_dim, x_dim)

self.data.generate('mask')

def crop(self, map_data, binning=None):
""" Crop given data using crop parameters stored in map
i.e. cropped_data = DicMap.crop(DicMap.data_to_crop).
Expand Down Expand Up @@ -452,16 +450,21 @@ def calc_mask(self, mask="unset_mask", dilation=0):
Parameters
----------
mask: numpy.array(bool)
A boolean array where points to be removed are True
mask: numpy.array(bool) or str('unset_mask')
A boolean array where points to be removed are True. Set to string 'unset_mask' to disable masking.
dilation: int, optional
Number of pixels to dilate the mask by. Useful to remove anomalous points
around masked values. No dilation applied if not specified.
Examples
----------
To remove data points in dic_map where `max_shear` is above 0.8, use:
To disable masking:
>>> mask = 'unset_mask'
To remove data points in dic_map where `max_shear` is above 0.8, use:
>>> mask = dic_map.data.max_shear > 0.8
To remove data points in dic_map where e11 is above 1 or less than -1, use:
Expand All @@ -476,10 +479,9 @@ def calc_mask(self, mask="unset_mask", dilation=0):
see :func:`defdap.hrdic.load_corr_val_data`
"""
if mask == "unset_mask":
mask = np.full((self.shape), fill_value = False)
if type(mask) == str and mask == "unset_mask":
return mask

if not isinstance(mask, np.ndarray) or mask.shape != self.shape:
raise ValueError('The mask must be a numpy array the same shape as '
'the cropped map.')
Expand All @@ -498,9 +500,11 @@ def calc_mask(self, mask="unset_mask", dilation=0):
def mask(self, map_data):
""" Values set to False in mask will be set to nan in map.
"""

return np.ma.array(map_data,
mask=np.broadcast_to(self.data.mask, np.shape(map_data)))
if self.data.mask == 'unset_mask':
return map_data
else:
return np.ma.array(map_data,
mask=np.broadcast_to(self.data.mask, np.shape(map_data)))

def set_pattern(self, img_path, window_size):
"""Set the path to the image of the pattern.
Expand Down

0 comments on commit 4ba91e5

Please sign in to comment.