Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Astropy Header not behaving dict-like. #53

Merged
merged 5 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions python/astro_metadata_translator/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from astropy.time import Time
import astropy.utils.exceptions
import warnings
from astropy.io.fits import Header

from astro_metadata_translator import ObservationInfo

Expand Down Expand Up @@ -149,8 +150,26 @@ def assertObservationInfoFromYaml(self, file, dir=None, check_wcs=True, # noqa:
inconsistent.
"""
header = read_test_file(file, dir=dir)
self.assertObservationInfo(header, filename=file, check_wcs=check_wcs,
wcs_params=wcs_params, **kwargs)

try:
DinoBektesevic marked this conversation as resolved.
Show resolved Hide resolved
self.assertObservationInfo(header, filename=file, check_wcs=check_wcs,
wcs_params=wcs_params, **kwargs)
except AssertionError as e:
raise AssertionError("ObservationInfo derived from an dict-like "
"type is inconsistent.") from e

astropy_header = Header()
DinoBektesevic marked this conversation as resolved.
Show resolved Hide resolved
for key, val in header.items():
values = val if isinstance(val, list) else [val]
for v in values:
astropy_header[key] = v
DinoBektesevic marked this conversation as resolved.
Show resolved Hide resolved

try:
self.assertObservationInfo(astropy_header, filename=file, check_wcs=check_wcs,
wcs_params=wcs_params, **kwargs)
except AssertionError as e:
raise AssertionError("ObservationInfo derived from an Astropy "
"Header is inconsistent.") from e

def assertObservationInfo(self, header, filename=None, check_wcs=True, # noqa: N802
wcs_params=None, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion python/astro_metadata_translator/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def is_keyword_defined(header, keyword):
is_defined : `bool`
`True` if the header is present and not-`None`. `False` otherwise.
"""
if keyword not in header:
if keyword is None or keyword not in header:
return False

if header[keyword] is None:
Expand Down