Skip to content

Commit

Permalink
support background statistic choices
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Dec 14, 2022
1 parent 46f0ae2 commit e57350c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Specviz2d
- Update to be compatible with changes in specreduce 1.3, including FitTrace
with Polynomial, Spline, and Legendre options. [#1889]

- Add dropdown for choosing background statistic (average or median). [#1922]

API Changes
-----------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class SpectralExtraction(PluginTemplateMixin):
Separation from the referenced trace for the center of each of the background window(s).
* :attr:`bg_width` :
full width of each background window(s).
* ``bg_statistic`` (:class:`~jdaviz.core.template_mixin.SelectPluginComponent`):
statistic to use when computing the background. 'Average' will account for partial pixel
weights, 'Median' will include all partial pixels.
* ``bg_add_results`` (:class:`~jdaviz.core.template_mixin.AddResults`)
* ``bg_sub_add_results``
* :meth:`import_bg`
Expand Down Expand Up @@ -139,6 +142,9 @@ class SpectralExtraction(PluginTemplateMixin):

bg_trace_pixel = FloatHandleEmpty(0).tag(sync=True)

bg_statistic_items = List().tag(sync=True)
bg_statistic_selected = Unicode().tag(sync=True)

bg_separation = FloatHandleEmpty(0).tag(sync=True)
bg_width = FloatHandleEmpty(0).tag(sync=True)

Expand Down Expand Up @@ -252,6 +258,11 @@ def __init__(self, *args, **kwargs):
default_text='From Plugin',
filters=['is_trace'])

self.bg_statistic = SelectPluginComponent(self,
items='bg_statistic_items',
selected='bg_statistic_selected',
manual_options=['Average', 'Median'])

self.bg_add_results = AddResults(self, 'bg_results_label',
'bg_results_label_default',
'bg_results_label_auto',
Expand Down Expand Up @@ -323,6 +334,7 @@ def user_api(self):
'export_trace',
'bg_dataset', 'bg_type',
'bg_trace_pixel', 'bg_separation', 'bg_width',
'bg_statistic',
'bg_add_results', 'bg_sub_add_results',
'import_bg',
'export_bg', 'export_bg_img', 'export_bg_sub',
Expand Down Expand Up @@ -511,7 +523,7 @@ def _interaction_in_trace_step(self, event={}):

@observe('bg_dataset_selected', 'bg_type_selected',
'bg_trace_selected', 'bg_trace_pixel',
'bg_separation', 'bg_width', 'active_step')
'bg_separation', 'bg_width', 'bg_statistic_selected', 'active_step')
def _interaction_in_bg_step(self, event={}):
if not self.plugin_opened or not self._do_marks:
return
Expand Down Expand Up @@ -757,17 +769,20 @@ def export_bg(self, **kwargs):

if self.bg_type_selected == 'Manual':
bg = background.Background(self.bg_dataset.selected_obj,
[trace], width=self.bg_width)
[trace], width=self.bg_width,
statistic=self.bg_statistic.selected.lower())
elif self.bg_type_selected == 'OneSided':
bg = background.Background.one_sided(self.bg_dataset.selected_obj,
trace,
self.bg_separation,
width=self.bg_width)
width=self.bg_width,
statistic=self.bg_statistic.selected.lower())
elif self.bg_type_selected == 'TwoSided':
bg = background.Background.two_sided(self.bg_dataset.selected_obj,
trace,
self.bg_separation,
width=self.bg_width)
width=self.bg_width,
statistic=self.bg_statistic.selected.lower())
else: # pragma: no cover
raise NotImplementedError(f"bg_type={self.bg_type_selected} not implemented")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@
</v-text-field>
</v-row>

<v-row>
<v-select
attach
:menu-props="{ left: true }"
:items="bg_statistic_items.map(i => i.label)"
v-model="bg_statistic_selected"
label="Statistic"
hint="Statistic to use over the background window."
persistent-hint
></v-select>
</v-row>

<v-row>
<v-expansion-panels popout>
<v-expansion-panel>
Expand Down

0 comments on commit e57350c

Please sign in to comment.