diff --git a/jdaviz/configs/specviz/helper.py b/jdaviz/configs/specviz/helper.py index dd3791cce0..321ada4efa 100644 --- a/jdaviz/configs/specviz/helper.py +++ b/jdaviz/configs/specviz/helper.py @@ -82,7 +82,7 @@ def load_data(self, data, data_label=None, format=None, show_in_viewer=True, default_labels = {'mosviz-spec2d-parser': '2D Spectrum', 'specreduce-trace': 'Trace', - 'specviz-spectrum1d-parser': 'Spectrum 1D'} + 'specviz-spectrum1d-parser': 'Spectrum'} if data_label is None: data_label = default_labels.get(parser, 'Unknown') data_label = self.app.return_unique_name(data_label) diff --git a/jdaviz/configs/specviz/tests/test_helper.py b/jdaviz/configs/specviz/tests/test_helper.py index 3c0f7f5223..bd144f3e86 100644 --- a/jdaviz/configs/specviz/tests/test_helper.py +++ b/jdaviz/configs/specviz/tests/test_helper.py @@ -60,7 +60,7 @@ def test_load_spectrum_list_no_labels(self): self.spec_app.load_data(self.spec_list) assert len(self.spec_app.app.data_collection) == 4 for i in (1, 2, 3): - assert "specviz_data" in self.spec_app.app.data_collection[i].label + assert "Spectrum" in self.spec_app.app.data_collection[i].label def test_load_spectrum_list_with_labels(self): # now load three more spectra from a SpectrumList, with labels: @@ -412,7 +412,7 @@ def test_load_2d_flux(specviz_helper): # 1D Spectrum1D objects to load in Specviz. spec = Spectrum1D(spectral_axis=np.linspace(4000, 6000, 10)*u.Angstrom, flux=np.ones((4, 10))*u.Unit("1e-17 erg / (Angstrom cm2 s)")) - specviz_helper.load_data(spec, data_label="test") + specviz_helper.load_data(spec, data_label="test", load_as_list=True) assert len(specviz_helper.app.data_collection) == 4 assert specviz_helper.app.data_collection[0].label == "test [0]" diff --git a/jdaviz/core/data_formats.py b/jdaviz/core/data_formats.py index 13ec295bbe..56b05468a4 100644 --- a/jdaviz/core/data_formats.py +++ b/jdaviz/core/data_formats.py @@ -101,15 +101,29 @@ def get_parser(obj, load_as_list=False): parser : str The parser for the data object """ + if isinstance(obj, (SpectrumList, SpectrumCollection)): + return 'specviz-spectrum1d-parser' if isinstance(obj, Trace): return 'specreduce-trace' - elif isinstance(obj, Spectrum1D): + if isinstance(obj, Spectrum1D): if obj.flux.ndim == 1: return 'specviz-spectrum1d-parser' else: if load_as_list: - return 'specviz-spectrumlist-parser' + return 'specviz-spectrum1d-parser' return 'mosviz-spec2d-parser' + if isinstance(obj, fits.HDUList): + columns = [c.name.lower() for hduitem in obj for c in getattr(hduitem, 'columns', [])] + if 'wavelength' in columns and 'flux' in columns: + return 'specviz-spectrum1d-parser' + else: + raise ValueError("cannot find valid parser for HDUList") + if isinstance(obj, list): + parsers = [get_parser(o, load_as_list=load_as_list) for o in obj] + if len(set(parsers)) > 1: + raise ValueError("cannot find single parser for list of objects") + return parsers[0] + _, config = get_valid_format(obj) parsers = {'specviz': 'specviz-spectrum1d-parser', 'specviz2d': 'mosviz-spec2d-parser'} return parsers.get(config)