Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions map_binning/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,31 @@ class Binning:
ydim_name : str, optional
Name of the y (latitude) dimension in the datasets. Default is 'lat'.
search_radius : float or None, optional
Radius in degrees to search for high-resolution points around each low-resolution grid point.
If None, the radius is automatically calculated based on the spacing of the low-resolution grid.
Radius in degrees to search for high-resolution points around each
low-resolution grid point. If None, the radius is automatically
calculated based on the spacing of the low-resolution grid.

Methods
-------
create_binning_index()
Creates a mapping from each low-resolution grid point to the
indices of high-resolution grid points within the specified search radius.

mean_binning()
Applies the binning index to compute the mean of high-resolution data
for each low-resolution grid point.

Examples
--------
>>> import xarray as xr
>>> from map_binning.binning import Binning
>>> ds_high = xr.open_dataset('high_res_data.nc')
>>> ds_low = xr.open_dataset('low_res_grid.nc')
>>> binning = Binning(ds_high, ds_low, var_name='temperature')
>>> binning = Binning(
... ds_high,
... ds_low,
... var_name='temperature'
... )
>>> binned_data = binning.mean_binning(precomputed_binning_index=False)
>>> print(binned_data)
xr.DataArray with binned mean values on the low-resolution grid.
Expand Down Expand Up @@ -82,11 +91,11 @@ def create_binning_index(self):
# check high-res is having more grid than low-res
if len(high_lats) < len(low_lats):
raise ValueError(
"High-resolution dataset latitude must have more grid points than low-resolution dataset."
"High-resolution latitude must have more grid points than low-resolution."
)
if len(high_lons) < len(low_lons):
raise ValueError(
"High-resolution dataset longitude must have more grid points than low-resolution dataset."
"High-resolution longitude must have more grid points than low-resolution."
)

# Create meshgrids for high-res points
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "map-binning"
version = "0.3.1"
version = "0.3.2"
description = "A map binning tool for spatial resampling"
authors = [{name = "Chia-Wei Hsu", email = "chiaweh2@uci.edu"}]
readme = "README.md"
Expand Down