Skip to content

Commit

Permalink
per-config display of unit selections (#3166)
Browse files Browse the repository at this point in the history
* per-config display of unit selections and customizable downstream
  • Loading branch information
kecnry authored Sep 9, 2024
1 parent 5ae74cb commit 3f80eb5
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 36 deletions.
53 changes: 41 additions & 12 deletions jdaviz/configs/specviz/plugins/unit_conversion/unit_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,25 @@ class UnitConversion(PluginTemplateMixin):
"""
template_file = __file__, "unit_conversion.vue"

has_spectral = Bool(False).tag(sync=True)
spectral_unit_items = List().tag(sync=True)
spectral_unit_selected = Unicode().tag(sync=True)

has_flux = Bool(False).tag(sync=True)
flux_unit_items = List().tag(sync=True)
flux_unit_selected = Unicode().tag(sync=True)

sb_unit_selected = Unicode().tag(sync=True)

has_angle = Bool(False).tag(sync=True)
angle_unit_items = List().tag(sync=True)
angle_unit_selected = Unicode().tag(sync=True)

has_sb = Bool(False).tag(sync=True)
sb_unit_selected = Unicode().tag(sync=True)

has_time = Bool(False).tag(sync=True)
time_unit_items = List().tag(sync=True)
time_unit_selected = Unicode().tag(sync=True)

spectral_y_type_items = List().tag(sync=True)
spectral_y_type_selected = Unicode().tag(sync=True)

Expand Down Expand Up @@ -97,30 +105,51 @@ def __init__(self, *args, **kwargs):
self.session.hub.subscribe(self, AddDataToViewerMessage,
handler=self._find_and_convert_contour_units)

self.has_spectral = self.config in ('specviz', 'cubeviz', 'specviz2d', 'mosviz')
self.spectral_unit = UnitSelectPluginComponent(self,
items='spectral_unit_items',
selected='spectral_unit_selected')

self.spectral_y_type = SelectPluginComponent(self,
items='spectral_y_type_items',
selected='spectral_y_type_selected',
manual_options=['Surface Brightness', 'Flux'])

self.has_flux = self.config in ('specviz', 'cubeviz', 'specviz2d', 'mosviz')
self.flux_unit = UnitSelectPluginComponent(self,
items='flux_unit_items',
selected='flux_unit_selected')

self.has_angle = self.config in ('cubeviz', 'specviz', 'mosviz')
self.angle_unit = UnitSelectPluginComponent(self,
items='angle_unit_items',
selected='angle_unit_selected')

self.has_sb = self.has_angle or self.config in ('imviz',)
# NOTE: always read_only, exposed through sb_unit property

self.has_time = False
self.time_unit = UnitSelectPluginComponent(self,
items='time_unit_items',
selected='time_unit_selected')

self.spectral_y_type = SelectPluginComponent(self,
items='spectral_y_type_items',
selected='spectral_y_type_selected',
manual_options=['Surface Brightness', 'Flux'])

@property
def user_api(self):
if self.app.config == 'cubeviz':
expose = ('spectral_unit', 'spectral_y_type', 'flux_unit', 'angle_unit', 'sb_unit')
else:
expose = ('spectral_unit', 'flux_unit', 'angle_unit')
return PluginUserApi(self, expose=expose)
expose = []
readonly = []
if self.has_spectral:
expose += ['spectral_unit']
if self.has_flux:
expose += ['flux_unit']
if self.has_angle:
expose += ['angle_unit']
if self.has_sb:
readonly = ['sb_unit']
if self.has_time:
expose += ['time_unit']
if self.config == 'cubeviz':
expose += ['spectral_y_type']
return PluginUserApi(self, expose=expose, readonly=readonly)

@property
def sb_unit(self):
Expand Down
63 changes: 39 additions & 24 deletions jdaviz/configs/specviz/plugins/unit_conversion/unit_conversion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:popout_button="popout_button"
:scroll_to.sync="scroll_to">

<v-row>
<v-row v-if="has_spectral">
<v-select
:menu-props="{ left: true }"
attach
Expand All @@ -22,7 +22,20 @@
></v-select>
</v-row>

<v-row>
<v-row v-if="has_time">
<v-select
:menu-props="{ left: true }"
attach
:items="time_unit_items.map(i => i.label)"
v-model="time_unit_selected"
:label="api_hints_enabled ? 'plg.time_unit =' : 'Time Unit'"
:class="api_hints_enabled ? 'api-hint' : null"
hint="Global display unit for time axis."
persistent-hint
></v-select>
</v-row>

<v-row v-if="has_flux">
<v-select
:menu-props="{ left: true }"
attach
Expand All @@ -34,8 +47,8 @@
persistent-hint
></v-select>
</v-row>

<v-row v-if="config in ['cubeviz', 'imviz', 'mosviz']">
<v-row v-if="has_angle">
<v-select
:menu-props="{ left: true }"
attach
Expand All @@ -49,7 +62,7 @@
></v-select>
</v-row>

<v-row>
<v-row v-if="has_spectral">
<v-text-field
v-model="sb_unit_selected"
:label="api_hints_enabled ? 'plg.sb_unit' : 'Surface Brightness Unit'"
Expand All @@ -60,27 +73,29 @@
></v-text-field>
</v-row>

<v-row v-if="config == 'cubeviz'">
<v-divider></v-divider>
</v-row>
<div v-if="config == 'cubeviz'">
<v-row>
<v-divider></v-divider>
</v-row>

<v-row v-if="config == 'cubeviz'">
<v-select
:menu-props="{ left: true }"
attach
:items="spectral_y_type_items.map(i => i.label)"
v-model="spectral_y_type_selected"
:label="api_hints_enabled ? 'plg.spectral_y_type =' : 'Spectral y-axis Type'"
:class="api_hints_enabled ? 'api-hint' : null"
hint="Select the y-axis physical type for the spectrum-viewer."
persistent-hint
></v-select>
</v-row>
<v-row>
<v-select
:menu-props="{ left: true }"
attach
:items="spectral_y_type_items.map(i => i.label)"
v-model="spectral_y_type_selected"
:label="api_hints_enabled ? 'plg.spectral_y_type =' : 'Spectral y-axis Type'"
:class="api_hints_enabled ? 'api-hint' : null"
hint="Select the y-axis physical type for the spectrum-viewer."
persistent-hint
></v-select>
</v-row>

<v-alert type="warning" v-if="!pixar_sr_exists && config == 'cubeviz'">
PIXAR_SR FITS header keyword not found when parsing spectral cube.
Flux/Surface Brightness will use default PIXAR_SR value of 1.
</v-alert>
<v-alert type="warning" v-if="!pixar_sr_exists">
PIXAR_SR FITS header keyword not found when parsing spectral cube.
Flux/Surface Brightness will use default PIXAR_SR value of 1.
</v-alert>
</div>

</j-tray-plugin>
</template>

0 comments on commit 3f80eb5

Please sign in to comment.