Skip to content

Commit

Permalink
Fixing errors after rebase to main
Browse files Browse the repository at this point in the history
  • Loading branch information
rosteen committed Jan 6, 2025
1 parent 9fcb2bc commit 787141a
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 28 deletions.
4 changes: 1 addition & 3 deletions jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,7 @@ def _link_new_data(self, reference_data=None, data_to_be_linked=None):
spectral_axis_index = dc[0].meta['spectral_axis_index']
ref_wavelength_component = dc[0].components[spectral_axis_index]
# May need to update this for specutils 2
ref_flux_component = dc[0].components[6]
linked_wavelength_component = dc[-1].components[1]
linked_flux_component = dc[-1].components[-1]

dc.add_link(LinkSame(ref_wavelength_component, linked_wavelength_component))
return
Expand Down Expand Up @@ -1089,7 +1087,7 @@ def _get_range_subset_bounds(self, subset_state,
if ndim == 2:
units = u.pix
else:
handler, _ = data_translator.get_handler_for(Spectrum1D)
handler, _ = data_translator.get_handler_for(Spectrum)
spec = handler.to_object(data)
units = spec.spectral_axis.unit

Expand Down
2 changes: 0 additions & 2 deletions jdaviz/configs/cubeviz/helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from jdaviz.core.events import SnackbarMessage
from jdaviz.core.helpers import ImageConfigHelper
from jdaviz.configs.default.plugins.line_lists.line_list_mixin import LineListMixin
from jdaviz.configs.specviz import Specviz
from jdaviz.core.events import AddDataMessage, SnackbarMessage
Expand Down
4 changes: 2 additions & 2 deletions jdaviz/configs/cubeviz/plugins/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def parse_data(app, file_obj, data_type=None, data_label=None,
if isinstance(file_obj, fits.hdu.hdulist.HDUList):
try:
_parse_spectrum1d_3d(
app, Spectrum1D.read(file_obj), data_label=data_label,
app, Spectrum.read(file_obj), data_label=data_label,
flux_viewer_reference_name=flux_viewer_reference_name,
uncert_viewer_reference_name=uncert_viewer_reference_name
)
Expand Down Expand Up @@ -128,7 +128,7 @@ def parse_data(app, file_obj, data_type=None, data_label=None,
else:
try:
_parse_spectrum1d_3d(
app, Spectrum1D.read(hdulist), data_label=data_label or file_name,
app, Spectrum.read(hdulist), data_label=data_label or file_name,
flux_viewer_reference_name=flux_viewer_reference_name,
uncert_viewer_reference_name=uncert_viewer_reference_name
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def test_spectral_extraction_scientific_validation(
calspec_fitsrec = fits.getdata(calspec_url)
column_units = [u.AA] + 2 * [u.Unit('erg s-1 cm-2 AA-1')]
spectra_table = QTable(calspec_fitsrec, units=column_units)
model_spectrum = Spectrum1D(
model_spectrum = Spectrum(
flux=spectra_table['FLUX'],
spectral_axis=spectra_table['WAVELENGTH']
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def test_incompatible_units(specviz_helper, spectrum1d):
def test_cube_fit_with_nans(cubeviz_helper):
flux = np.ones((7, 8, 9)) * u.nJy
flux[:, :, 0] = np.nan
spec = Spectrum1D(flux=flux)
spec = Spectrum(flux=flux)
cubeviz_helper.load_data(spec, data_label="test")

mf = cubeviz_helper.plugins["Model Fitting"]
Expand All @@ -426,7 +426,7 @@ def test_cube_fit_with_subset_and_nans(cubeviz_helper):
# Also test with existing mask
flux = np.ones((7, 8, 9)) * u.nJy
flux[:, :, 0] = np.nan
spec = Spectrum1D(flux=flux)
spec = Spectrum(flux=flux)
spec.flux[5, 5, 7] = 10 * u.nJy
cubeviz_helper.load_data(spec, data_label="test")

Expand All @@ -448,7 +448,7 @@ def test_fit_with_count_units(cubeviz_helper):
flux = np.random.random((7, 8, 9)) * u.count
spectral_axis = np.linspace(4000, 5000, flux.shape[-1]) * u.AA

spec = Spectrum1D(flux=flux, spectral_axis=spectral_axis)
spec = Spectrum(flux=flux, spectral_axis=spectral_axis)
cubeviz_helper.load_data(spec, data_label="test")

mf = cubeviz_helper.plugins["Model Fitting"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_fit_cube_no_wcs(cubeviz_helper):


def test_toggle_cube_fit_subset(cubeviz_helper):
sp = Spectrum1D(flux=np.ones((7, 8, 9)) * u.nJy) # ny, nx, nz
sp = Spectrum(flux=np.ones((7, 8, 9)) * u.nJy) # ny, nx, nz
cubeviz_helper.load_data(sp, data_label="test_cube")
mf = cubeviz_helper.plugins['Model Fitting']

Expand Down
6 changes: 3 additions & 3 deletions jdaviz/configs/specviz/plugins/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def specviz_spectrum1d_parser(app, data, data_label=None, format=None, show_in_v
"returned an empty list")
elif path.is_file():
try:
data = Spectrum1D.read(str(path), format=format)
data = Spectrum.read(str(path), format=format)
if data.flux.ndim == 2:
data = split_spectrum_with_2D_flux_array(data)
else:
Expand Down Expand Up @@ -293,7 +293,7 @@ def split_spectrum_with_2D_flux_array(data):
unc = data.uncertainty[i, :]
if data.mask is not None:
mask = data.mask[i, :]
new_data.append(Spectrum1D(flux=data.flux[i, :], spectral_axis=data.spectral_axis,
uncertainty=unc, mask=mask, meta=data.meta))
new_data.append(Spectrum(flux=data.flux[i, :], spectral_axis=data.spectral_axis,
uncertainty=unc, mask=mask, meta=data.meta))

return new_data
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_value_error_exception(specviz_helper, spectrum1d, new_spectral_axis, ne


def test_initialize_specviz_sb(specviz_helper, spectrum1d):
spec_sb = Spectrum1D(spectrum1d.flux/u.sr, spectrum1d.spectral_axis)
spec_sb = Spectrum(spectrum1d.flux/u.sr, spectrum1d.spectral_axis)
specviz_helper.load_data(spec_sb, data_label="Test 1D Spectrum")
plg = specviz_helper.plugins["Unit Conversion"]
assert plg._obj.flux_unit == "Jy"
Expand Down
8 changes: 4 additions & 4 deletions jdaviz/configs/specviz/tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,15 @@ def test_load_spectrum_list_directory_concat(tmpdir, specviz_helper):
def test_load_2d_flux(specviz_helper):
# Test loading a spectrum with a 2D flux, which should be split into separate
# 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)"))
spec = Spectrum(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")

assert len(specviz_helper.app.data_collection) == 4
assert specviz_helper.app.data_collection[0].label == "test [0]"

spec2 = Spectrum1D(spectral_axis=np.linspace(4000, 6000, 10)*u.Angstrom,
flux=np.ones((2, 10))*u.Unit("1e-17 erg / (Angstrom cm2 s)"))
spec2 = Spectrum(spectral_axis=np.linspace(4000, 6000, 10)*u.Angstrom,
flux=np.ones((2, 10))*u.Unit("1e-17 erg / (Angstrom cm2 s)"))

# Make sure 2D spectra in a SpectrumList also get split properly.
spec_list = SpectrumList([spec, spec2])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ def test_horne_extract_self_profile(specviz2d_helper):
spec2d[:, ii] = gaus

wave = np.arange(0, spec2d.shape[1], 1)
objectspec = Spectrum1D(spectral_axis=wave*u.m,
flux=spec2d*u.Jy,
uncertainty=VarianceUncertainty(spec2dvar*u.Jy*u.Jy))
objectspec = Spectrum(spectral_axis=wave*u.m,
flux=spec2d*u.Jy,
uncertainty=VarianceUncertainty(spec2dvar*u.Jy*u.Jy))

specviz2d_helper.load_data(objectspec)
pext = specviz2d_helper.app.get_tray_item_from_name('spectral-extraction')
Expand Down
8 changes: 4 additions & 4 deletions jdaviz/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,10 @@ def _handle_display_units(self, data, use_display_units=True):
* u.Unit(spectral_unit))

data = Spectrum(spectral_axis=new_spec,
flux=new_y,
uncertainty=new_uncert,
mask=data.mask,
spectral_axis_index=data.meta['spectral_axis_index'])
flux=new_y,
uncertainty=new_uncert,
mask=data.mask,
spectral_axis_index=data.meta['spectral_axis_index'])
else: # pragma: nocover
raise NotImplementedError(f"converting {data.__class__.__name__} to display units is not supported") # noqa
return data
Expand Down
2 changes: 1 addition & 1 deletion jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3240,7 +3240,7 @@ def _get_continuum(self, dataset, spectral_subset, update_marks=False, per_pixel
min_x = min(spectral_axis.value)
if per_pixel:
# full_spectrum.flux is a cube, so we want to act on all spaxels independently
continuum_y = np.take(full_spectrum.flux, continuum_mask, axis=spectral_axis_index).value
continuum_y = np.take(full_spectrum.flux, continuum_mask, axis=spectral_axis_index).value # noqa

def fit_continuum(continuum_y_spaxel):
return np.polyfit(continuum_x-min_x, continuum_y_spaxel, deg=1)
Expand Down

0 comments on commit 787141a

Please sign in to comment.