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

Unused functions #420

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 4 additions & 28 deletions src/stdatamodels/fits_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
log.addHandler(logging.NullHandler())


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


_ASDF_EXTENSION_NAME = "ASDF"
Expand Down Expand Up @@ -112,22 +112,10 @@
return keyword


def fits_hdu_name(name):
"""
Returns a FITS hdu name in the correct form for the current
version of Python.
"""
if isinstance(name, bytes):
return name.decode("ascii")
return name


def _get_hdu_name(schema):
hdu_name = schema.get("fits_hdu")
if hdu_name in (None, "PRIMARY"):
hdu_name = 0
else:
hdu_name = fits_hdu_name(hdu_name)
return hdu_name


Expand Down Expand Up @@ -245,7 +233,7 @@
title = schema.get("title")
if title is not None:
current_comment_stack = fits_context.comment_stack
current_comment_stack.append(ensure_ascii(title))
current_comment_stack.append(title)

for prop, subschema in properties.items():
if prop in instance:
Expand Down Expand Up @@ -274,12 +262,11 @@
hdu.header.append((" ", ""), end=True)
fits_context.comment_stack = []

comment = ensure_ascii(get_short_doc(schema))
instance = ensure_ascii(instance)
comment = get_short_doc(schema)

if fits_keyword in ("COMMENT", "HISTORY"):
for item in instance:
hdu.header[fits_keyword] = ensure_ascii(item)
hdu.header[fits_keyword] = item

Check warning on line 269 in src/stdatamodels/fits_support.py

View check run for this annotation

Codecov / codecov/patch

src/stdatamodels/fits_support.py#L269

Added line #L269 was not covered by tests
elif fits_keyword in hdu.header:
hdu.header[fits_keyword] = (instance, comment)
else:
Expand Down Expand Up @@ -471,7 +458,6 @@
def _save_extra_fits(hdulist, tree):
# Handle _extra_fits
for hdu_name, parts in tree.get("extra_fits", {}).items():
hdu_name = fits_hdu_name(hdu_name)
if "data" in parts:
hdu_type = _get_hdu_type(hdu_name, value=parts["data"])
hdu = _get_or_make_hdu(hdulist, hdu_name, hdu_type=hdu_type, value=parts["data"])
Expand Down Expand Up @@ -919,13 +905,3 @@
if title is not None:
description = title + "\n\n" + description
return description.partition("\n")[0]


def ensure_ascii(s):
# TODO: This function seems to only ever receive
# string input. Also it's not checking that the
# characters in the string fall within the valid
# range for FITS headers.
if isinstance(s, bytes):
s = s.decode("ascii")
return s
20 changes: 1 addition & 19 deletions src/stdatamodels/jwst/datamodels/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from stdatamodels.model_base import _FileReference


__all__ = ["open", "NoTypeWarning", "can_broadcast", "to_camelcase", "is_association"]
__all__ = ["open", "NoTypeWarning", "is_association"]


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -368,24 +368,6 @@ def _class_from_shape(hdulist, shape):
return new_class


def can_broadcast(a, b):
"""
Given two shapes, returns True if they are broadcastable.
"""
for i in range(1, min(len(a), len(b)) + 1):
adim = a[-i]
bdim = b[-i]

if not (adim == 1 or bdim == 1 or adim == bdim):
return False

return True


def to_camelcase(token):
return "".join(x.capitalize() for x in token.split("_-"))


def is_association(asn_data):
"""
Test if an object is an association by checking for required fields
Expand Down
36 changes: 0 additions & 36 deletions src/stdatamodels/jwst/library/basic_utils.py

This file was deleted.

10 changes: 0 additions & 10 deletions src/stdatamodels/model_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,16 +1105,6 @@ def set_fits_wcs(self, wcs, hdu_name="SCI"):

self._instance = properties.merge_tree(self._instance, ff.tree)

# --------------------------------------------------------
# These two method aliases are here for astropy.registry
# compatibility and should not be called directly
# --------------------------------------------------------

read = __init__

def write(self, path, *args, **kwargs):
self.save(path, *args, **kwargs)

def getarray_noinit(self, attribute):
"""Retrieve array but without initialization

Expand Down
5 changes: 0 additions & 5 deletions tests/test_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,6 @@ def test_get_short_doc():
)


def test_ensure_ascii():
for inp in [b"ABCDEFG", "ABCDEFG"]:
assert fits_support.ensure_ascii(inp) == "ABCDEFG"


@pytest.mark.parametrize(
"which_file, skip_fits_update, expected_exp_type",
[
Expand Down
Loading