Skip to content

Commit

Permalink
replace usages of copy_arrays with memmap for asdf>=3.1.0 (
Browse files Browse the repository at this point in the history
…#422)

* replace usages of ``copy_arrays`` with ``memmap``

* add change log

* modify arguments based on installed version of asdf

* resolve linting check

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* compare strings directly

Co-authored-by: Brett Graham <[email protected]>

* remove importlib import

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Brett Graham <[email protected]>
  • Loading branch information
3 people authored Aug 26, 2024
1 parent 567a2fd commit bf3dc0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/422.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
replace usages of ``copy_arrays`` with ``memmap`` for ``asdf>=3.1.0``
8 changes: 7 additions & 1 deletion dkist/dataset/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
from asdf import ValidationError


def asdf_open_memory_mapping_kwarg(memmap: bool) -> dict:
if asdf.__version__ > "3.1.0":
return {"memmap": memmap}
return {"copy_arrays": not memmap}


@singledispatch
def load_dataset(target):
"""
Expand Down Expand Up @@ -156,7 +162,7 @@ def _load_from_asdf(filepath):
try:
with importlib_resources.as_file(importlib_resources.files("dkist.io") / "level_1_dataset_schema.yaml") as schema_path:
with asdf.open(filepath, custom_schema=schema_path.as_posix(),
lazy_load=False, copy_arrays=True) as ff:
lazy_load=False, **asdf_open_memory_mapping_kwarg(memmap=False)) as ff:
ds = ff.tree["dataset"]
if isinstance(ds, TiledDataset):
for sub in ds.flat:
Expand Down

0 comments on commit bf3dc0a

Please sign in to comment.