equi7grid.warp#
Code for resampling image raster data to the Equi7Grid.
Yields tiled raster images organised in folders for a) in the continental zones + grid sampling b) the subgrid tiling
The module should help to easily bring your raster images to the Equi7Grid spatial reference.
Module Contents#
Functions#
Convert pixel to world system coordinates. |
|
Get accurate boundary of a raster file. |
|
Get extent of a raster file. |
|
Get default Equi7Grid filename. |
|
Resample a portion of an image to an Equi7Grid tile. |
|
Get all overlapping Equi7Grid tiles. |
|
Convert Equi7Grid tilenames to tiles. |
|
Resample an image to Equi7Grid tiles. |
API#
- equi7grid.warp.pixel_to_world_coords(tf: rasterio.warp.Affine, pixel_coords: numpy.ndarray) numpy.ndarray#
Convert pixel to world system coordinates.
- Parameters:
tf (Affine) – Affine object representing affine transformation parameters.
pixel_coords (np.ndarray) – 2D array with shape (n, 2) containing pixel coordinates: - first column are pixel column coordinates - second column are pixel row coordinates
- Returns:
World system coordinates array with shape (n, 2): - first column are X coordinates - second column are Y coordinates
- Return type:
np.ndarray
- equi7grid.warp.get_raster_boundary(filepath: pathlib.Path) pytileproj.ProjGeom#
Get accurate boundary of a raster file.
- Parameters:
filepath (Path) – Geospatial filepath to retrieve raster boundary from.
- Returns:
Accurate raster boundary represented by ProjGeom instance (shapely polygon + pyproj.CRS).
- Return type:
ProjGeom
- equi7grid.warp.get_raster_extent(filepath: pathlib.Path) pytileproj.ProjGeom#
Get extent of a raster file.
- Parameters:
filepath (Path) – Geospatial filepath to retrieve raster extent from.
- Returns:
Raster extent represented by ProjGeom instance (shapely polygon + pyproj.CRS).
- Return type:
ProjGeom
- equi7grid.warp.get_default_e7_filename(filepath: pathlib.Path, ftilename: str) str#
Get default Equi7Grid filename.
- Parameters:
filepath (Path) – Full system path to geospatial image file.
ftilename (str) – Full Equi7Grid tilename.
- Returns:
Equi7Grid standard filename.
- Return type:
str
- equi7grid.warp.resample_tile(e7tile: equi7grid.core.Equi7Tile, filepath: pathlib.Path, output_dirpath: pathlib.Path, *, band: int = 1, image_nodata: float | None = None, resampling_type: Union[rasterio.warp.Resampling, None] = None, compress_type: str = 'LZW', naming_traffo: collections.abc.Callable | None = None, tile_nodata: float | None = None, tile_dtype: numpy.dtype | None = None, tile_scale: float | None = None, tile_offset: float | None = None, tile_blocksize: int | None = None, tif_is_tiled: bool = True, overwrite: bool = False, create_e7_folder: bool = True) pathlib.Path#
Resample a portion of an image to an Equi7Grid tile.
- Parameters:
e7tile (Equi7Tile) – Equi7Tile instance to resample and slice to.
filepath (Path) – Full system path to geospatial image file.
output_dirpath (Path) – Full system path to the output directory.
band (int, optional) – Band number (defaults to 1).
image_nodata (float | None, optional) – Nodata value of geospatial image. Defaults to nodata value provided in the file metadata.
resampling_type (Resampling | None, optional) – Resampling method provided by rasterio. Defaults to neareast.
compress_type (str, optional) – Compression type (defaults to “LZW”).
naming_traffo (Callable | None, optional) – Callable/function to define naming convention. It expects two input arguments: -
filepath: the full system path to geospatial image file -ftilename: the full tilename. Defaults to standard naming: “[filename]_[full tilename].[suffix]”tile_nodata (float | None, optional) – Nodata value of the tiled image. Defaults to nodata value of the input image.
tile_dtype (np.dtype | None, optional) – Data type of the tiled image. Defaults to data type of the input image.
tile_scale (float | None, optional) – Scale factor of the tiled image. Defaults to scale factor of the input image.
tile_offset (float | None, optional) – Offset of the tiled image. Defaults to offset of the input image.
tile_blocksize (int | None, optional) – Block size of the tiled image. Defaults to block size of the input image.
tif_is_tiled (bool, optional) – Flag to define if the output tile image should be tiled w.r.t. the GeoTIFF format (defined by the block size) or not (defaults to True).
overwrite (bool, optional) – Flag if data should be overwritten or not (defaults to false).
create_e7_folder (bool, optional) – Flag if a root Equi7Grid folder (“EQUI7_[continent]”) should be created or not (defaults to true).
- Returns:
Full system path to the image tile in the Equi7Grid.
- Return type:
Path
- equi7grid.warp.get_overlapping_tiles(e7grid: equi7grid.core.Equi7Grid, *, tiling_id: str | int = 0, xy_bbox_map: collections.abc.Mapping[str, equi7grid._types.Extent] | None = None, geog_bbox: equi7grid._types.Extent | None = None, roi_geom: pytileproj.ProjGeom | None = None, filepath: pathlib.Path | None = None, cover_land: bool = False, accurate_boundary: bool = False) list[equi7grid.core.Equi7Tile]#
Get all overlapping Equi7Grid tiles.
- Parameters:
e7grid (Equi7Grid) – Equi7Grid instance to get the tiles from.
tiling_id (int | str, optional) – Tiling level or name. Defaults to 0, the first tiling level.
xy_bbox_map (Mapping[str, Extent] | None, optional) – Defines projected bounding boxes in the Equi7Grid to consider for reprojection. The keys are the continents, and the values the spatial extent/bounding box. Defaults to image extent.
geog_bbox (Extent | None, optional) – Defines geographic bounding box to consider for reprojection. Defaults to image extent.
roi_geom (ProjGeom | None, optional) – Defines geospatial geometry to consider only a certain region for reprojection. Defaults to image extent.
filepath (Path | None, optional) – Full system path to geospatial image file.
cover_land (bool, optional) – Flag defining if only tiles covering land should be considered (defaults to false).
accurate_boundary (bool, optional) – Flag to define if the accurate raster boundary (excluding nodata values) should be used. If false, then the image extent will be used (default).
- equi7grid.warp.ftilenames_to_tiles(ftilenames: list[str], e7grid: equi7grid.core.Equi7Grid) list[equi7grid.core.Equi7Tile]#
Convert Equi7Grid tilenames to tiles.
- equi7grid.warp.resample_to_equi7_tiles(filepath: pathlib.Path, e7grid: equi7grid.core.Equi7Grid, output_dirpath: pathlib.Path, *, tiling_id: str | int = 0, xy_bbox_map: collections.abc.Mapping[str, equi7grid._types.Extent] | None = None, geog_bbox: equi7grid._types.Extent | None = None, roi_geom: pytileproj.ProjGeom | None = None, cover_land: bool = False, accurate_boundary: bool = False, ftilenames: list[str] | None = None, band: int = 1, image_nodata: float | None = None, resampling_type: Union[rasterio.warp.Resampling, None] = None, compress_type: str = 'LZW', naming_traffo: collections.abc.Callable | None = None, tile_nodata: float | None = None, tile_dtype: numpy.dtype | None = None, tile_scale: float | None = None, tile_offset: float | None = None, tile_blocksize: int | None = None, tif_is_tiled: bool = True, overwrite: bool = False, create_e7_folder: bool = True, n_tasks: int = 1) list[pathlib.Path]#
Resample an image to Equi7Grid tiles.
- Parameters:
filepath (Path) – Full system path to geospatial image file.
e7grid (Equi7Grid) – Equi7Grid instance to resample and slice to.
output_dirpath (Path) – Full system path to the output directory.
tiling_id (int | str, optional) – Tiling level or name. Defaults to 0, the first tiling level.
xy_bbox_map (Mapping[str, Extent] | None, optional) – Defines projected bounding boxes in the Equi7Grid to consider for reprojection. The keys are the continents, and the values the spatial extent/bounding box. Defaults to image extent.
geog_bbox (Extent | None, optional) – Defines geographic bounding box to consider for reprojection. Defaults to image extent.
roi_geom (ProjGeom | None, optional) – Defines geospatial geometry to consider only a certain region for reprojection.Defaults to image extent.
cover_land (bool, optional) – Flag defining if only tiles covering land should be considered (defaults to false).
accurate_boundary (bool, optional) – Flag to define if the accurate raster boundary (excluding nodata values) should be used. If false, then the image extent will be used (default).
ftilenames (list[str] | None, optional) – List of full tilenames to resample to. Defaults to all tiles intersecting with the image.
band (int, optional) – Band number (defaults to 1).
image_nodata (float | None, optional) – Nodata value of geospatial image. Defaults to nodata value provided in the file metadata.
resampling_type (Resampling | None, optional) – Resampling method provided by rasterio. Defaults to neareast.
compress_type (str, optional) – Compression type (defaults to “LZW”).
naming_traffo (Callable | None, optional) – Callable/function to define naming convention. It expects two input arguments: -
filepath: the full system path to geospatial image file -ftilename: the full tilename. Defaults to standard naming: “[filename]_[full tilename].[suffix]”tile_nodata (float | None, optional) – Nodata value of the tiled image. Defaults to nodata value of the input image.
tile_dtype (np.dtype | None, optional) – Data type of the tiled image. Defaults to data type of the input image.
tile_scale (float | None, optional) – Scale factor of the tiled image. Defaults to scale factor of the input image.
tile_offset (float | None, optional) – Offset of the tiled image. Defaults to offset of the input image.
tile_blocksize (int | None, optional) – Block size of the tiled image. Defaults to block size of the input image.
tif_is_tiled (bool, optional) – Flag to define if the output tile image should be tiled w.r.t. the GeoTIFF format (defined by the block size) or not (defaults to True).
overwrite (bool, optional) – Flag if data should be overwritten or not (defaults to false).
create_e7_folder (bool, optional) – Flag if a root Equi7Grid folder (“EQUI7_[continent]”) should be created or not (defaults to true).
n_tasks (int, optional) – Number of parallel processes to resample multiple tiles in parallel (defaults to 1).
- Returns:
List of full system paths to the image tiles in the Equi7Grid.
- Return type:
list[Path]