easy_vic_build.tools.geo_func.resample
Resampling methods for grid-based geospatial variables.
This module provides several interpolation/aggregation strategies that map source-grid values to a destination location, including mean, IDW, bilinear, majority vote, generic-function aggregation, and conservative remapping.
Functions
|
Resample values using a user-provided aggregation function. |
|
Resample values using inverse-distance weighting (IDW). |
|
Resample categorical values using majority vote. |
|
Resample values using simple arithmetic mean. |
|
Resample values using bilinear interpolation with fallbacks. |
|
Resample values using overlap-area conservative remapping. |
- easy_vic_build.tools.geo_func.resample.resampleMethod_SimpleAverage(searched_grids_data, searched_grids_lat, searched_grids_lon, dst_lat=None, dst_lon=None, missing_value=None)[source]
Resample values using simple arithmetic mean.
- Parameters:
searched_grids_data (array-like) – The data values of the searched grids.
searched_grids_lat (array-like) – The latitudes corresponding to the searched grids.
searched_grids_lon (array-like) – The longitudes corresponding to the searched grids.
dst_lat (float, optional) – The latitude of the destination grid (not used in computation).
dst_lon (float, optional) – The longitude of the destination grid (not used in computation).
missing_value (float or None, optional) – The value representing missing data. If provided, missing data will be removed before averaging.
- Returns:
Mean value of
searched_grids_data. If no valid data is available, returnsmissing_valueornp.nan.- Return type:
float
- easy_vic_build.tools.geo_func.resample.resampleMethod_IDW(searched_grids_data, searched_grids_lat, searched_grids_lon, dst_lat, dst_lon, missing_value=None, p=2)[source]
Resample values using inverse-distance weighting (IDW).
- Parameters:
searched_grids_data (array-like) – The data values of the searched grids.
searched_grids_lat (array-like) – The latitudes corresponding to the searched grids.
searched_grids_lon (array-like) – The longitudes corresponding to the searched grids.
dst_lat (float) – The latitude of the destination grid.
dst_lon (float) – The longitude of the destination grid.
p (int or float, optional) – The power exponent for weighting, controlling the influence of distance. Default is 2.
missing_value (float or None, optional) – The value representing missing data. If provided, missing data will be removed before interpolation.
- Returns:
IDW-interpolated value at
(dst_lat, dst_lon). If no valid data is available, returnsmissing_valueornp.nan.- Return type:
float
- easy_vic_build.tools.geo_func.resample.resampleMethod_bilinear(searched_grids_data, searched_grids_lat, searched_grids_lon, dst_lat, dst_lon, missing_value=None)[source]
Resample values using bilinear interpolation with fallbacks.
Bilinear interpolation estimates the value at
(dst_lat, dst_lon)using four surrounding points. If geometric assumptions are not met, the function falls back to distance-based interpolation.Schematic representation:
- (lat2, lon1) —– (lat2, lon2) -> Corresponding latitudes and longitudes
- (x, y) |
(lat1, lon1) —– (lat1, lon2)
The interpolation first computes intermediate values along the longitude direction.
Then, it interpolates along the latitude direction.
- Parameters:
searched_grids_data (array-like) – The data values of the searched grids.
searched_grids_lat (array-like) – The latitudes corresponding to the searched grids.
searched_grids_lon (array-like) – The longitudes corresponding to the searched grids.
dst_lat (float) – The latitude of the destination grid.
dst_lon (float) – The longitude of the destination grid.
missing_value (float or None, optional) – The value representing missing data. If provided, missing data will be removed before interpolation.
- Returns:
Interpolated destination value.
- Return type:
float
Notes
Fallback behavior:
4+ points: bilinear interpolation (or IDW when points are not rectangular),
2-3 points: distance-weighted interpolation,
1 point: direct value return,
0 point:
missing_valueornp.nan.
- easy_vic_build.tools.geo_func.resample.resampleMethod_Majority(searched_grids_data, searched_grids_lat, searched_grids_lon, dst_lat=None, dst_lon=None, missing_value=None)[source]
Resample categorical values using majority vote.
This method finds the most frequently occurring value (mode) in the searched grid data. It is useful for categorical data resampling, such as land cover classification.
- Parameters:
searched_grids_data (array-like) – The data values of the searched grids.
searched_grids_lat (array-like) – The latitudes corresponding to the searched grids.
searched_grids_lon (array-like) – The longitudes corresponding to the searched grids.
dst_lat (float, optional) – The latitude of the destination grid (not used in computation).
dst_lon (float, optional) – The longitude of the destination grid (not used in computation).
missing_value (float or None, optional) – The value representing missing data. If provided, missing data will be removed before computing the majority value.
- Returns:
Most frequent value in
searched_grids_data. If no valid data is available, returnsmissing_valueornp.nan.- Return type:
float
- easy_vic_build.tools.geo_func.resample.resampleMethod_GeneralFunction(searched_grids_data, searched_grids_lat, searched_grids_lon, dst_lat=None, dst_lon=None, missing_value=None, general_function=<function mean>)[source]
Resample values using a user-provided aggregation function.
This method applies
general_functionto source values after wrapper-level preprocessing.- Parameters:
searched_grids_data (array-like) – The data values of the searched grids.
searched_grids_lat (array-like) – The latitudes corresponding to the searched grids.
searched_grids_lon (array-like) – The longitudes corresponding to the searched grids.
dst_lat (float, optional) – The latitude of the destination grid (not used in computation).
dst_lon (float, optional) – The longitude of the destination grid (not used in computation).
general_function (callable, optional) – A function that aggregates the input data, such as np.mean, np.max, or np.min. Default is np.mean.
missing_value (float or None, optional) – The value representing missing data. If provided, missing data will be removed before applying the general function.
- Returns:
Aggregated value returned by
general_function. If evaluation fails or no valid data is available, returnsmissing_valueornp.nan.- Return type:
float
- easy_vic_build.tools.geo_func.resample.resampleMethod_conservative(searched_grids_data, searched_grids_lat, searched_grids_lon, searched_grids_res=None, dst_lat=None, dst_lon=None, dst_res=None, missing_value=None)[source]
Resample values using overlap-area conservative remapping.
- Parameters:
searched_grids_data (array-like) – Values from source grids.
searched_grids_lat (array-like) – Source-grid center latitudes.
searched_grids_lon (array-like) – Source-grid center longitudes.
searched_grids_res (float, optional) – Source-grid resolution.
dst_lat (float, optional) – Destination-grid center latitude.
dst_lon (float, optional) – Destination-grid center longitude.
dst_res (float, optional) – Destination-grid resolution.
missing_value (float, optional) – Missing-value code used when no valid overlap exists.
- Returns:
Conservatively remapped destination value. If resolution inputs are missing, the function falls back to
np.nanmean(data).- Return type:
float