Skip to content

Commit 4f8d269

Browse files
committed
Speed test
1 parent 9349c9a commit 4f8d269

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

arrakis/cutout.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ def cutout(
118118
logger.info(f"Reading {cutout_args.image}")
119119
with warnings.catch_warnings():
120120
warnings.simplefilter("ignore", AstropyWarning)
121-
cube = SpectralCube.read(cutout_args.image)
121+
cube = SpectralCube.read(
122+
cutout_args.image, memmap=True, mode="denywrite"
123+
)
122124
padder = cube.header["BMAJ"] * u.deg * pad
123125

124126
xlo = Longitude(cutout_args.ra_low * u.deg) - Longitude(padder)
@@ -138,6 +140,7 @@ def cutout(
138140
# Use subcube for header transformation
139141
cutout_cube = cube[:, yp_lo_idx:yp_hi_idx, xp_lo_idx:xp_hi_idx]
140142
new_header = cutout_cube.header
143+
del cube, cutout_cube
141144
with warnings.catch_warnings():
142145
warnings.simplefilter("ignore", AstropyWarning)
143146
with fits.open(
@@ -146,12 +149,15 @@ def cutout(
146149
data = hdulist[0].data
147150
old_header = hdulist[0].header
148151

149-
sub_data = data[
150-
:,
151-
:,
152-
yp_lo_idx:yp_hi_idx,
153-
xp_lo_idx:xp_hi_idx, # freq, Stokes, y, x
154-
]
152+
# Use numpy to force into memory
153+
sub_data = np.array(
154+
data[
155+
:,
156+
:,
157+
yp_lo_idx:yp_hi_idx,
158+
xp_lo_idx:xp_hi_idx, # freq, Stokes, y, x
159+
]
160+
)
155161
fixed_header = fix_header(new_header, old_header)
156162
# Add source name to header for CASDA
157163
fixed_header["OBJECT"] = cutout_args.source_id

0 commit comments

Comments
 (0)