Skip to content

Commit

Permalink
Fixed codestyle errors in calibration_data and its tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
hpparvi committed Nov 29, 2024
1 parent 6731847 commit ffde805
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
18 changes: 13 additions & 5 deletions specreduce/calibration_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,12 @@ def load_pypeit_calibration_lines(
data_path = f"arc_lines/lists/{lamp}_lines.dat"
try:
with get_pkg_data_fileobj(data_path, cache=cache) as data_file:
linelists.append(Table.read(data_file.read(), format='ascii.fixed_width', comment='#'))
linelists.append(Table.read(data_file.read(),
format='ascii.fixed_width',
comment='#'))
except URLError as e:
warnings.warn(f"Downloading of {data_path} failed: {e}", AstropyUserWarning)
warnings.warn(f"Downloading of {data_path} failed: {e}",

Check warning on line 170 in specreduce/calibration_data.py

View check run for this annotation

Codecov / codecov/patch

specreduce/calibration_data.py#L169-L170

Added lines #L169 - L170 were not covered by tests
AstropyUserWarning)
else:
warnings.warn(
f"{lamp} not in the list of supported calibration "
Expand Down Expand Up @@ -220,7 +223,8 @@ def load_MAST_calspec(
if filename.exists() and filename.is_file():
file_path = filename
else:
with conf.set_temp("dataurl", "https://archive.stsci.edu/hlsps/reference-atlases/cdbs/calspec/"):
with conf.set_temp("dataurl",
"https://archive.stsci.edu/hlsps/reference-atlases/cdbs/calspec/"):
try:
file_path = get_pkg_data_filename(str(filename), show_progress=show_progress)
except URLError as e:
Expand Down Expand Up @@ -281,7 +285,9 @@ def load_onedstds(
try:
data_path = str(Path("onedstds") / Path(dataset) / Path(specfile))
with get_pkg_data_fileobj(data_path, cache=cache) as data_file:
t = Table.read(data_file.read(), format="ascii", names=['wavelength', 'ABmag', 'binsize'])
t = Table.read(data_file.read(),
format="ascii",
names=['wavelength', 'ABmag', 'binsize'])
except URLError as e:
msg = f"Can't load {specfile} from {dataset}: {e}."
warnings.warn(msg, AstropyUserWarning)
Expand Down Expand Up @@ -375,7 +381,9 @@ def __init__(
with conf.set_temp("dataurl", SPECREDUCE_DATA_URL):
data_path = str(Path("extinction") / Path(f"{model}extinct.dat"))
with get_pkg_data_fileobj(data_path, cache=cache) as data_file:
t = Table.read(data_file.read(), format="ascii", names=['wavelength', 'extinction'])
t = Table.read(data_file.read(),
format="ascii",
names=['wavelength', 'extinction'])

# the specreduce_data models all provide wavelengths in angstroms
spectral_axis = t['wavelength'].data * u.angstrom
Expand Down
3 changes: 1 addition & 2 deletions specreduce/tests/test_extinction.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_unsupported_model():
Test loading of a nonexistent model
"""
with pytest.raises(ValueError, match='Requested extinction model,'):
ext = AtmosphericExtinction(model='bad_model')
AtmosphericExtinction(model='bad_model')


@pytest.mark.remote_data
Expand All @@ -75,7 +75,6 @@ def test_missing_extinction_unit():
extinction = 1. / wave
with pytest.warns(AstropyUserWarning):
ext = AtmosphericExtinction(extinction=extinction, spectral_axis=wave * u.um)

assert len(ext.extinction_mag) > 0
assert len(ext.transmission) > 0

Expand Down
2 changes: 1 addition & 1 deletion specreduce/tests/test_linelists.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_pypeit_nonexisting_lamp():
Test to make sure a warning is raised if the lamp list includes a bad lamp name.
"""
with pytest.warns(UserWarning, match='NeJ not in the list'):
line_tab = load_pypeit_calibration_lines(["HeI", "NeJ"], cache=True, show_progress=False)
load_pypeit_calibration_lines(["HeI", "NeJ"], cache=True, show_progress=False)


@pytest.mark.remote_data
Expand Down
4 changes: 1 addition & 3 deletions specreduce/tests/test_specphot_stds.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from urllib.error import URLError

import pytest
from astropy.utils.exceptions import AstropyUserWarning

Expand All @@ -16,7 +14,7 @@ def test_load_MAST():
@pytest.mark.remote_data
def test_load_MAST_bad_filename():
with pytest.warns(AstropyUserWarning, match="Downloading of"):
sp = load_MAST_calspec("j191b2b_005.fits", show_progress=False)
load_MAST_calspec("j191b2b_005.fits", show_progress=False)


@pytest.mark.remote_data
Expand Down

0 comments on commit ffde805

Please sign in to comment.