diff --git a/defdap/file_readers.py b/defdap/file_readers.py index 8b9539e..1c3cecb 100644 --- a/defdap/file_readers.py +++ b/defdap/file_readers.py @@ -984,12 +984,12 @@ def load(self, file_name: pathlib.Path) -> None: """ if not file_name.is_file(): raise FileNotFoundError(f"Cannot open file {file_name}") - + int_type = 'int32' double_type = 'double' data_format = np.dtype([ - ('x', int_type), - ('y', int_type), + ('x', double_type), + ('y', double_type), ('u', double_type), ('v', double_type), ('displacement_mag', double_type), @@ -1026,12 +1026,12 @@ def load(self, file_name: pathlib.Path) -> None: yx_max = yx_array.max(axis=0) shape = yx_max - yx_min assert np.allclose(shape % binning, 0.) + shape = np.rint(shape).astype(int) shape = tuple((shape // binning + 1).tolist()) self.loaded_metadata['shape'] = shape self.checkMetadata() - - index_array = (yx_array - yx_min) // binning + index_array = np.rint((yx_array - yx_min) / binning).astype(int) disp_dense = np.zeros(shape + (2,)) disp_dense[index_array[:, 0], index_array[:, 1]] = ( structured_to_unstructured(data[['u', 'v']])) diff --git a/defdap/hrdic.py b/defdap/hrdic.py index 81b9230..5de3c85 100755 --- a/defdap/hrdic.py +++ b/defdap/hrdic.py @@ -534,12 +534,27 @@ def load_pattern(self): raise FileNotFoundError("First set path to pattern image.") img = imread(path) - exp_shape = tuple(v * binning for v in self.original_shape) - if img.shape != exp_shape: + + bounds = { + 'DaVis': (-1, 0), # Davis rounds up to nearest subwindow + 'PyVale': (0, 1), # PyVale rounds down to nearest subwindow + 'OpenPIV': (0, 1) # OpenPIV rounds down to nearest subwindow + } + lower, upper = bounds[self.format] + + img_shape = np.array(img.shape) + dic_shape = np.array(self.original_shape) + + min_shape = np.array((dic_shape + lower) * binning, dtype=int) + max_shape = np.array((dic_shape + upper) * binning, dtype=int) + + if not np.all((min_shape <= img_shape) & (img_shape <= max_shape)): raise ValueError( f'Incorrect size of pattern image. For binning of {binning} ' - f'expected size {exp_shape[::-1]} but got {img.shape[::-1]}' + f'expected size {min_shape[::-1]} to {max_shape[::-1]} ' + f'but got {img_shape[::-1]}' ) + return img def plot_grain_av_max_shear(self, **kwargs):