Skip to content

Commit

Permalink
Added support for h5py 3.*
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Nov 30, 2020
1 parent 1218c17 commit bc27d6b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
32 changes: 17 additions & 15 deletions iris/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,13 @@ def diff_apply(self, func, callback=None, processes=1):
placeholder = np.empty(shape=self.resolution, dtype=dset.dtype, order="C")

for index, time_point in enumerate(self.time_points):
dset.read_direct(
placeholder, source_sel=np.s_[:, :, index], dest_sel=np.s_[:, :]
)
# NOTE: Using dset.read_direct was causing problems because
# the destination had shape (N,N), but read_direct wanted a
# destination of shape (N,N,1). This is a new behavior since h5py 3.*
placeholder[:] = dset[:,:,index]
placeholder[:] = func(placeholder)
dset.write_direct(
placeholder, source_sel=np.s_[:, :], dest_sel=np.s_[:, :, index]
placeholder, dest_sel=np.s_[:, :, index]
)
callback(int(100 * index / ntimes))

Expand Down Expand Up @@ -377,7 +378,7 @@ def _diff_apply_parallel(self, func, callback, processes):
self.swmr_mode = True

for index, im in enumerate(transformed):
dset.write_direct(im, source_sel=np.s_[:, :], dest_sel=np.s_[:, :, index])
dset.write_direct(im, dest_sel=np.s_[:, :, index])
dset.flush()
callback(int(100 * index / ntimes))
self.diff_eq.cache_clear()
Expand Down Expand Up @@ -568,9 +569,10 @@ def diff_data(self, timedelay, relative=False, out=None):
time_index = self._get_time_index(timedelay)
if out is None:
out = np.empty(self.resolution, dtype=dataset.dtype)
dataset.read_direct(
out, source_sel=np.s_[:, :, time_index], dest_sel=np.s_[:, :]
)
# NOTE: Using dataset.read_direct was causing problems because
# the destination had shape (N,N), but read_direct wanted a
# destination of shape (N,N,1). This is a new behavior since h5py 3.*
out[:] = dataset[:,:,time_index]

if relative:
out -= self.diff_eq()
Expand Down Expand Up @@ -666,11 +668,11 @@ def time_series_selection(self, selection, relative=False, out=None):
dataset = self.diffraction_group["intensity"]
placeholder = np.empty(shape=(r2 - r1, c2 - c1), dtype=dataset.dtype)
for index, _ in enumerate(self.time_points):
# It is faster to read data directly
# than to go through DiffractionDataset.diff_data
dataset.read_direct(
placeholder, source_sel=np.s_[r1:r2, c1:c2, index], dest_sel=np.s_[:, :]
)
# NOTE: Using dataset.read_direct was causing problems because
# the destination had shape (N,N), but read_direct wanted a
# destination of shape (N,N,1). This is a new behavior since h5py 3.*
placeholder[:] = dataset[r1:r2, c1:c2, index]

out[index] = np.mean(placeholder[reduced_selection])

if relative:
Expand Down Expand Up @@ -929,7 +931,7 @@ def powder_data(self, timedelay, bgr=False, relative=False, out=None):
time_index = self._get_time_index(timedelay)
if out is None:
out = np.empty_like(self.px_radius)
dataset.read_direct(out, source_sel=np.s_[time_index, :], dest_sel=np.s_[:])
dataset.read_direct(out, source_sel=np.s_[time_index, :])

if bgr:
out -= self.powder_baseline(timedelay)
Expand Down Expand Up @@ -971,7 +973,7 @@ def powder_baseline(self, timedelay, out=None):
time_index = self._get_time_index(timedelay)
if out is None:
out = np.empty_like(self.px_radius)
dataset.read_direct(out, source_sel=np.s_[time_index, :], dest_sel=np.s_[:])
dataset.read_direct(out, source_sel=np.s_[time_index, :])

return out

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy >= 1.12
scipy >= 1.0.0
h5py >= 2.10.0, <3
h5py >= 2.10.0
PyQt5
crystals >= 1.1.2, < 2
scikit-ued >= 2.0.3, < 3
Expand Down

0 comments on commit bc27d6b

Please sign in to comment.