Skip to content

Commit

Permalink
Avoid unecessary updates in FRBImage if limits and relevant settings …
Browse files Browse the repository at this point in the history
…haven't changed (unless called with force=True)
  • Loading branch information
astrofrog committed Oct 29, 2024
1 parent dc834e8 commit 7e3ab43
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions glue_jupyter/bqplot/image/frb_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def __init__(self, viewer, array_maker, compression='png'):
self.viewer.figure.axes[1].scale.observe(self.debounced_update, 'min')
self.viewer.figure.axes[1].scale.observe(self.debounced_update, 'max')

self._latest_hash = None

# NOTE: we deliberately don't call .update() here because when FRBImage
# is created for the main composite image layer the composite arrays
# haven't been set up yet, and for subset layers the layer gets force
Expand All @@ -62,7 +64,7 @@ def external_padding(self, value):
if value > previous_value: # no point updating if the value is smaller than before
self.debounced_update()

def update(self, *args, **kwargs):
def update(self, *args, force=False, **kwargs):

# Shape can be (0, 0) when viewer was created and then destroyed.
if self.shape is None or np.allclose(self.shape, 0):
Expand All @@ -77,6 +79,11 @@ def update(self, *args, **kwargs):
if xmin is None or xmax is None or ymin is None or ymax is None:
return

current_hash = (xmin, xmax, ymin, ymax, self.external_padding)

if not force and current_hash == self._latest_hash:
return

ny, nx = self.shape

# Expand beyond the boundary
Expand All @@ -103,5 +110,7 @@ def update(self, *args, **kwargs):
else:
self.image = EMPTY_IMAGE

self._latest_hash = current_hash

def invalidate_cache(self):
self.update()
self.update(force=True)

0 comments on commit 7e3ab43

Please sign in to comment.