Skip to content

Commit

Permalink
support exporting continuum cube
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Dec 5, 2023
1 parent 0c29d77 commit 292b7d9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
53 changes: 51 additions & 2 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import numpy as np

from traitlets import Bool, List, Unicode, observe
from specutils import manipulation, analysis
from specutils import manipulation, analysis, Spectrum1D

from jdaviz.core.custom_traitlets import IntHandleEmpty, FloatHandleEmpty
from jdaviz.core.events import SnackbarMessage
from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import (PluginTemplateMixin,
DatasetSelectMixin,
SpectralSubsetSelectMixin,
AddResults,
AddResultsMixin,
SelectPluginComponent,
SpectralContinuumMixin,
Expand Down Expand Up @@ -57,6 +58,15 @@ class MomentMap(PluginTemplateMixin, DatasetSelectMixin, SpectralSubsetSelectMix
template_file = __file__, "moment_maps.vue"
uses_active_status = Bool(True).tag(sync=True)

continuum_results_label = Unicode().tag(sync=True)
continuum_results_label_default = Unicode().tag(sync=True)
continuum_results_label_auto = Bool(True).tag(sync=True)
continuum_results_label_invalid_msg = Unicode('').tag(sync=True)
continuum_results_label_overwrite = Bool().tag(sync=True)
continuum_add_to_viewer_items = List().tag(sync=True)
continuum_add_to_viewer_selected = Unicode().tag(sync=True)
continuum_spinner = Bool(False).tag(sync=True)

n_moment = IntHandleEmpty(0).tag(sync=True)
filename = Unicode().tag(sync=True)
moment_available = Bool(False).tag(sync=True)
Expand All @@ -76,6 +86,16 @@ def __init__(self, *args, **kwargs):

self.moment = None

self.continuum_add_results = AddResults(self, 'continuum_results_label',
'continuum_results_label_default',
'continuum_results_label_auto',
'continuum_results_label_invalid_msg',
'continuum_results_label_overwrite',
'continuum_add_to_viewer_items',
'continuum_add_to_viewer_selected')
self.continuum_add_results.viewer.filters = ['is_image_viewer']
self.continuum_results_label_default = 'continuum'

self.output_unit = SelectPluginComponent(self,
items='output_unit_items',
selected='output_unit_selected',
Expand Down Expand Up @@ -107,6 +127,7 @@ def user_api(self):
# accross all plugins at some point
return PluginUserApi(self, expose=('dataset', 'spectral_subset',
'continuum', 'continuum_width',
'continuum_add_results', 'calculate_continuum',
'n_moment',
'output_unit', 'reference_wavelength',
'add_results', 'calculate_moment'))
Expand All @@ -122,6 +143,8 @@ def _set_default_results_label(self, event={}):
label_comps = []
if hasattr(self, 'dataset') and len(self.dataset.labels) > 1:
label_comps += [self.dataset_selected]
self.continuum_results_label_default = " ".join(label_comps) + " continuum"

label_comps += [f"moment {self.n_moment}"]
self.results_label_default = " ".join(label_comps)

Expand Down Expand Up @@ -150,7 +173,33 @@ def _calculate_continuum(self, msg=None):
self.spectral_subset,
update_marks=True)

@with_spinner()
@with_spinner('continuum_spinner')
def calculate_continuum(self, add_data=True):
# TODO: need to account for _orig_spec here?
cube, continuum_cube, sub_cube = self._get_continuum(self.dataset,
'per-pixel',
self.spectral_subset,
update_marks=False)

full_cube = self.dataset.selected_obj
_, inds, _ = np.intersect1d(full_cube.spectral_axis.value, sub_cube.spectral_axis.value,
assume_unique=True, return_indices=True)
flux = np.full(full_cube.flux.shape, np.nan)
flux[:, :, inds] = continuum_cube

full_continuum_cube = Spectrum1D(spectral_axis=full_cube.spectral_axis,
flux=flux*full_cube.flux.unit,
wcs=full_cube.wcs)

if add_data:
self.continuum_add_results.add_results_from_plugin(full_continuum_cube)

return full_continuum_cube

def vue_calculate_continuum(self, *args):
self.calculate_continuum(add_data=True)

@with_spinner('')
def calculate_moment(self, add_data=True):
"""
Calculate the moment map
Expand Down
31 changes: 31 additions & 0 deletions jdaviz/configs/cubeviz/plugins/moment_maps/moment_maps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,37 @@
</v-text-field>
</v-row>

<v-row v-if="continuum_subset_selected !== 'None'">
<v-expansion-panels accordion>
<v-expansion-panel>
<v-expansion-panel-header v-slot="{ open }">
<span style="padding: 6px">Export Continuum</span>
</v-expansion-panel-header>
<v-expansion-panel-content class="plugin-expansion-panel-content">
<j-docs-link>
Expose the continuum (as a cube).
{{spectral_subset_selected!='Entire Spectrum' ? 'Fluxes in slices outside of \''+spectral_subset_selected+'\' will be padded with nans.' : null}}
</j-docs-link>
<plugin-add-results
:label.sync="continuum_results_label"
:label_default="continuum_results_label_default"
:label_auto.sync="continuum_results_label_auto"
:label_invalid_msg="continuum_results_label_invalid_msg"
:label_overwrite="continuum_results_label_overwrite"
label_hint="Label for the continuum cube"
:add_to_viewer_items="continuum_add_to_viewer_items"
:add_to_viewer_selected.sync="continuum_add_to_viewer_selected"
action_label="Calculate"
action_tooltip="Calculate Continuum Cube"
:action_spinner="continuum_spinner"
@click:action="calculate_continuum"
></plugin-add-results>
</v-expansion-panel-content>
</v-expansion-panel>
</v-expansion-panels>
</v-row>


<j-plugin-section-header>Moment</j-plugin-section-header>
<v-row>
<j-docs-link>Options for generating the moment map.</j-docs-link>
Expand Down

0 comments on commit 292b7d9

Please sign in to comment.