Skip to content

Commit 0edcfb2

Browse files
committed
Handle non-standard units more gracefully
1 parent 6720c9a commit 0edcfb2

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

synphot/specio.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,28 @@ def read_fits_spec(filename, ext=1, wave_col='WAVELENGTH', flux_col='FLUX',
198198
if not val:
199199
continue
200200
newval = units.validate_unit(val)
201-
subhdu.header[key] = newval.to_string("fits")
201+
subhdu.header[key] = newval.to_string() # Must be generic to handle mag # noqa: E501
202202

203-
t = QTable.read(subhdu)
203+
with warnings.catch_warnings():
204+
warnings.filterwarnings("ignore", category=u.UnitsWarning,
205+
message=".* did not parse as fits unit")
206+
t = QTable.read(subhdu)
204207
header = dict(fs["PRIMARY"].header)
205208

206209
# https://github.com/astropy/astropy/issues/16221
207210
lower_colnames = [c.lower() for c in t.colnames]
208211
t_col_wave = t.columns[lower_colnames.index(wave_col)]
212+
if t_col_wave.unit:
213+
t_col_wave_unit = units.validate_unit(t_col_wave.unit.to_string())
214+
else:
215+
t_col_wave_unit = u.dimensionless_unscaled
209216
t_col_flux = t.columns[lower_colnames.index(flux_col)]
210-
wavelengths = t_col_wave.value * (t_col_wave.unit or u.dimensionless_unscaled) # noqa: E501
211-
fluxes = t_col_flux.value * (t_col_flux.unit or u.dimensionless_unscaled) # noqa: E501
217+
if t_col_flux.unit:
218+
t_col_flux_unit = units.validate_unit(t_col_flux.unit.to_string())
219+
else:
220+
t_col_flux_unit = u.dimensionless_unscaled
221+
wavelengths = t_col_wave.value * t_col_wave_unit
222+
fluxes = t_col_flux.value * t_col_flux_unit
212223

213224
finally:
214225
if isinstance(filename, str):

0 commit comments

Comments
 (0)