Skip to content

Commit

Permalink
in-plugin warning when dataset results in flux-scaling defaulting to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Oct 10, 2023
1 parent 0dfeb75 commit 2a9ab8c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SimpleAperturePhotometry(PluginTemplateMixin, DatasetMultiSelectMixin, Tab
pixel_area = FloatHandleEmpty(0).tag(sync=True)
counts_factor = FloatHandleEmpty(0).tag(sync=True)
flux_scaling_multi_auto = Bool(True).tag(sync=True)
flux_scaling_warning = Unicode("").tag(sync=True)
flux_scaling = FloatHandleEmpty(0).tag(sync=True)
result_available = Bool(False).tag(sync=True)
result_failed_msg = Unicode("").tag(sync=True)
Expand Down Expand Up @@ -180,6 +181,21 @@ def _get_defaults_from_metadata(self, dataset=None):

return defaults

@observe('flux_scaling_multi_auto')
def _multiselect_flux_scaling_warning(self, event={}):
if not self.flux_scaling_multi_auto:
self.flux_scaling_warning = ''
return
no_flux_scaling = [dataset for dataset in self.dataset.selected
if 'flux_scaling' not in self._get_defaults_from_metadata(dataset)]
if len(no_flux_scaling):
self.flux_scaling_warning = ('Could not determine flux scaling for '
f'{", ".join(no_flux_scaling)}. Those entries will '
'default to zero. Turn off auto-mode to provide '
'flux-scaling manually.')
else:
self.flux_scaling_warning = ''

@observe('dataset_selected')
def _dataset_selected_changed(self, event={}):
if not hasattr(self, 'dataset'):
Expand All @@ -188,14 +204,20 @@ def _dataset_selected_changed(self, event={}):
if self.dataset.selected_dc_item is None:
return
if self.multiselect:
# defaults are applied within the loop if the auto-switches are enabled
# defaults are applied within the loop if the auto-switches are enabled,
# but we still need to update the flux-scaling warning
self._multiselect_flux_scaling_warning()
return

try:
defaults = self._get_defaults_from_metadata()
self.counts_factor = 0
self.pixel_area = defaults.get('pixel_area', 0)
self.flux_scaling = defaults.get('flux_scaling', 0)
if 'flux_scaling' in defaults:
self.flux_scaling_warning = ''
else:
self.flux_scaling_warning = f'Could not determine flux scaling for {self.dataset.selected}, defaulting to zero.'

except Exception as e:
self.hub.broadcast(SnackbarMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
>
</v-text-field>
</v-row>
<v-row v-if="flux_scaling_warning.length > 0">
<span class="v-messages v-messages__message text--secondary" style="color: red !important">
{{flux_scaling_warning}}
</span>
</v-row>

<v-row v-if="!multiselect">
<v-select
Expand Down

0 comments on commit 2a9ab8c

Please sign in to comment.