Binning¶
- class weatherbenchX.binning.Binning(bin_dim_name: str)[source]¶
Binning base class.
Init.
- Parameters:
bin_dim_name – Name of binning dimension.
- class weatherbenchX.binning.Regions(regions: Mapping[Hashable, Tuple[Tuple[int, int], Tuple[int, int]]], bin_dim_name: str = 'region', land_sea_mask: DataArray | None = None)[source]¶
Class for rectangular region binning.
Note that coordinate must be named latitude and longitude.
Init.
- Parameters:
regions – Dictionary specifying {name: ((lat_lims), (lon_lims))}.
bin_dim_name – Name of binning dimension. Default: ‘region’
land_sea_mask – (Optional) Boolean mask (land = True) with same latitude/longitude coordinates as the statistic. If provided, for each region will add a new land-onlybin with the name {region}_land.
- class weatherbenchX.binning.ByExactCoord(coord: str, add_global_bin: bool = False)[source]¶
Binning by unique coordinate values.
This will create a bin for each unique coordinate value, for example for each unique lead time in the case of sparse forecasts where lead_time is a coordinate but not a dimension.
Init.
- Parameters:
coord – Name of coordinate to bin by.
add_global_bin – If True, add a global bin containing all data. Default: False.
- class weatherbenchX.binning.ByTimeUnit(unit: str, time_dim: str, add_global_bin: bool = False)[source]¶
Bin by time unit for given axis.
This uses the .dt datetime accessor in xarray, so this will only work for datetime64 coordinates.
See: https://docs.xarray.dev/en/latest/generated/xarray.core.accessor_dt.DatetimeAccessor.html
Example
` unit = 'hour' time_dim = 'init_time' `This will aggregate together all data initialized at the same time of day, e.g. [0, 1, 2, .., 23].Init.
- Parameters:
unit – Time unit to bin by.
time_dim – Time dimension to bin by.
add_global_bin – If True, add a global bin containing all data. Default: False.
- class weatherbenchX.binning.ByCoordBins(dim_name: str, bin_edges: ndarray)[source]¶
Binning by specified bins over a coordinate.
Init.
- Parameters:
dim_name – Name of dimension to bin by.
bin_edges – Bin edges to bin by.
- class weatherbenchX.binning.BySets(sets: Mapping[str, Sequence[Any]], coord_name: str, bin_dim_name: str | None = None, add_global_bin: bool = False)[source]¶
Bin by sets of values along a coordinate.
This is, for example, useful for binning by different sets of station names.
Init.
- Parameters:
sets – Dictionary specifying sets of values to bin by.
coord_name – Name of coordinate to bin over.
bin_dim_name – Name of binning dimension. Default: dim_name
add_global_bin – If True, add a global bin containing all data. Default: False.