From bbc90163aaebe00323fbeed94e8d40d2110b4aad Mon Sep 17 00:00:00 2001 From: Brett Graham Date: Thu, 7 Dec 2023 08:37:04 -0500 Subject: [PATCH] allow control of memmapping for asdf files (#232) --- CHANGES.rst | 3 +++ src/stdatamodels/model_base.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 907b6cdf..251cb20f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -12,6 +12,9 @@ Changes to API - Deprecate ``cast_arrays`` argument to ``from_fits_hdu`` and ``cast_fits_arrays`` argument to ``Datamodel.__init__`` [#214] +- Use ``DataModel.__init__`` ``memmap`` argument when opening ASDF + files [#232] + Other ----- diff --git a/src/stdatamodels/model_base.py b/src/stdatamodels/model_base.py index 4802b2cb..c4096570 100644 --- a/src/stdatamodels/model_base.py +++ b/src/stdatamodels/model_base.py @@ -94,8 +94,7 @@ def __init__(self, init=None, schema=None, memmap=False, will be used. memmap : bool - Turn memmap of FITS file on or off. (default: False). Ignored for - ASDF files. + Turn memmap of FITS/ASDF file on or off. (default: False). pass_invalid_values : bool or None If `True`, values that do not validate the schema @@ -244,6 +243,8 @@ def __init__(self, init=None, schema=None, memmap=False, ) elif file_type == "asdf": + # use memmap argument of "copy_arrays" was not defined + kwargs["copy_arrays"] = kwargs.get("copy_arrays", not memmap) asdffile = self.open_asdf(init=init, **kwargs) else: @@ -575,7 +576,8 @@ def open_asdf(init=None, if isinstance(init, str): asdffile = asdf.open(init, ignore_version_mismatch=ignore_version_mismatch, - ignore_unrecognized_tag=ignore_unrecognized_tag) + ignore_unrecognized_tag=ignore_unrecognized_tag, + **kwargs) else: asdffile = AsdfFile(init,