Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moment map continuum unit conversion #3212

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -559,10 +559,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 @@
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 @@
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

Check warning on line 2959 in jdaviz/core/template_mixin.py

View check run for this annotation

Codecov / codecov/patch

jdaviz/core/template_mixin.py#L2959

Added line #L2959 was not covered by tests

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
Loading