Skip to content

Commit

Permalink
replace usages of copy_arrays with memmap (#503)
Browse files Browse the repository at this point in the history
Co-authored-by: Nadia Dencheva <[email protected]>
  • Loading branch information
zacharyburnett and nden authored Jul 30, 2024
1 parent 4a1e104 commit 735c306
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
0.22.0 (unreleased)
-------------------

- replace usages of ``copy_arrays`` with ``memmap`` [#503]

0.21.0 (2024-03-10)
-------------------
Expand Down
19 changes: 14 additions & 5 deletions gwcs/tests/test_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from astropy import wcs as astwcs
from astropy.wcs import wcsapi
from astropy.time import Time
from astropy.utils.introspection import minversion
import asdf

from .. import wcs
Expand Down Expand Up @@ -50,6 +51,14 @@
y = np.linspace(0, 1, ny)
xv, yv = np.meshgrid(x, y)


def asdf_open_memory_mapping_kwarg(memmap: bool) -> dict:
if minversion("asdf", "3.1.0"):
return {"memmap": memmap}
else :
return {"copy_arrays": not memmap}


# Test initializing a WCS


Expand Down Expand Up @@ -648,7 +657,7 @@ def test_to_fits_sip():
xflat = np.ravel(x[1:-1, 1:-1])
yflat = np.ravel(y[1:-1, 1:-1])
fn = os.path.join(data_path, 'miriwcs.asdf')
with asdf.open(fn, lazy_load=False, copy_arrays=True, ignore_missing_extensions=True) as af:
with asdf.open(fn, lazy_load=False, ignore_missing_extensions=True, **asdf_open_memory_mapping_kwarg(memmap=False)) as af:
miriwcs = af.tree['wcs']
bounding_box = ((0, 1024), (0, 1024))
mirisip = miriwcs.to_fits_sip(bounding_box, max_inv_pix_error=0.1, verbose=True)
Expand Down Expand Up @@ -1009,7 +1018,7 @@ def test_to_fits_tab_time_cube(gwcs_cube_with_separable_time):
def test_to_fits_tab_miri_image():
# gWCS:
fn = os.path.join(data_path, 'miriwcs.asdf')
with asdf.open(fn, copy_arrays=True, lazy_load=False, ignore_missing_extensions=True) as af:
with asdf.open(fn, lazy_load=False, ignore_missing_extensions=True, **asdf_open_memory_mapping_kwarg(memmap=False)) as af:
w = af.tree['wcs']

# FITS WCS -TAB:
Expand All @@ -1033,7 +1042,7 @@ def test_to_fits_tab_miri_image():

def test_to_fits_tab_miri_lrs():
fn = os.path.join(data_path, 'miri_lrs_wcs.asdf')
with asdf.open(fn, copy_arrays=True, lazy_load=False, ignore_missing_extensions=True) as af:
with asdf.open(fn, lazy_load=False, ignore_missing_extensions=True, **asdf_open_memory_mapping_kwarg(memmap=False)) as af:
w = af.tree['wcs']

# FITS WCS -TAB:
Expand Down Expand Up @@ -1102,7 +1111,7 @@ def test_in_image():

def test_iter_inv():
fn = os.path.join(data_path, 'nircamwcs.asdf')
with asdf.open(fn, lazy_load=False, copy_arrays=False, ignore_missing_extensions=True) as af:
with asdf.open(fn, lazy_load=False, ignore_missing_extensions=True, **asdf_open_memory_mapping_kwarg(memmap=True)) as af:
w = af.tree['wcs']
# remove analytic/user-supplied inverse:
w.pipeline[0].transform.inverse = None
Expand All @@ -1129,7 +1138,7 @@ def test_iter_inv():
)
assert np.allclose((x, y), (xp, yp))

with asdf.open(fn, lazy_load=False, copy_arrays=False, ignore_missing_extensions=True) as af:
with asdf.open(fn, lazy_load=False, ignore_missing_extensions=True, **asdf_open_memory_mapping_kwarg(memmap=True)) as af:
w = af.tree['wcs']

# test single point
Expand Down
2 changes: 1 addition & 1 deletion gwcs/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def numerical_inverse(self, *args, tolerance=1e-5, maxiter=50, adaptive=True,
>>> import numpy as np
>>> filename = get_pkg_data_filename('data/nircamwcs.asdf', package='gwcs.tests')
>>> with asdf.open(filename, copy_arrays=True, lazy_load=False, ignore_missing_extensions=True) as af:
>>> with asdf.open(filename, memmap=False, lazy_load=False, ignore_missing_extensions=True) as af:
... w = af.tree['wcs']
>>> ra, dec = w([1,2,3], [1,1,1])
Expand Down

0 comments on commit 735c306

Please sign in to comment.