Skip to content

Commit

Permalink
Merge pull request #3212 from kecnry/mm-continuum-units
Browse files Browse the repository at this point in the history
Moment map continuum unit conversion
  • Loading branch information
pllim authored Oct 7, 2024
2 parents 770dfd1 + 14a6801 commit 0f46989
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def __init__(self, *args, **kwargs):
'continuum_dataset_selected',
filters=['not_child_layer',
'layer_in_spectrum_viewer'])
# since the continuum is just an approximation preview,
# automatically convert the units instead of recomputing
self.continuum_auto_update_units = True

# when plugin is initialized, there won't be a dataset selected, so
# call the output unit 'Flux' for now (rather than surface brightness).
Expand Down
4 changes: 2 additions & 2 deletions jdaviz/core/marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,10 @@ def __init__(self, viewer, x=[], y=[], **kwargs):

class LineAnalysisContinuum(PluginLine):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# units do not need to be updated because the plugin itself reruns
# the computation and automatically changes the arrays themselves
self.auto_update_units = False
self.auto_update_units = kwargs.pop('auto_update_units', False)
super().__init__(*args, **kwargs)


class LineAnalysisContinuumCenter(LineAnalysisContinuum):
Expand Down
23 changes: 20 additions & 3 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2895,6 +2895,9 @@ class SpectralContinuumMixin(VuetifyTemplate, HubListener):
continuum_subset_selected = Unicode().tag(sync=True)

continuum_width = FloatHandleEmpty(3).tag(sync=True)
# whether continuum marks should update on unit change or
# if the plugin will handle that logic
continuum_auto_update_units = Bool(False).tag(sync=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -2932,15 +2935,29 @@ def continuum_marks(self):
return {}
# then haven't been initialized yet, so initialize with empty
# marks that will be populated once the first analysis is done.
marks = {'left': LineAnalysisContinuumLeft(viewer, visible=self.is_active),
'center': LineAnalysisContinuumCenter(viewer, visible=self.is_active),
'right': LineAnalysisContinuumRight(viewer, visible=self.is_active)}
marks = {'left': LineAnalysisContinuumLeft(viewer,
auto_update_units=self.continuum_auto_update_units, # noqa
visible=self.is_active),
'center': LineAnalysisContinuumCenter(viewer,
auto_update_units=self.continuum_auto_update_units, # noqa
visible=self.is_active),
'right': LineAnalysisContinuumRight(viewer,
auto_update_units=self.continuum_auto_update_units, # noqa
visible=self.is_active)}
shadows = [ShadowLine(mark, shadow_width=2) for mark in marks.values()]
# NOTE: += won't trigger the figure to notice new marks
viewer.figure.marks = viewer.figure.marks + shadows + list(marks.values())

return marks

@observe('continuum_auto_update_units')
def _set_auto_update_units(self, event=None):
for mark in self.continuum_marks.values():
# LineAnalysis recomputes the continuum on a change to units,
# but here since the continuum is just visual and an approximation,
# let's just convert units on the mark itself
mark.auto_update_units = self.continuum_auto_update_units

def _update_continuum_marks(self, mark_x={}, mark_y={}):
for pos, mark in self.continuum_marks.items():
mark.update_xy(mark_x.get(pos, []), mark_y.get(pos, []))
Expand Down

0 comments on commit 0f46989

Please sign in to comment.