Skip to content

Commit 3af6205

Browse files
committed
updates for Spectrum1D support in specreduce
1 parent 9a1d414 commit 3af6205

File tree

1 file changed

+14
-33
lines changed

1 file changed

+14
-33
lines changed

jdaviz/configs/specviz2d/plugins/spectral_extraction/spectral_extraction.py

+14-33
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
from jdaviz.core.custom_traitlets import IntHandleEmpty, FloatHandleEmpty
1414
from jdaviz.core.marks import PluginLine
1515

16-
from astropy.nddata import NDData, StdDevUncertainty, VarianceUncertainty, UnknownUncertainty
17-
from specutils import Spectrum1D
16+
from astropy.nddata import UnknownUncertainty
1817
from specreduce import tracing
1918
from specreduce import background
2019
from specreduce import extract
@@ -644,18 +643,18 @@ def export_trace(self, add_data=False, **kwargs):
644643
# being able to load back into the plugin)
645644
orig_trace = self.trace_trace.selected_obj
646645
if isinstance(orig_trace, tracing.FlatTrace):
647-
trace = tracing.FlatTrace(self.trace_dataset.selected_obj.data,
646+
trace = tracing.FlatTrace(self.trace_dataset.selected_obj,
648647
orig_trace.trace_pos+self.trace_offset)
649648
else:
650-
trace = tracing.ArrayTrace(self.trace_dataset.selected_obj.data,
649+
trace = tracing.ArrayTrace(self.trace_dataset.selected_obj,
651650
self.trace_trace.selected_obj.trace+self.trace_offset)
652651

653652
elif self.trace_type_selected == 'Flat':
654-
trace = tracing.FlatTrace(self.trace_dataset.selected_obj.data,
653+
trace = tracing.FlatTrace(self.trace_dataset.selected_obj,
655654
self.trace_pixel)
656655

657656
elif self.trace_type_selected == 'Auto':
658-
trace = tracing.KosmosTrace(self.trace_dataset.selected_obj.data,
657+
trace = tracing.KosmosTrace(self.trace_dataset.selected_obj,
659658
guess=self.trace_pixel,
660659
bins=int(self.trace_bins),
661660
window=self.trace_window,
@@ -674,7 +673,7 @@ def vue_create_trace(self, *args):
674673

675674
def _get_bg_trace(self):
676675
if self.bg_type_selected == 'Manual':
677-
trace = tracing.FlatTrace(self.trace_dataset.selected_obj.data,
676+
trace = tracing.FlatTrace(self.trace_dataset.selected_obj,
678677
self.bg_trace_pixel)
679678
elif self.bg_trace_selected == 'From Plugin':
680679
trace = self.export_trace(add_data=False)
@@ -736,15 +735,15 @@ def export_bg(self, **kwargs):
736735
trace = self._get_bg_trace()
737736

738737
if self.bg_type_selected == 'Manual':
739-
bg = background.Background(self.bg_dataset.selected_obj.data,
738+
bg = background.Background(self.bg_dataset.selected_obj,
740739
[trace], width=self.bg_width)
741740
elif self.bg_type_selected == 'OneSided':
742-
bg = background.Background.one_sided(self.bg_dataset.selected_obj.data,
741+
bg = background.Background.one_sided(self.bg_dataset.selected_obj,
743742
trace,
744743
self.bg_separation,
745744
width=self.bg_width)
746745
elif self.bg_type_selected == 'TwoSided':
747-
bg = background.Background.two_sided(self.bg_dataset.selected_obj.data,
746+
bg = background.Background.two_sided(self.bg_dataset.selected_obj,
748747
trace,
749748
self.bg_separation,
750749
width=self.bg_width)
@@ -763,10 +762,7 @@ def export_bg_img(self, add_data=False, **kwargs):
763762
Whether to add the resulting image to the application, according to the options
764763
defined in the plugin.
765764
"""
766-
bg = self.export_bg(**kwargs)
767-
768-
bg_spec = Spectrum1D(spectral_axis=self.bg_dataset.selected_obj.spectral_axis,
769-
flux=bg.bkg_image()*self.bg_dataset.selected_obj.flux.unit)
765+
bg_spec = self.export_bg(**kwargs).bkg_image()
770766

771767
if add_data:
772768
self.bg_add_results.add_results_from_plugin(bg_spec, replace=True)
@@ -792,8 +788,7 @@ def export_bg_spectrum(self, add_data=False, **kwargs):
792788
Whether to add the resulting spectrum to the application, according to the options
793789
defined in the plugin.
794790
"""
795-
bg = self.export_bg(**kwargs)
796-
spec = bg.bkg_spectrum()
791+
spec = self.export_bg(**kwargs).bkg_spectrum()
797792

798793
if add_data:
799794
self.bg_spec_add_results.add_results_from_plugin(spec, replace=False)
@@ -813,10 +808,7 @@ def export_bg_sub(self, add_data=False, **kwargs):
813808
Whether to add the resulting image to the application, according to the options
814809
defined in the plugin.
815810
"""
816-
bg = self.export_bg(**kwargs)
817-
818-
bg_sub_spec = Spectrum1D(spectral_axis=self.bg_dataset.selected_obj.spectral_axis,
819-
flux=bg.sub_image()*self.bg_dataset.selected_obj.flux.unit)
811+
bg_sub_spec = self.export_bg(**kwargs).sub_image()
820812

821813
if add_data:
822814
self.bg_sub_add_results.add_results_from_plugin(bg_sub_spec, replace=True)
@@ -867,13 +859,9 @@ def export_extract(self, **kwargs):
867859
inp_sp2d = self._get_ext_input_spectrum()
868860

869861
if self.ext_type_selected == 'Boxcar':
870-
ext = extract.BoxcarExtract(inp_sp2d.data, trace, width=self.ext_width)
862+
ext = extract.BoxcarExtract(inp_sp2d, trace, width=self.ext_width)
871863
elif self.ext_type_selected == 'Horne':
872-
uncert = inp_sp2d.uncertainty if inp_sp2d.uncertainty is not None else VarianceUncertainty(np.ones_like(inp_sp2d.data)) # noqa
873-
if not hasattr(uncert, 'uncertainty_type'):
874-
uncert = StdDevUncertainty(uncert)
875-
image = NDData(inp_sp2d.data, uncertainty=uncert)
876-
ext = extract.HorneExtract(image, trace)
864+
ext = extract.HorneExtract(inp_sp2d, trace)
877865
else:
878866
raise NotImplementedError(f"extraction type '{self.ext_type_selected}' not supported") # noqa
879867

@@ -892,13 +880,6 @@ def export_extract_spectrum(self, add_data=False, **kwargs):
892880
extract = self.export_extract(**kwargs)
893881
spectrum = extract.spectrum
894882

895-
# Specreduce returns a spectral axis in pixels, so we'll replace with input spectral_axis
896-
# NOTE: this is currently disabled until proper handling of axes-limit linking between
897-
# the 2D spectrum image (plotted in pixels) and a 1D spectrum (plotted in freq or
898-
# wavelength) is implemented.
899-
900-
# spectrum = Spectrum1D(spectral_axis=inp_sp2d.spectral_axis, flux=spectrum.flux)
901-
902883
if add_data:
903884
self.ext_add_results.add_results_from_plugin(spectrum, replace=False)
904885

0 commit comments

Comments
 (0)