Skip to content

Commit a664f35

Browse files
author
Peter Ercius ncem-gauss jupyter
committed
Allow reader to read non-square scanning regions.
1 parent ab7edd1 commit a664f35

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

ncempy/io/dectris.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class fileDECTRIS:
1010
raw_shape : list
1111
The shape of the raw data. This is three-dimensional: [num_frames, frameY, frameX].
1212
data_shape : list
13-
The four-dimensional shape of the dataset. It is always assumed that the
14-
num_frames**0.5 = num_frames (i.e. region of interest is square).
13+
The four-dimensional shape of the dataset. By default, the
14+
scanned region is square.
1515
file_hdl : h5py.File
1616
The h5py file handle which provides direct access to the underlying hdf5 file structure.
1717
data_type : numpy.dtype
@@ -94,14 +94,16 @@ def __exit__(self, exception_type, exception_value, traceback):
9494
self.__del__()
9595
return None
9696

97-
def get_dataset(self, remove_bad_pixels=False):
97+
def get_dataset(self, remove_bad_pixels=False, assume_shape=None:
9898
""" Read the data from the HDF5 files
9999
100100
Parameters
101101
----------
102102
remove_bad_pixels : bool, default False
103103
If True, remove_bad_pixels function is called after the data is loaded.
104-
104+
assume_shape : tuple, optional
105+
If this is set, then this tuple is used as the scanning shape overriding
106+
the assumption of a square real space scanning grid
105107
"""
106108
# Pre allocate space
107109
data = np.zeros(self.raw_shape, dtype=self.data_dtype)
@@ -111,11 +113,15 @@ def get_dataset(self, remove_bad_pixels=False):
111113
data[ii:ii+v.shape[0]] = v[:]
112114
ii += v.shape[0]
113115

114-
# Reshape assuming square
115-
shape_square = int((data.shape[0])**0.5)
116-
assert data.shape[0] == shape_square**2
117-
self.data_shape = (shape_square, shape_square,
118-
data.shape[1], data.shape[2])
116+
if assume_shape:
117+
self.data.shape = (assume_shape[0], assume_shape[1],
118+
data.shape[1], data.shape[2])
119+
else:
120+
# Reshape assuming square
121+
shape_square = int((data.shape[0])**0.5)
122+
assert data.shape[0] == shape_square**2
123+
self.data_shape = (shape_square, shape_square,
124+
data.shape[1], data.shape[2])
119125
data = data.reshape(data_shape)
120126
if remove_bad_pixels:
121127
self.remove_bad_pixels()

0 commit comments

Comments
 (0)