Skip to content

Commit

Permalink
Remove patchy getattrs now that ScopeSim v0.9.0 is here
Browse files Browse the repository at this point in the history
This was just a temporary workaround anyway, now there's no longer a need for it.
  • Loading branch information
teutoburg committed Nov 16, 2024
1 parent 5844e21 commit c3d4dff
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 65 deletions.
9 changes: 3 additions & 6 deletions scopesim_templates/tests/test_calibration/test_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def test_empty_sky_returns_source_object(self):
sky = calibration.calibration.empty_sky()
assert isinstance(sky, Source)
assert isinstance(sky.spectra[0], SourceSpectrum)
assert (isinstance(getattr(sky.fields[0], "field", sky.fields[0]), Table)
or isinstance(sky.fields[0], Table))
assert isinstance(sky.fields[0].field, Table)
assert sky.fields[0]["ref"][0] == 0


Expand All @@ -23,8 +22,7 @@ def test_flat_field_returns_source_object(self):
flatfield = calibration.calibration.flat_field()
assert isinstance(flatfield, Source)
assert isinstance(flatfield.spectra[0], SourceSpectrum)
assert (isinstance(getattr(flatfield.fields[0], "field", flatfield.fields[0]), ImageHDU)
or isinstance(flatfield.fields[0], ImageHDU))
assert isinstance(flatfield.fields[0].field, ImageHDU)


class TestLamp:
Expand All @@ -40,5 +38,4 @@ def test_lamp_returns_source_object(self):
)
assert isinstance(lamp, Source)
assert isinstance(lamp.spectra[0], SourceSpectrum)
assert (isinstance(getattr(lamp.fields[0], "field", lamp.fields[0]), ImageHDU)
or isinstance(lamp.fields[0], ImageHDU))
assert isinstance(lamp.fields[0].field, ImageHDU)
3 changes: 1 addition & 2 deletions scopesim_templates/tests/test_micado/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ def test_cluster_returns_source_object(self):
sky = cluster()
assert isinstance(sky, Source)
assert isinstance(sky.spectra[0], SourceSpectrum)
assert (isinstance(getattr(sky.fields[0], "field", sky.fields[0]), Table)
or isinstance(sky.fields[0], Table))
assert isinstance(sky.fields[0].field, Table)
3 changes: 1 addition & 2 deletions scopesim_templates/tests/test_micado/test_darkness.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ def test_darkness_returns_source_object(self):
sky = darkness()
assert isinstance(sky, Source)
assert isinstance(sky.spectra[0], SourceSpectrum)
assert (isinstance(getattr(sky.fields[0], "field", sky.fields[0]), Table)
or isinstance(sky.fields[0], Table))
assert isinstance(sky.fields[0].field, Table)
assert sky.fields[0]["ref"][0] == 0
2 changes: 1 addition & 1 deletion scopesim_templates/tests/test_micado/test_flatlamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def test_flatlamp_returns_source_object(self):
lamp = flatlamp()
assert isinstance(lamp, Source)
assert isinstance(lamp.spectra[0], SourceSpectrum)
assert isinstance(getattr(lamp.fields[0], "field", lamp.fields[0]), ImageHDU)
assert isinstance(lamp.fields[0].field, ImageHDU)
4 changes: 1 addition & 3 deletions scopesim_templates/tests/test_micado/test_pinhole_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def test_pinhole_mask_returns_source_object(self):

assert isinstance(ph_mask, Source)
assert isinstance(ph_mask.spectra[0], SourceSpectrum)
assert (isinstance(getattr(ph_mask.fields[0], "field",
ph_mask.fields[0]), Table)
or isinstance(ph_mask.fields[0], Table))
assert isinstance(ph_mask.fields[0].field, Table)

def test_pinhole_with_basic_instrument(self):
dr = np.arange(-25, 26, 5) # [arcsec]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_returns_source_object_with_everything_as_needed(self):
plt.show()

assert isinstance(src.spectra[0], SourceSpectrum)
assert isinstance(getattr(src.fields[0], "field", src.fields[0]), fits.ImageHDU)
assert isinstance(src.fields[0].field, fits.ImageHDU)

def test_returns_flux_scaled_spectrum(self):
src1 = mic_sc.line_list()
Expand Down
28 changes: 7 additions & 21 deletions scopesim_templates/tests/test_stellar/test_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,22 @@ def test_it_works(self, basic_cluster):

@pytest.mark.usefixtures("basic_cluster")
def test_spectra_are_correct_type(self, basic_cluster):
if (hasattr(basic_cluster.fields[0], "field") and
not isinstance(basic_cluster.fields[0], Table)):
assert all(isinstance(spec, Spextrum)
for spec in basic_cluster.spectra.values())
else:
assert all(isinstance(spec, Spextrum)
for spec in basic_cluster.spectra)
assert all(isinstance(spec, Spextrum)
for spec in basic_cluster.spectra.values())

