Skip to content

Commit

Permalink
Make is_builtin_fits_keyword a public function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Slavich committed Dec 2, 2020
1 parent 0d8cade commit b8d34e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/stdatamodels/fits_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
log.addHandler(logging.NullHandler())


__all__ = ['to_fits', 'from_fits', 'fits_hdu_name', 'get_hdu']
__all__ = ['to_fits', 'from_fits', 'fits_hdu_name', 'get_hdu', 'is_builtin_fits_keyword']


_ASDF_GE_2_6 = parse_version(asdf.__version__) >= parse_version('2.6')
Expand All @@ -51,7 +51,7 @@
'|'.join('(^{0}$)'.format(x) for x in _builtin_regexes))


def _is_builtin_fits_keyword(key):
def is_builtin_fits_keyword(key):
"""
Returns `True` if the given `key` is a built-in FITS keyword, i.e.
a keyword that is managed by ``astropy.io.fits`` and we wouldn't
Expand Down Expand Up @@ -182,7 +182,7 @@ def _get_or_make_hdu(hdulist, hdu_name, index=None, hdu_type=None, value=None):
new_hdu = _make_hdu(hdulist, hdu_name, index=index,
hdu_type=hdu_type, value=value)
for key, val in hdu.header.items():
if not _is_builtin_fits_keyword(key):
if not is_builtin_fits_keyword(key):
new_hdu.header[key] = val
hdulist.remove(hdu)
hdu = new_hdu
Expand Down Expand Up @@ -364,7 +364,7 @@ def _save_extra_fits(hdulist, tree):
if 'header' in parts:
hdu = _get_or_make_hdu(hdulist, hdu_name)
for key, val, comment in parts['header']:
if _is_builtin_fits_keyword(key):
if is_builtin_fits_keyword(key):
continue
hdu.header.append((key, val, comment), end=True)

Expand Down Expand Up @@ -518,7 +518,7 @@ def _load_extra_fits(hdulist, known_keywords, known_datas, tree):

cards = []
for key, val, comment in hdu.header.cards:
if not (_is_builtin_fits_keyword(key) or
if not (is_builtin_fits_keyword(key) or
key in known):
cards.append([key, val, comment])

Expand Down
9 changes: 9 additions & 0 deletions tests/test_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,12 @@ def test_data_array(tmp_path):
assert x == set(
[('FOO', 2), ('FOO', 1), ('ASDF', None), ('DQ', 2),
(None, None)])


@pytest.mark.parametrize("keyword,result", [
("BZERO", True),
("TFORM53", True),
("INSTRUME", False),
])
def test_is_builtin_fits_keyword(keyword, result):
assert fits_support.is_builtin_fits_keyword(keyword) is result

0 comments on commit b8d34e4

Please sign in to comment.