easy_vic_build.tools.geo_func.clip

Clipping utilities for array grids and GeoTIFF rasters.

Functions

clip(dst_lat, dst_lon, dst_res, src_lat, ...)

Clip source gridded arrays by destination extent and resolution buffer.

clip_tiff(input_tiff, output_tiff[, bbox, ...])

Clip a GeoTIFF by bounding box or shapefile boundary.

easy_vic_build.tools.geo_func.clip.clip(dst_lat, dst_lon, dst_res, src_lat, src_lon, src_data, reverse_lat=True)[source]

Clip source gridded arrays by destination extent and resolution buffer.

This function is typically used as a pre-step before grid searching to reduce search-space size and improve runtime.

Parameters:
  • dst_lat (array-like) – The latitude values of the target grid (destination).

  • dst_lon (array-like) – The longitude values of the target grid (destination).

  • dst_res (float) – The resolution of the target grid (in degrees).

  • src_lat (array-like) – The latitude values of the source data grid.

  • src_lon (array-like) – The longitude values of the source data grid.

  • src_data (array-like) – Source 2D data array indexed by [lat, lon].

  • reverse_lat (bool, optional) – If True, assumes the source latitude values are in descending order (large to small). If False, assumes ascending order (small to large). Default is True.

Returns:

(src_data_clip, src_lon_clip, src_lat_clip).

Return type:

tuple

Notes

dst_res / 2 is used as an outer buffer when locating source indices.

easy_vic_build.tools.geo_func.clip.clip_tiff(input_tiff: str, output_tiff: str, bbox: tuple | None = None, shp_path: str | None = None)[source]

Clip a GeoTIFF by bounding box or shapefile boundary.

Parameters:
  • input_tiff (str) – Path to the input GeoTIFF file.

  • output_tiff (str) – Path to the output clipped GeoTIFF file.

  • bbox (tuple, optional) – Geographic extent (xmin, ymin, xmax, ymax), e.g. (105.2, 33.5, 106.8, 34.9).

  • shp_path (str, optional) – Path to a shapefile used as the clipping boundary.

Returns:

Clipped raster is written to output_tiff.

Return type:

None

Raises:
  • FileNotFoundError – If input_tiff or shp_path does not exist.

  • ValueError – If neither bbox nor shp_path is provided.