diff --git a/specutils/io/parsing_utils.py b/specutils/io/parsing_utils.py index 9fd8702ec..b2d4437ca 100644 --- a/specutils/io/parsing_utils.py +++ b/specutils/io/parsing_utils.py @@ -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 diff --git a/specutils/tests/test_spectrum1d.py b/specutils/tests/test_spectrum1d.py index cc6856760..07b535c0a 100644 --- a/specutils/tests/test_spectrum1d.py +++ b/specutils/tests/test_spectrum1d.py @@ -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):