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

per-config display of unit selections #3166

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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',)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.has_sb = self.has_angle or self.config in ('imviz',)
self._has_sb = self.has_angle or self.config in ('imviz',)

As per "convention," should this be "hidden" then if read only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traitlets cannot have leading underscores, and this is not exposed to the user

# 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
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 =' : 'Flux or Surface Brightness'"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed this string in the rebase, unless you meant to change it back from the more general language.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, missed that too 🤦 Reverted to "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>
Loading