Skip to content

Commit

Permalink
update to make use of FitTrace
Browse files Browse the repository at this point in the history
  • Loading branch information
kecnry committed Nov 15, 2022
1 parent 11543ab commit 0f53528
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class SpectralExtraction(PluginTemplateMixin):
* ``trace_type`` (:class:`~jdaviz.core.template_mixin.SelectPluginComponent`):
controls the type of trace to be generated.
* ``trace_peak_method`` (:class:`~jdaviz.core.template_mixin.SelectPluginComponent`):
only applicable if ``trace_type`` is set to ``Auto``.
only applicable if ``trace_type`` is not ``Flat``.
* :attr:`trace_pixel` :
pixel of the trace. If ``trace_type`` is set to ``Auto``, then this
pixel of the trace. If ``trace_type`` is not ``Flat``, then this
is the "guess" for the automated trace.
* :attr:`trace_bins` :
only applicable if ``trace_type`` is set to ``Auto``.
only applicable if ``trace_type`` is not ``Flat``.
* :attr:`trace_window` :
full width of the trace.
* :meth:`import_trace`
Expand Down Expand Up @@ -217,7 +217,7 @@ def __init__(self, *args, **kwargs):
self.trace_peak_method = SelectPluginComponent(self,
items='trace_peak_method_items',
selected='trace_peak_method_selected',
manual_options=['Gaussian', 'Centroid' 'Max']) # noqa
manual_options=['Gaussian', 'Centroid', 'Max']) # noqa

self.trace_add_results = AddResults(self, 'trace_results_label',
'trace_results_label_default',
Expand Down Expand Up @@ -415,7 +415,7 @@ def _update_plugin_marks(self, *args):
sp1d = self.export_extract_spectrum(add_data=False)
except Exception as e:
# NOTE: ignore error, but will be raised when clicking ANY of the export buttons
# NOTE: AutoTrace or manual background are often giving a
# NOTE: FitTrace or manual background are often giving a
# "background regions overlapped" error from specreduce
self.ext_specreduce_err = repr(e)
self.marks['extract'].clear()
Expand Down Expand Up @@ -621,11 +621,12 @@ def import_trace(self, trace):
if isinstance(trace, tracing.FlatTrace):
self.trace_type_selected = 'Flat'
self.trace_pixel = trace.trace_pos
elif isinstance(trace, tracing.AutoTrace):
self.trace_type_selected = 'Auto'
elif isinstance(trace, tracing.FitTrace):
self.trace_type_selected = trace.trace_model.__class__.__name__.strip('1D')
self.trace_pixel = trace.guess
self.trace_window = trace.window
self.trace_bins = trace.bins
self.trace_order = trace.degree
elif isinstance(trace, tracing.ArrayTrace): # pragma: no cover
raise NotImplementedError(f"cannot import ArrayTrace into plugin. Use viz.load_trace instead") # noqa
else: # pragma: no cover
Expand Down Expand Up @@ -664,12 +665,12 @@ def export_trace(self, add_data=False, **kwargs):

elif self.trace_type_selected in _model_cls:
trace_model = _model_cls[self.trace_type_selected](degree=self.trace_order)
trace = tracing.AutoTrace(self.trace_dataset.selected_obj.data,
guess=self.trace_pixel,
bins=int(self.trace_bins),
window=self.trace_window,
peak_method=self.trace_peak_method_selected.lower(),
trace_model=trace_model)
trace = tracing.FitTrace(self.trace_dataset.selected_obj.data,
guess=self.trace_pixel,
bins=int(self.trace_bins),
window=self.trace_window,
peak_method=self.trace_peak_method_selected.lower(),
trace_model=trace_model)

else:
raise NotImplementedError(f"trace_type={self.trace_type_selected} not implemented")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
type="number"
v-model.number="trace_pixel"
:rules="[() => trace_pixel!=='' || 'This field is required']"
:hint="trace_type_selected === 'Flat' ? 'Pixel row for flat trace.' : 'Pixel row initial guess for auto trace.'"
:hint="trace_type_selected === 'Flat' ? 'Pixel row for flat trace.' : 'Pixel row initial guess for fitting the trace.'"
persistent-hint
>
</v-text-field>
Expand All @@ -113,19 +113,20 @@
</v-text-field>
</v-row>

<v-row v-if="trace_type_selected==='Auto'">
<v-row v-if="trace_type_selected!=='Flat'">
<v-text-field
label="Window Width"
type="number"
v-model.number="trace_window"
:rules="[() => trace_window!=='' || 'This field is required']"
:rules="[() => trace_window!=='' || 'This field is required',
() => trace_window > 0 || 'Window must be positive']"
hint="Width in rows to consider for peak finding."
persistent-hint
>
</v-text-field>
</v-row>

<v-row v-if="trace_type_selected==='Auto'">
<v-row v-if="trace_type_selected!=='Flat'">
<v-select
attach
:menu-props="{ left: true }"
Expand Down

0 comments on commit 0f53528

Please sign in to comment.