@pytest.mark.usefixtures("basic_cluster")
def test_spectra_waverange(self, basic_cluster):
# TODO: don't know if it makes sense to test like this
if (hasattr(basic_cluster.fields[0], "field") and
not isinstance(basic_cluster.fields[0], Table)):
wvrng_min = [s.waverange.min().to(u.um).value
for s in basic_cluster.spectra.values()]
wvrng_max = [s.waverange.max().to(u.um).value
for s in basic_cluster.spectra.values()]
else:
wvrng_min = [s.waverange.min().to(u.um).value
for s in basic_cluster.spectra]
wvrng_max = [s.waverange.max().to(u.um).value
for s in basic_cluster.spectra]
wvrng_min = [s.waverange.min().to(u.um).value
for s in basic_cluster.spectra.values()]
wvrng_max = [s.waverange.max().to(u.um).value
for s in basic_cluster.spectra.values()]
assert all(wave == approx(0.115) for wave in wvrng_min)
assert all(wave == approx(2.5) for wave in wvrng_max)

@pytest.mark.usefixtures("basic_cluster")
def test_field_is_correct_type(self, basic_cluster):
assert (isinstance(getattr(basic_cluster.fields[0], "field",
basic_cluster.fields[0]), Table)
or isinstance(basic_cluster.fields[0], Table))
assert isinstance(basic_cluster.fields[0].field, Table)
assert len(basic_cluster.fields[0]) > 0

@pytest.mark.usefixtures("basic_cluster")
Expand Down
11 changes: 3 additions & 8 deletions scopesim_templates/tests/test_stellar/test_stars.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@
def source_eq(source_lhs: Source, source_rhs: Source):
"""hacky way to ensure two source"""
eq = len(source_lhs.spectra) == len(source_rhs.spectra)
if isinstance(source_lhs.spectra, list):
for spectrum_lhs, spectrum_rhs in zip(source_lhs.spectra,
source_rhs.spectra):
eq = eq and all(spectrum_lhs.waveset == spectrum_rhs.waveset)
elif isinstance(source_lhs.spectra, dict):
for spectrum_lhs, spectrum_rhs in zip(source_lhs.spectra.values(),
source_rhs.spectra.values()):
eq = eq and all(spectrum_lhs.waveset == spectrum_rhs.waveset)
for spectrum_lhs, spectrum_rhs in zip(source_lhs.spectra.values(),
source_rhs.spectra.values()):
eq = eq and all(spectrum_lhs.waveset == spectrum_rhs.waveset)
return eq


Expand Down
30 changes: 9 additions & 21 deletions scopesim_templates/tests/test_utils/test_validate_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,18 @@ def test_is_fields_a_list(self, src):
def test_fields_list_has_only_imagehdus_or_tables(self, src):
for field in src.fields:
if not isinstance(field, Table):
assert isinstance(getattr(field, "field", field), (Table, ImageHDU))
assert isinstance(field.field, (Table, ImageHDU))

def test_any_tables_have_correct_column_names(self, src):
for field in src.fields:
if isinstance(field, Table):
fld = field
else:
if isinstance(getattr(field, "field", field), Table):
fld = getattr(field, "field", field)
else:
continue

if not isinstance(field, Table):
continue
req_colnames = ["x", "y", "ref", "weight"]
assert all(col in fld.colnames for col in req_colnames)
assert all(col in field.field.colnames for col in req_colnames)

def test_any_imagehdus_have_correct_header_keywords(self, src):
for field in src.fields:
if isinstance(getattr(field, "field", field), ImageHDU):
if isinstance(field.field, ImageHDU):
req_keys = ["SPEC_REF", "NAXIS", "NAXIS1", "NAXIS2",
"CUNIT1", "CUNIT2", "CTYPE1", "CTYPE2",
"CDELT1", "CDELT2", "CRVAL1", "CRVAL2",
Expand All @@ -69,14 +63,8 @@ def test_is_spectra_a_list_or_dict(self, src):
assert isinstance(src.spectra, (list, dict))

def test_spectra_list_has_only_synphot_sourcespectrum_objects(self, src):
if isinstance(src.spectra, list):
for spectrum in src.spectra:
assert isinstance(spectrum, SourceSpectrum)
elif isinstance(src.spectra, dict):
for spectrum in src.spectra.values():
assert isinstance(spectrum, SourceSpectrum)
else:
raise TypeError(src.spectra)
for spectrum in src.spectra.values():
assert isinstance(spectrum, SourceSpectrum)


@pytest.mark.parametrize("src", SOURCE_LIST)
Expand All @@ -85,12 +73,12 @@ class TestConnectionBetweenFieldsAndSpectra:

def test_all_spectra_in_table_ref_column_exist(self, src):
for field in src.fields:
if isinstance(getattr(field, "field", field), Table):
if isinstance(field.field, Table):
for ref in field["ref"]:
assert isinstance(src.spectra[ref], SourceSpectrum)

def test_all_spectra_refereced_in_imagehdu_header_exist(self, src):
for field in src.fields:
if isinstance(getattr(field, "field", field), ImageHDU):
if isinstance(field.field, ImageHDU):
ref = field.header["SPEC_REF"]
assert isinstance(src.spectra[ref], SourceSpectrum)

0 comments on commit c3d4dff

Please sign in to comment.