pyfor.rasterizer module

class pyfor.rasterizer.Grid(cloud, cell_size)

Bases: object

The Grid object is a representation of a point cloud that has been sorted into X and Y dimensional bins. From the Grid object we can derive other useful products, most importantly, Raster objects.

__init__(cloud, cell_size)

Upon initialization, the parent cloud object’s data.points attribute is sorted into bins in place. The columns ‘bins_x’ and ‘bins_y’ are appended. Other useful information, such as the resolution, number of rows and columns are also stored.

Parameters
  • cloud – The “parent” cloud object.

  • cell_size – The size of the cell for sorting in the units of the input cloud object.

property empty_cells

Retrieves the cells with no returns in self.data

return: An N x 2 numpy array where each row cooresponds to the [y x] coordinate of the empty cell.

interpolate(func, dim, interp_method='nearest')

Interpolates missing cells in the grid. This function uses scipy.griddata as a backend. Please see documentation for that function for more details.

Parameters
  • func – The function (or function string) to calculate an array on the gridded data.

  • dim – The dimension (i.e. column name of self.cells) to cast func onto.

  • interp_method – The interpolation method call for scipy.griddata, one of any: “nearest”, “cubic”, “linear”

Returns

An interpolated array.

metrics(func_dict, as_raster=False)

Calculates summary statistics for each grid cell in the Grid.

Parameters

func_dict – A dictionary containing keys corresponding to the columns of self.data and values that correspond to the functions to be called on those columns.

Returns

A pandas dataframe with the aggregated metrics.

raster(func, dim, **kwargs)

Generates an m x n matrix with values as calculated for each cell in func. This is a raw array without missing cells interpolated. See self.interpolate for interpolation methods.

Parameters
  • func – A function string, i.e. “max” or a function itself, i.e. np.max(). This function must be able to take a 1D array of the given dimension as an input and produce a single value as an output. This single value will become the value of each cell in the array.

  • dim – A dimension to calculate on.

Returns

A 2D numpy array where the value of each cell is the result of the passed function.

standard_metrics(heightbreak=0)
class pyfor.rasterizer.ImportedGrid(path, cloud)

Bases: pyfor.rasterizer.Grid

ImportedGrid is used to normalize a parent cloud object with an arbitrary raster file.

__init__(path, cloud)

Upon initialization, the parent cloud object’s data.points attribute is sorted into bins in place. The columns ‘bins_x’ and ‘bins_y’ are appended. Other useful information, such as the resolution, number of rows and columns are also stored.

Parameters
  • cloud – The “parent” cloud object.

  • cell_size – The size of the cell for sorting in the units of the input cloud object.

class pyfor.rasterizer.Raster(array, grid)

Bases: object

__init__(array, grid)

Initialize self. See help(type(self)) for accurate signature.

force_extent(bbox)

Sets self._affine and self.array to a forced bounding box. Useful for trimming edges off of rasters when processing buffered tiles. This operation is done in place.

Parameters

bbox – Coordinates of output raster as a tuple (min_x, max_x, min_y, max_y)

classmethod from_rasterio()
pit_filter(kernel_size)

Filters pits in the raster. Intended for use with canopy height models (i.e. grid(0.5).interpolate(“max”, “z”). This function modifies the raster array in place.

Parameters

kernel_size – The size of the kernel window to pass over the array. For example 3 -> 3x3 kernel window.

plot(cmap='viridis', block=False, return_plot=False)

Default plotting method for the Raster object.

write(path)

Writes the raster to a geotiff. Requires the Cloud.crs attribute to be filled by a projection string (ideally wkt or proj4).

Parameters

path – The path to write to.