Interpolations

class weatherbenchX.interpolations.Interpolation[source]

Interpolation base class.

class weatherbenchX.interpolations.MultipleInterpolation(interpolations: Sequence[Interpolation])[source]

Applies multiple interpolations to a dataset in sequence.

interpolations

List of interpolations to be applied in sequence.

Type:

Sequence[weatherbenchX.interpolations.Interpolation]

class weatherbenchX.interpolations.InterpolateToFixedCoords(method: str, coords: Mapping[str, DataArray | ndarray], wrap_longitude: bool = False, extrapolate_out_of_bounds: bool = True)[source]

Interpolate to a fixed set of coordinates.

Interplation is done using xarray’s built-in interp method: https://docs.xarray.dev/en/latest/generated/xarray.DataArray.interp.html

Init.

Parameters:
  • method – Interpolation method to be passed to xarray’s interpolation API.

  • coords – Dictionary of coordinate names and values to interpolate to.

  • wrap_longitude – If True, perform a wrapped interpolation in the longitude dimension. Default: False

  • extrapolate_out_of_bounds – If True, extrapolate to out of bounds values using the chosen interpolation method. Default: True

class weatherbenchX.interpolations.InterpolateToReferenceCoords(method: str, dims: Sequence[str] | None = None, wrap_longitude: bool = False, clip_reference_coords: Iterable[str] | None = None, extrapolate_out_of_bounds: bool = True)[source]

Interpolate to a reference dataset.

Interplation is done using xarray’s built-in interp method: https://docs.xarray.dev/en/latest/generated/xarray.DataArray.interp.html

Init.

Parameters:
  • method – Interpolation method to be passed to xarray’s interpolation API.

  • dims – (Optional) Dimensions over which to interpolate. If None (default), infer dimensions from intersect of DataArray dimensions and reference coordinates.

  • wrap_longitude – If True, perform a wrapped interpolation in the longitude dimension. Default: False

  • clip_reference_coords – Clip the reference dataset to the maximum extent of the data to be interpolated in the given dimensions, e.g. [‘latitude’, ‘longitude’]. Note that this can potentially lead to errors in the reference go unnoticed. It is preferred to use a fixed interpolation instead or ensure that the reference extent matches beforehand. Default: None.

  • extrapolate_out_of_bounds – If True, extrapolate to out of bounds values using the chosen interpolation method. Default: True

class weatherbenchX.interpolations.GridToSparseWithAltitudeAdjustment(method: str, grid_elevation: DataArray, dims: Sequence[str] | None = None, wrap_longitude: bool = False, extrapolate_out_of_bounds: bool = True, max_alititude_diff_in_m: float = 1500)[source]

Applies altitude adjustment to 2m_temperature and 10m_wind_speed.

Alititude adjustments are based on the difference of the grid elevation to the station elevation. Reference: https://rmets.onlinelibrary.wiley.com/doi/10.1002/qj.2372, Section 3.3.

Assumes that elevations are in meters and an ‘elevation’ coordinate exists on the reference dataset. Requires passing a DataArray with the grid elevation corresponding to the dataset to be interpolated. Variables must be named ‘2m_temperature’ and ‘10m_wind_speed’. Other variables will be left unchanged.

Note

The same interpolation is applied to the grid_elevation as to the data, so in the case of linear interpolation, the elevation difference will also be based on the grid elevation linearly interpolated to the reference coordinates.

Init.

Parameters:
  • method – Interpolation method to be passed to xarray’s interpolation API.

  • grid_elevation – DataArray matching the dataset coordinates specifying the grid box elevation in m.

  • dims – (Optional) Dimensions over which to interpolate. If None (default), infer dimensions from intersect of DataArray dimensions and reference coordinates.

  • wrap_longitude – If True, perform a wrapped interpolation in the longitude dimension. Default: False

  • extrapolate_out_of_bounds – If True, extrapolate to out of bounds values using the chosen interpolation method. Default: True

  • max_alititude_diff_in_m – No adjustment is applied for elevation differences greater than this value. Large values can appear because of errors in the station dataset, e.g. elevation reported in ft instead of m. Default: 1500.

class weatherbenchX.interpolations.NeighborhoodThresholdProbabilities(neighborhood_sizes, thresholds, threshold_dim='threshold_value', wrap_longitude: bool = False)[source]

Converts a deterministic forecast to a probabilistic one by neighborhood averaging.

For a given threshold, the probability is devined as the fraction of the fraction of pixels in a square neighborhood that exceeds the threshold. This is the same computation as in the Fraction Skill Score.

Init.

Parameters:
  • neighborhood_sizes – List of neighborhood sizes to be used in pixels. Must be odd.

  • thresholds – List of thresholds to be used to binarize data.

  • threshold_dim – Dimension name of the thresholds. Default: ‘threshold_value’

  • wrap_longitude – If True, perform a wrapped convolution in the longitude dimension. Default: False