Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions hexrd/imageseries/load/framecache.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def _load_cache_fch5(self):
unwrap_h5_to_dict(file["metadata"], self._meta)

def _load_cache_npz(self):
arrs = np.load(self._fname)
with np.load(self._fname) as arrs:
self._load_cache_npz_arrays(arrs)

def _load_cache_npz_arrays(self, arrs: np.lib.npyio.NpzFile):
# HACK: while the loaded npz file has a getitem method
# that mimicks a dict, it doesn't have a "pop" method.
# must make an empty dict to pop after assignment of
Expand Down Expand Up @@ -266,19 +269,19 @@ def _load_framecache_npz(
) -> list[csr_array]:

framelist = []
arrs = np.load(filepath)
for i in range(num_frames):
row = arrs[f"{i}_row"]
col = arrs[f"{i}_col"]
data = arrs[f"{i}_data"]
frame = csr_array((data, (row, col)),
shape=shape,
dtype=dtype)

# Make the data unwriteable, so we can be sure it won't be modified
frame.data.flags.writeable = False

framelist.append(frame)
with np.load(filepath) as arrs:
for i in range(num_frames):
row = arrs[f"{i}_row"]
col = arrs[f"{i}_col"]
data = arrs[f"{i}_data"]
frame = csr_array((data, (row, col)),
shape=shape,
dtype=dtype)

# Make the data unwriteable, so we can be sure it won't be modified
frame.data.flags.writeable = False

framelist.append(frame)

return framelist

Expand Down
Loading