Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Spectrum1D reading from file with flux in counts #1018

Merged
merged 3 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion specutils/io/parsing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def _find_spectral_column(table, columns_to_search, spectral_axis):
u.spectral_density() equivalencies. If none meet that criterion,
look for other likely length units such as 'adu' or 'cts/s'.
"""
additional_valid_units = [u.Unit('adu'), u.Unit('ct/s')]
additional_valid_units = [u.Unit('adu'), u.Unit('ct/s'), u.Unit('count')]
found_column = None

# First, search for a column with units compatible with Janskies
Expand Down
12 changes: 12 additions & 0 deletions specutils/tests/test_spectrum1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,18 @@ def test_create_with_uncertainty():
Spectrum1D(spectral_axis=wavelengths*u.um, flux=flux, uncertainty=uncertainty)


@pytest.mark.parametrize("flux_unit", ["adu", "ct/s", "count"])
def test_flux_unit_io_roundtrip(tmp_path, flux_unit):
# regression test for https://github.com/astropy/specutils/pull/1018
fname = str(tmp_path / 'flux_unit_io_roundtrip.fits')
sp = Spectrum1D(flux=np.ones(11) * u.Unit(flux_unit),
spectral_axis=np.arange(1, 12) * u.Unit('Hz'))
sp.write(fname, overwrite=True)

sp_load = Spectrum1D.read(fname)
assert sp_load.flux.unit == sp.flux.unit


@pytest.mark.filterwarnings('ignore::astropy.io.fits.verify.VerifyWarning')
@remote_access([{'id': '1481190', 'filename': 'L5g_0355+11_Cruz09.fits'}])
def test_read_linear_solution(remote_data_path):
Expand Down