Source code for piv.grid_spec

[docs]class GridSpec(object): """ Class for grid specifications. This class saves and calculates the grid specifications. """ def __init__(self, frame_shape, frame_strides, window_size, search_size, distance): """ Initialization of the shapes and strides. Setting the values according to parameters. If the window_size and search_size are not the same a padding for the smaller one is added. :param frame_shape: shape of the initial image :param frame_strides: strides of the initial image :param window_size: size of the interrogation window :param search_size: size of the search window :param distance: distance between interrogation window beginnings """ self.frame_shape = frame_shape self.frame_strides = frame_strides self.window_size = window_size self.search_size = search_size self.distance = distance self.pad = max([0, (search_size - window_size)/2])
[docs] def equal_to(self, grid_spec): """ Comparison operator for class. Two GridSpecs are equal if the window_size, the search_size and distance are equal. :param GridSpec grid_spec: grid spec to compare with :returns: True or False """ cond1 = grid_spec.window_size == self.window_size cond2 = grid_spec.search_size == self.search_size cond3 = grid_spec.distance == self.distance if cond1 & cond2 & cond3: return True else: return False
[docs] def get_grid_shape(self): """ Getter function for the shape of the grid. The returned value is the shape of the grid calculated from the arrangement of the interrogation windows. :returns: grid shape in x and y direction as tuple """ lx, ly = self.frame_shape return ((lx - self.window_size)//self.distance+1, (ly - self.window_size)//self.distance+1)
[docs] def get_interogation_grid_shape(self): """ Getter function for the shape of the interrogation window. :returns: shape of the interrogation window """ shape = self.get_grid_shape() return shape + 2*(self.window_size,)
[docs] def get_search_grid_shape(self): """ Getter function for the shape of the search window. :returns: shape of the search window """ shape = self.get_grid_shape() return shape + 2*(self.search_size,)
[docs] def get_interogation_grid_strides(self): """ Getter function for the strides of the interrogation window. :returns: strides of the interrogation window """ sx, sy = self.frame_strides return (sx*self.distance, sy*self.distance, sx, sy)
[docs] def get_search_grid_strides(self): """ Getter function for the strides of the search window. :returns: strides of the search window """ sx, sy = self.frame_strides sx = sx + 2*self.pad*sy return (sx*self.distance, sy*self.distance, sx, sy)