Skip to content

Commit

Permalink
Do not reset threshold data when toggling visibility
Browse files Browse the repository at this point in the history
Signed-off-by: Brianna Major <[email protected]>
  • Loading branch information
bnmajor committed Jan 8, 2024
1 parent c7f7a19 commit 37b78de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
4 changes: 2 additions & 2 deletions hexrdgui/calibration/polarview.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ def apply_masks(self, img):
continue
mask_arr = mask.masked_arrays
total_mask = np.logical_or(total_mask, ~mask_arr)
if MaskManager().threshold_mask:
lt_val, gt_val = MaskManager().threshold_mask.data
if (tm := MaskManager().threshold_mask) and tm.visible:
lt_val, gt_val = tm.data
lt_mask = img < lt_val
gt_mask = img > gt_val
mask = np.logical_or(lt_mask, gt_mask)
Expand Down
15 changes: 8 additions & 7 deletions hexrdgui/masking/create_raw_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ def recompute_raw_threshold_mask():
if tm := MaskManager().threshold_mask:
for det in HexrdConfig().detector_names:
ims = HexrdConfig().imageseries(det)
masks = [None for i in range(len(ims))]
for idx in range(len(ims)):
img = HexrdConfig().image(det, idx)
mask = create_threshold_mask(img, tm.data)
masks[idx] = mask
if tm.visible:
masks = [None for i in range(len(ims))]
for idx in range(len(ims)):
img = HexrdConfig().image(det, idx)
mask = create_threshold_mask(img, tm.data)
masks[idx] = mask
else:
masks = np.ones(ims.shape, dtype=bool)
results[det] = masks
return results

Expand Down Expand Up @@ -83,6 +86,4 @@ def create_raw_mask(line_data):
def rebuild_raw_masks():
from hexrdgui.masking.mask_manager import MaskManager
for mask in MaskManager().masks.values():
if mask.type == MaskType.threshold:
continue
mask.update_masked_arrays(ViewType.raw)
20 changes: 2 additions & 18 deletions hexrdgui/masking/mask_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ def __init__(self, name='', mtype='', visible=True):
self.visible = visible
self.masked_arrays = None

def update_mask_visibility(self, visibility):
self.visible = visibility

# Abstract methods
@property
@abstractmethod
Expand Down Expand Up @@ -103,19 +100,6 @@ def __init__(self, name='', mtype='', visible=True):
super().__init__(name, mtype, visible)
self.min_val = -math.inf
self.max_val = math.inf
self._hidden_mask_data = None

def update_mask_visibility(self, visible):
if visible == self.visible:
return

self.visible = visible
if visible and self._hidden_mask_data:
self.data = self._hidden_mask_data
self._hidden_mask_data = None
elif not visible:
self._hidden_mask_data = self.data
self.data = [-math.inf, math.inf]

@property
def data(self):
Expand All @@ -127,7 +111,7 @@ def data(self, values):
self.max_val = values[1]
self.update_masked_arrays()

def update_masked_arrays(self):
def update_masked_arrays(self, view=ViewType.raw):
self.masked_arrays = recompute_raw_threshold_mask()

def serialize(self):
Expand Down Expand Up @@ -282,7 +266,7 @@ def update_view_mode(self, mode):
self.view_mode = mode

def update_mask_visibility(self, name, visibility):
self.masks[name].update_mask_visibility(visibility)
self.masks[name].visible = visibility

def threshold_toggled(self):
if self.threshold_mask:
Expand Down

0 comments on commit 37b78de

Please sign in to comment.