Skip to content

Commit 81626fa

Browse files
rileythairosteen
authored andcommitted
fix: formatting
1 parent 2fd78fb commit 81626fa

File tree

2 files changed

+50
-42
lines changed

2 files changed

+50
-42
lines changed

specutils/io/default_loaders/sdss_v.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Register reader functions for various spectral formats."""
2+
23
import warnings
34
from typing import Optional
45

@@ -89,7 +90,7 @@ def mwm_identify(origin, *args, **kwargs):
8990
return (("V_ASTRA" in hdulist[0].header.keys()) and len(hdulist) > 0
9091
and ("SDSS_ID" in hdulist[0].header.keys())
9192
and (isinstance(hdulist[i], BinTableHDU) for i in range(1, 5))
92-
and all('model_flux' not in hdulist[i].columns.names
93+
and all("model_flux" not in hdulist[i].columns.names
9394
for i in range(1, 5)))
9495

9596

@@ -102,7 +103,7 @@ def astra_identify(origin, *args, **kwargs):
102103
return (("V_ASTRA" in hdulist[0].header.keys()) and len(hdulist) > 0
103104
and ("SDSS_ID" in hdulist[0].header.keys())
104105
and (isinstance(hdulist[i], BinTableHDU) for i in range(1, 5))
105-
and all('model_flux' in hdulist[i].columns.names
106+
and all("model_flux" in hdulist[i].columns.names
106107
for i in range(1, 5)))
107108

108109

@@ -359,7 +360,7 @@ def load_sdss_spec_1D(file_obj, *args, hdu: Optional[int] = None, **kwargs):
359360
"""
360361
if hdu is None:
361362
# TODO: how should we handle this -- multiple things in file, but the user cannot choose.
362-
warnings.warn('HDU not specified. Loading coadd spectrum (HDU1)',
363+
warnings.warn("HDU not specified. Loading coadd spectrum (HDU1)",
363364
AstropyUserWarning)
364365
hdu = 1 # defaulting to coadd
365366
# raise ValueError("HDU not specified! Please specify a HDU to load.")
@@ -648,15 +649,15 @@ def _load_mwmVisit_or_mwmStar_hdu(hdulist: HDUList, hdu: int, **kwargs):
648649

649650
# choose between mwmVisit/Star via KeyError except
650651
try:
651-
meta['mjd'] = hdulist[hdu].data['mjd']
652+
meta["mjd"] = hdulist[hdu].data["mjd"]
652653
meta["datatype"] = "mwmVisit"
653654
except KeyError:
654655
meta["min_mjd"] = str(hdulist[hdu].data["min_mjd"][0])
655656
meta["max_mjd"] = str(hdulist[hdu].data["max_mjd"][0])
656657
meta["datatype"] = "mwmStar"
657658
finally:
658659
meta["name"] = hdulist[hdu].name
659-
meta["sdss_id"] = hdulist[hdu].data['sdss_id']
660+
meta["sdss_id"] = hdulist[hdu].data["sdss_id"]
660661

661662
# drop back a list of Spectrum objects to unpack
662663
return Spectrum(
@@ -703,7 +704,8 @@ def load_astra_1d(file_obj, hdu: Optional[int] = None, **kwargs):
703704
for i in range(1, len(hdulist)):
704705
if hdulist[i].header.get("DATASUM") != "0":
705706
hdu = i
706-
print(f'HDU not specified. Loading spectrum at (HDU{i}).')
707+
warnings.warn(f"HDU not specified. Loading spectrum at (HDU{i})",
708+
AstropyUserWarning,)
707709
break
708710

709711
return _load_astra_hdu(hdulist, hdu, **kwargs)
@@ -793,7 +795,7 @@ def _load_astra_hdu(hdulist: HDUList, hdu: int, **kwargs):
793795
# NOTE:: flux info is not written
794796
flux_unit = Unit("1e-17 erg / (Angstrom cm2 s)") # NOTE: hardcoded unit
795797
flux = Quantity(hdulist[hdu].data["model_flux"] *
796-
hdulist[hdu].data['continuum'],
798+
hdulist[hdu].data["continuum"],
797799
unit=flux_unit)
798800
e_flux = InverseVariance(array=hdulist[hdu].data["ivar"])
799801

@@ -822,15 +824,15 @@ def _load_astra_hdu(hdulist: HDUList, hdu: int, **kwargs):
822824

823825
# choose between mwmVisit/Star via KeyError except
824826
try:
825-
meta['mjd'] = hdulist[hdu].data['mjd']
827+
meta["mjd"] = hdulist[hdu].data["mjd"]
826828
meta["datatype"] = "astraVisit"
827829
except KeyError:
828830
meta["min_mjd"] = str(hdulist[hdu].data["min_mjd"][0])
829831
meta["max_mjd"] = str(hdulist[hdu].data["max_mjd"][0])
830832
meta["datatype"] = "astraStar"
831833
finally:
832834
meta["name"] = hdulist[hdu].name
833-
meta["sdss_id"] = hdulist[hdu].data['sdss_id']
835+
meta["sdss_id"] = hdulist[hdu].data["sdss_id"]
834836

835837
# drop back a list of Spectrum1Ds to unpack
836838
metadicts = _split_mwm_meta_dict(meta)

specutils/io/default_loaders/tests/test_sdss_v.py

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ def generate_apogee_hdu(observatory="APO",
2424

2525
columns = [
2626
fits.Column(name="spectrum_pk_id", array=[159783564], format="K"),
27-
fits.Column(name="release", array=[b"sdss5"]*nvisits, format="5A"),
28-
fits.Column(name="v_astra", array=[b"0.5.0"]*nvisits, format="5A"),
27+
fits.Column(name="release", array=[b"sdss5"] * nvisits, format="5A"),
28+
fits.Column(name="v_astra", array=[b"0.5.0"] * nvisits, format="5A"),
2929
fits.Column(name="healpix", array=[3], format="J"),
30-
fits.Column(name="sdss_id", array=[42]*nvisits, format="K"),
31-
fits.Column(name="apred", array=[b"1.2"]*nvisits, format="3A"),
30+
fits.Column(name="sdss_id", array=[42] * nvisits, format="K"),
31+
fits.Column(name="apred", array=[b"1.2"] * nvisits, format="3A"),
3232
fits.Column(name="obj", array=[b"2M19534321+6705175"], format="18A"),
33-
fits.Column(name="telescope", array=[b"apo25m"]*nvisits, format="6A"),
34-
fits.Column(name="snr", array=[50]*nvisits, format="E"),
33+
fits.Column(name="telescope", array=[b"apo25m"] * nvisits,
34+
format="6A"),
35+
fits.Column(name="snr", array=[50] * nvisits, format="E"),
3536
]
3637
if with_wl:
3738
columns.append(
@@ -47,7 +48,7 @@ def generate_apogee_hdu(observatory="APO",
4748
columns += [
4849
fits.Column(name="mjd", array=[59804], format="J"),
4950
]
50-
flux_col = 'model_flux' if astra else 'flux'
51+
flux_col = "model_flux" if astra else "flux"
5152

5253
columns += [
5354
fits.Column(name=flux_col, array=flux, format="8575E", dim="(8575)"),
@@ -98,14 +99,14 @@ def generate_boss_hdu(observatory="APO",
9899
continuum = np.array([np.zeros_like(wl)] * nvisits)
99100
nmf_rectified_model_flux = np.array([np.zeros_like(wl)] * nvisits)
100101
columns = [
101-
fits.Column(name="spectrum_pk_id", array=[0]*nvisits, format="K"),
102-
fits.Column(name="release", array=["sdss5"]*nvisits, format="5A"),
102+
fits.Column(name="spectrum_pk_id", array=[0] * nvisits, format="K"),
103+
fits.Column(name="release", array=["sdss5"] * nvisits, format="5A"),
103104
fits.Column(name="v_astra", array=["0.5.0"], format="5A"),
104105
fits.Column(name="healpix", array=[34], format="J"),
105106
fits.Column(name="sdss_id", array=[42], format="K"),
106107
fits.Column(name="run2d", array=["6_1_2"], format="6A"),
107-
fits.Column(name="telescope", array=["apo25m"]*nvisits, format="6A"),
108-
fits.Column(name="snr", array=[50]*nvisits, format="E"),
108+
fits.Column(name="telescope", array=["apo25m"] * nvisits, format="6A"),
109+
fits.Column(name="snr", array=[50] * nvisits, format="E"),
109110
]
110111

111112
if with_wl:
@@ -122,7 +123,7 @@ def generate_boss_hdu(observatory="APO",
122123
columns += [
123124
fits.Column(name="mjd", array=[59804], format="J"),
124125
]
125-
flux_col = 'model_flux' if astra else 'flux'
126+
flux_col = "model_flux" if astra else "flux"
126127
columns += [
127128
fits.Column(name=flux_col, array=flux, format="4648E", dim="(4648)"),
128129
fits.Column(name="ivar", array=ivar, format="4648E", dim="(4648)"),
@@ -472,9 +473,9 @@ def test_mwm_1d_nohdu(file_obj, hdu, with_wl, hduflags, nvisits):
472473
if nvisits > 1:
473474
assert data.flux.value.shape[0] == nvisits
474475
if with_wl:
475-
assert data.meta['datatype'].lower() == 'mwmstar'
476-
else:
477-
assert data.meta['datatype'].lower() == 'mwmvisit'
476+
assert data.meta["datatype"].lower() == "mwmstar"
477+
else:
478+
assert data.meta["datatype"].lower() == "mwmvisit"
478479
assert data.spectral_axis.unit == Angstrom
479480
assert data.flux.unit == Unit("1e-17 erg / (s cm2 Angstrom)")
480481
os.remove(tmpfile)
@@ -512,9 +513,9 @@ def test_astra_nohdu(file_obj, hdu, with_wl, hduflags, nvisits):
512513
if nvisits > 1:
513514
assert data.flux.value.shape[0] == nvisits
514515
if with_wl:
515-
assert data.meta['datatype'].lower() == 'astrastar'
516-
else:
517-
assert data.meta['datatype'].lower() == 'astravisit'
516+
assert data.meta["datatype"].lower() == "astrastar"
517+
else:
518+
assert data.meta["datatype"].lower() == "astravisit"
518519
assert data.spectral_axis.unit == Angstrom
519520
assert data.flux.unit == Unit("1e-17 erg / (s cm2 Angstrom)")
520521
os.remove(tmpfile)
@@ -564,9 +565,9 @@ def test_mwm_1d(file_obj, hdu, with_wl, hduflags, nvisits):
564565
if nvisits > 1:
565566
assert data.flux.value.shape[0] == nvisits
566567
if with_wl:
567-
assert data.meta['datatype'].lower() == 'mwmstar'
568-
else:
569-
assert data.meta['datatype'].lower() == 'mwmvisit'
568+
assert data.meta["datatype"].lower() == "mwmstar"
569+
else:
570+
assert data.meta["datatype"].lower() == "mwmvisit"
570571
assert data.spectral_axis.unit == Angstrom
571572
assert data.flux.unit == Unit("1e-17 erg / (s cm2 Angstrom)")
572573
os.remove(tmpfile)
@@ -603,9 +604,9 @@ def test_astra_1d(file_obj, hdu, with_wl, hduflags, nvisits):
603604
assert data.flux.value.shape[0] == nvisits
604605

605606
if with_wl:
606-
assert data.meta['datatype'].lower() == 'astrastar'
607-
else:
608-
assert data.meta['datatype'].lower() == 'astravisit'
607+
assert data.meta["datatype"].lower() == "astrastar"
608+
else:
609+
assert data.meta["datatype"].lower() == "astravisit"
609610

610611
assert data.spectral_axis.unit == Angstrom
611612
assert data.flux.unit == Unit("1e-17 erg / (s cm2 Angstrom)")
@@ -645,9 +646,9 @@ def test_mwm_list(file_obj, with_wl, hduflags):
645646
raise ValueError(
646647
"INSTRMNT tag in test HDU header is not set properly.")
647648
if with_wl:
648-
assert data[i].meta['datatype'].lower() == 'mwmstar'
649+
assert data[i].meta["datatype"].lower() == "mwmstar"
649650
else:
650-
assert data[i].meta['datatype'].lower() == 'mwmvisit'
651+
assert data[i].meta["datatype"].lower() == "mwmvisit"
651652
assert len(data[i].spectral_axis.value) == length
652653
assert data[i].flux.value.shape[-1] == length
653654
if nvisits > 1:
@@ -656,6 +657,7 @@ def test_mwm_list(file_obj, with_wl, hduflags):
656657
assert data[i].flux.unit == Unit("1e-17 erg / (s cm2 Angstrom)")
657658
os.remove(tmpfile)
658659

660+
659661
@pytest.mark.parametrize(
660662
"file_obj, with_wl, hduflags",
661663
[
@@ -673,8 +675,8 @@ def test_astra_list(file_obj, with_wl, hduflags):
673675
"""Test astra SpectrumList loader"""
674676
tmpfile = str(file_obj) + ".fits"
675677
nvisits = 1 if with_wl else 3
676-
mwm_HDUList(hduflags, with_wl, nvisits=nvisits,astra=True).writeto(tmpfile,
677-
overwrite=True)
678+
mwm_HDUList(hduflags, with_wl, nvisits=nvisits,
679+
astra=True).writeto(tmpfile, overwrite=True)
678680

679681
data = SpectrumList.read(tmpfile)
680682
assert isinstance(data, SpectrumList)
@@ -689,9 +691,9 @@ def test_astra_list(file_obj, with_wl, hduflags):
689691
raise ValueError(
690692
"INSTRMNT tag in test HDU header is not set properly.")
691693
if with_wl:
692-
assert data[i].meta['datatype'].lower() == 'astrastar'
693-
else:
694-
assert data[i].meta['datatype'].lower() == 'astravisit'
694+
assert data[i].meta["datatype"].lower() == "astrastar"
695+
else:
696+
assert data[i].meta["datatype"].lower() == "astravisit"
695697
assert len(data[i].spectral_axis.value) == length
696698
assert data[i].flux.value.shape[-1] == length
697699
if nvisits > 1:
@@ -735,6 +737,7 @@ def test_mwm_1d_fail(file_obj, with_wl):
735737
Spectrum.read(tmpfile)
736738
os.remove(tmpfile)
737739

740+
738741
@pytest.mark.parametrize(
739742
"file_obj, with_wl",
740743
[
@@ -745,7 +748,8 @@ def test_mwm_1d_fail(file_obj, with_wl):
745748
def test_astra_1d_fail(file_obj, with_wl):
746749
"""Test astra Spectrum1D loader fail on empty"""
747750
tmpfile = str(file_obj) + ".fits"
748-
mwm_HDUList([0, 0, 0, 0], with_wl,astra=True).writeto(tmpfile, overwrite=True)
751+
mwm_HDUList([0, 0, 0, 0], with_wl, astra=True).writeto(tmpfile,
752+
overwrite=True)
749753

750754
with pytest.raises(ValueError):
751755
Spectrum1D.read(tmpfile)
@@ -768,6 +772,7 @@ def test_mwm_list_fail(file_obj, with_wl):
768772
SpectrumList.read(tmpfile)
769773
os.remove(tmpfile)
770774

775+
771776
@pytest.mark.parametrize(
772777
"file_obj, with_wl",
773778
[
@@ -778,7 +783,8 @@ def test_mwm_list_fail(file_obj, with_wl):
778783
def test_astra_list_fail(file_obj, with_wl):
779784
"""Test astra SpectrumList loader fail on empty"""
780785
tmpfile = str(file_obj) + ".fits"
781-
mwm_HDUList([0, 0, 0, 0], with_wl,astra=True).writeto(tmpfile, overwrite=True)
786+
mwm_HDUList([0, 0, 0, 0], with_wl, astra=True).writeto(tmpfile,
787+
overwrite=True)
782788

783789
with pytest.raises(ValueError):
784790
SpectrumList.read(tmpfile)

0 commit comments

Comments
 (0)