ecoscope.io.raster#
Module Contents#
- ecoscope.io.raster.logger#
- ecoscope.io.raster.RioPixelType#
- class ecoscope.io.raster.RasterExtent(x_min=33.0, x_max=37.0, y_min=2.0, y_max=-2.0)[source]#
- Parameters:
x_min (float)
x_max (float)
y_min (float)
y_max (float)
- x_min = 33.0#
- x_max = 37.0#
- y_min = 2.0#
- y_max = -2.0#
- class ecoscope.io.raster.RasterProfile(pixel_size=1000.0, pixel_dtype=rio.float64, crs='EPSG:8857', nodata_value=0.0, band_count=1, raster_extent=None)[source]#
Bases:
collections.UserDictA class for holding raster properties At present this class is only valid for non-rotated rasters with a north-up orientation and square sized pixels defined by the E-W pixel size
- Parameters:
pixel_size (float)
pixel_dtype (str | RioPixelType)
crs (str | pyproj.CRS)
nodata_value (float)
band_count (int)
raster_extent (RasterExtent | None)
- class ecoscope.io.raster.RasterData[source]#
- data: numpy.ndarray#
- crs: str#
- transform: rasterio.Affine#
- class ecoscope.io.raster.RasterPy[source]#
- classmethod write(ndarray, fp, columns, rows, band_count, driver='GTiff', dtype=rio.float64, crs=None, transform=None, nodata=None, sharing=False, indexes=1, **kwargs)[source]#
- Parameters:
ndarray (numpy.ndarray)
fp (str | os.PathLike | rasterio.MemoryFile)
columns (int)
rows (int)
band_count (int)
driver (str)
dtype (str | RioPixelType)
crs (str | None)
transform (affine.Affine | None)
nodata (int | float | None)
sharing (bool)
indexes (int)
- Return type:
None
- ecoscope.io.raster.reduce_region(gdf, raster_path_list, reduce_func)[source]#
A function to apply the reduce_func to the values of the pixels within each of the rasters for every shape within the input geopandas dataframe ‘geometry’ column :param gdf: geopandas dataframe. The geometry column will be used to mask the areas of the input raster to be used in the reduction :param raster_path_list: a list of raster files on disc to analyse :param reduce_func: a single-value function to apply to the values of the input raster :return: dataframe with a column of reduce values for each raster and a row for each region
- Parameters:
raster_path_list (list[str])
reduce_func (collections.abc.Callable)
- Return type:
pandas.DataFrame
- ecoscope.io.raster.raster_to_gdf(raster_path)[source]#
- Parameters:
raster_path (str | os.PathLike | rasterio.MemoryFile)
- Return type:
geopandas.GeoDataFrame
- ecoscope.io.raster.grid_to_raster(grid, xlen, ylen, val_column='', out_dir='', raster_name=None)[source]#
Save a GeoDataFrame grid to a raster.
Args: grid (gpd.GeoDataFrame): The grid to rasterize xlen (int): The width of the raster cells, units must be valid in the CRS of the provided grid ylen (int): The height of the raster cells, units must be valid in the CRS of the provided grid val_column (str): The dataframe column of values to fill the raster cells out_dir (str): The directory to save the raster to - inert if raster_name is not provided raster_name (str): The filename name of the output raster
Returns: A rio.MemoryFile if raster_name is provided
- Parameters:
grid (geopandas.GeoDataFrame)
xlen (int)
ylen (int)
val_column (str)
out_dir (str)
raster_name (str | None)
- Return type:
None | rasterio.MemoryFile