Skip to content

Commit

Permalink
Updated to fallback to RA, DEC header keywords for unusable WCS (#78)
Browse files Browse the repository at this point in the history
* Updated to fallback to RA, DEC header keywords for unusable WCS coordinate values

* Updated docstring in test_gnirs.ad fixture

* Created test to check bug behavior

* Added test using monkeypatch to simulate the wcs coordinate failures

* Added test using monkeypatch to simulate the wcs coordinate failures

Co-authored-by: Oliver <oly@oberdorf.org>
Co-authored-by: Bruno Quint <b1quint@gmail.com>
  • Loading branch information
3 people committed Sep 24, 2020
1 parent 973da10 commit 7e3c552
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gemini_instruments/gnirs/adclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ def ra(self):
# if it's messed up

wcs_ra = self.wcs_ra()
if wcs_ra is None:
return self.phu.get('RA', None)
try:
tgt_ra = self.target_ra(offset=True, icrs=True)
except: # Return WCS value if we can't get our sanity check
Expand Down Expand Up @@ -469,6 +471,8 @@ def dec(self):
# if it's messed up

wcs_dec = self.wcs_dec()
if wcs_dec is None:
return self.phu.get('DEC', None)
try:
tgt_dec = self.target_dec(offset=True, icrs=True)
except: # Return WCS value if we can't get our sanity check
Expand Down
56 changes: 56 additions & 0 deletions gemini_instruments/gnirs/tests/test_gnirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@

@pytest.fixture(params=test_files)
def ad(request):
"""
Fixture that will download a file from specified as a test parameter,
open it as an AstroData object and return it.
Parameters
----------
request : fixture
Pytest built-in fixture containing information about the parent test.
Returns
-------
AstroData
Raw file downloaded from the archive and cached locally.
"""
filename = request.param
path = astrodata.testing.download_from_archive(filename)
return astrodata.open(path)
Expand Down Expand Up @@ -103,3 +117,45 @@ def test_descriptor_matches_type(ad, descriptor, expected_type):
value = getattr(ad, descriptor)()
assert isinstance(value, expected_type) or value is None, \
"Assertion failed for file: {}".format(ad.filename)


@pytest.mark.dragons_remote_data
@pytest.mark.parametrize("ad", ["N20190101S0102.fits"], indirect=True)
def test_ra_and_dec_always_returns_float(ad, monkeypatch):
"""
Tests that the get the RA/DEC coordinates using descriptors.
Parameters
----------
ad : fixture
Custom fixture that downloads and opens the input file.
"""
if isinstance(ad.wcs_ra(), float) or ad.wcs_ra() is None:
assert isinstance(ad.ra(), float)

if isinstance(ad.wcs_dec(), float) or ad.wcs_dec() is None:
assert isinstance(ad.dec(), float)


@pytest.mark.dragons_remote_data
@pytest.mark.parametrize("ad", ["N20190101S0102.fits"], indirect=True)
def test_ra_and_dec_wcs_fallback(ad, monkeypatch):
"""
Tests that the get the RA/DEC coordinates using descriptors when the WCS coordinate mapping fails
Parameters
----------
ad : fixture
Custom fixture that downloads and opens the input file.
"""
def _fake_wcs_call():
return None

monkeypatch.setattr(ad, 'wcs_ra', _fake_wcs_call)
monkeypatch.setattr(ad, 'wcs_dec', _fake_wcs_call)
assert(ad.ra() == ad.phu.get('RA', None))
assert(ad.dec() == ad.phu.get('DEC', None))


if __name__ == "__main__":
pytest.main()

0 comments on commit 7e3c552

Please sign in to comment.