API Reference#
This section provides comprehensive documentation for all gdptools classes and functions.
Overview#
The gdptools API is organized into several key modules:
Data Classes: Input data handling and validation
Weight Generation: Spatial intersection weight calculation
Aggregation: Statistical aggregation and interpolation
Zonal Statistics: Raster-based zonal operations
Helper Methods: Utility functions and spatial operations
Quick Start#
For most users, the primary entry points are:
# Grid-to-polygon aggregation
from gdptools import AggGen
# Polygon-to-polygon weights
from gdptools import WeightGenP2P
# Zonal statistics on rasters
from gdptools import ZonalGen
Module Index#
Top-level package for pygeoapi plugin: Gdptools.
Top-level package for pygeoapi plugin: Gdptools. |
Classes and Functions Index#
|
Interface for Climate-R catalog datasets with automatic metadata handling. |
|
Handler for user-provided xarray datasets with custom configuration. |
|
Factory for NHGF STAC catalog datasets. |
|
Interface for Zarr-backed NHGF STAC catalog datasets. |
|
Interface for GeoTIFF-backed NHGF STAC catalog datasets (e.g., NLCD). |
|
Handler for GeoTIFF and other raster data sources. |
|
Performs grid-to-polygon aggregation using area-weighted statistics. |
|
Calculates grid-to-polygon intersection weights for area-weighted aggregation. |
|
Calculates polygon-to-polygon intersection weights for spatial data transfer. |
|
Calculate standard zonal statistics for raster data. |
|
Create a dictionary to use with xarray .sel() method to subset by time and space. |
|
Create a dictionary to use with xarray .sel() method to subset TIFF data by space and band. |
|
Create a dictionary to use with xarray .sel() method to subset TIFF DataArray by space. |
Check that gridded data has the required dimensions. |
|
|
A container for data prepared for aggregation operations. |
|
A container for data prepared for weight generation. |
|
A Pydantic model for ClimateR-style catalog items. |
Data Containers#
gdptools passes prepared data between its stages in a few small containers.
AggData and WeightData are built internally – by
prep_agg_data() and
prep_wght_data() respectively – and
CatClimRItem models one entry of a ClimateR-style catalog. All three appear in
the public API as parameter or return types, so they are documented here.
- class AggData(variable, cat_cr, da, target_gdf, target_id, source_time_period)[source]#
Bases:
objectA container for data prepared for aggregation operations.
This dataclass holds all the necessary data for a single variable that has been pre-processed for aggregation. This includes the original gridded data subsetted to the area of interest, the target geometries, and relevant metadata.
Instances of AggData are typically created internally by gdptools during the aggregation process. For each variable specified in a UserData object, an AggData instance is generated.
- cat_cr#
Catalog metadata describing the gridded dataset.
- da#
The gridded data, spatially and temporally subsetted to the area of interest.
- Type:
- target_gdf#
Target vector geometries for aggregation.
- Type:
- source_time_period#
Start and end dates for the time slice used to prepare this data.
- __init__(variable, cat_cr, da, target_gdf, target_id, source_time_period)#
- class WeightData(target_gdf, target_id, grid_cells)[source]#
Bases:
objectA container for data prepared for weight generation.
This dataclass holds all the necessary data for calculating spatial intersection weights. This includes the target vector geometries and the source grid cell geometries.
Instances of WeightData are typically created internally by gdptools during the weight generation process.
- target_gdf#
The geopandas.GeoDataFrame containing the target vector geometries.
- target_id#
The column name in target_gdf that serves as the unique identifier for each geometry.
- Type:
- grid_cells#
The geopandas.GeoDataFrame containing the source grid cell polygons.
- __init__(target_gdf, target_id, grid_cells)#
- class CatClimRItem(*, id=None, asset=None, URL, varname, long_name=None, variable=None, description=None, units=None, model=None, ensemble=None, scenario=None, T_name=None, duration=None, interval=None, nT=0, X_name, Y_name, X1=None, Xn=None, Y1=None, Yn=None, resX, resY, ncols=None, nrows=None, proj=None, toptobottom, tiled=None, crs=None)[source]#
A Pydantic model for ClimateR-style catalog items.
This class provides a structured representation of a single entry from a climateR-style data catalog, such as the one maintained by Mike Johnson. It includes fields for dataset identification, access information (URL), variable metadata, and spatiotemporal properties.
The model includes validators to handle common data inconsistencies found in catalog files, such as converting NaN values to None, setting default values for projection, and ensuring boolean fields are correctly parsed.
Source data from: https://github.com/mikejohnson51/climateR-catalogs/releases/download/June-2024/catalog.parquet
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- __init__(**data)#
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.