From 523ac5d135f8dc99f33fca2efa761db39720cbd3 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 24 Feb 2025 14:50:40 -0500 Subject: [PATCH 1/6] remove can_broadcast --- src/stdatamodels/jwst/datamodels/util.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/stdatamodels/jwst/datamodels/util.py b/src/stdatamodels/jwst/datamodels/util.py index 215ca87d..4f6b4f6f 100644 --- a/src/stdatamodels/jwst/datamodels/util.py +++ b/src/stdatamodels/jwst/datamodels/util.py @@ -16,7 +16,7 @@ from stdatamodels.model_base import _FileReference -__all__ = ["open", "NoTypeWarning", "can_broadcast", "to_camelcase", "is_association"] +__all__ = ["open", "NoTypeWarning", "to_camelcase", "is_association"] log = logging.getLogger(__name__) @@ -368,20 +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("_-")) From 1b3d324611656b5670ac5c5ba26595e337faa458 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 24 Feb 2025 14:51:14 -0500 Subject: [PATCH 2/6] remove to_camelcase --- src/stdatamodels/jwst/datamodels/util.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/stdatamodels/jwst/datamodels/util.py b/src/stdatamodels/jwst/datamodels/util.py index 4f6b4f6f..9e1f8716 100644 --- a/src/stdatamodels/jwst/datamodels/util.py +++ b/src/stdatamodels/jwst/datamodels/util.py @@ -16,7 +16,7 @@ from stdatamodels.model_base import _FileReference -__all__ = ["open", "NoTypeWarning", "to_camelcase", "is_association"] +__all__ = ["open", "NoTypeWarning", "is_association"] log = logging.getLogger(__name__) @@ -368,10 +368,6 @@ def _class_from_shape(hdulist, shape): return new_class -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 From 8216eb390a62b8d6a949ac08eee0609c56ef8130 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 24 Feb 2025 14:52:27 -0500 Subject: [PATCH 3/6] remove ensure_ascii --- src/stdatamodels/fits_support.py | 17 +++-------------- tests/test_fits.py | 5 ----- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/stdatamodels/fits_support.py b/src/stdatamodels/fits_support.py index 811b31ce..4b7383c4 100644 --- a/src/stdatamodels/fits_support.py +++ b/src/stdatamodels/fits_support.py @@ -245,7 +245,7 @@ def _fits_comment_section_handler(fits_context, validator, properties, instance, 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: @@ -274,12 +274,11 @@ def _fits_element_writer(fits_context, validator, fits_keyword, instance, schema 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 elif fits_keyword in hdu.header: hdu.header[fits_keyword] = (instance, comment) else: @@ -919,13 +918,3 @@ def get_short_doc(schema): 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 diff --git a/tests/test_fits.py b/tests/test_fits.py index e53fc216..055bc630 100644 --- a/tests/test_fits.py +++ b/tests/test_fits.py @@ -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", [ From e076db598de9ae3e43371622754d76024e5484a1 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 24 Feb 2025 14:54:13 -0500 Subject: [PATCH 4/6] remove Datamodel.read Datamodel.write --- src/stdatamodels/model_base.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/stdatamodels/model_base.py b/src/stdatamodels/model_base.py index 1c0d918a..23b1c21c 100644 --- a/src/stdatamodels/model_base.py +++ b/src/stdatamodels/model_base.py @@ -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 From f021544b1d20de8b02659a9d209fa699000592c1 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 24 Feb 2025 14:55:48 -0500 Subject: [PATCH 5/6] remove fits_hdu_name --- src/stdatamodels/fits_support.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/stdatamodels/fits_support.py b/src/stdatamodels/fits_support.py index 4b7383c4..4c553f33 100644 --- a/src/stdatamodels/fits_support.py +++ b/src/stdatamodels/fits_support.py @@ -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" @@ -112,22 +112,10 @@ def _get_indexed_keyword(keyword, i): 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 @@ -470,7 +458,6 @@ def normalize_array(node): 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"]) From dd02aab1c4e004aa329c88ee6d98fd54dbbd669c Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 24 Feb 2025 14:56:45 -0500 Subject: [PATCH 6/6] remove bytes2human --- src/stdatamodels/jwst/library/basic_utils.py | 36 -------------------- 1 file changed, 36 deletions(-) delete mode 100644 src/stdatamodels/jwst/library/basic_utils.py diff --git a/src/stdatamodels/jwst/library/basic_utils.py b/src/stdatamodels/jwst/library/basic_utils.py deleted file mode 100644 index 3ad4545a..00000000 --- a/src/stdatamodels/jwst/library/basic_utils.py +++ /dev/null @@ -1,36 +0,0 @@ -"""General utility objects""" - - -def bytes2human(n): - """Convert bytes to human-readable format - - Taken from the `psutil` library which references - http://code.activestate.com/recipes/578019 - - Parameters - ---------- - n : int - Number to convert - - Returns - ------- - readable : str - A string with units attached. - - Examples - -------- - >>> bytes2human(10000) - '9.8K' - - >>> bytes2human(100001221) - '95.4M' - """ - symbols = ("K", "M", "G", "T", "P", "E", "Z", "Y") - prefix = {} - for i, s in enumerate(symbols): - prefix[s] = 1 << (i + 1) * 10 - for s in reversed(symbols): - if n >= prefix[s]: - value = float(n) / prefix[s] - return f"{value:.1f}{s}" - return f"{n}B"