deepsensor.model.pred

deepsensor.model.pred#

class Prediction(target_var_IDs, pred_params, dates, X_t, X_t_mask=None, coord_names=None, n_samples=0, forecasting_mode=False, lead_times=None)[source]#

Bases: dict

Object to store model predictions in a dictionary-like format.

Maps from target variable IDs to xarray/pandas objects containing prediction parameters (depending on the output distribution of the model).

For example, if the model outputs a Gaussian distribution, then the xarray/pandas objects in the Prediction will contain a mean and std.

If using a Prediction to store model samples, there is only a samples entry, and the xarray/pandas objects will have an additional sample dimension.

Parameters:
  • target_var_IDs (List[str]) – List of target variable IDs.

  • dates (List[Union[str, pd.Timestamp]]) – List of dates corresponding to the predictions.

  • X_t (xarray.Dataset | xarray.DataArray | pandas.DataFrame | pandas.Series | pandas.Index | numpy.ndarray) – Target locations to predict at. Can be an xarray object containing on-grid locations or a pandas object containing off-grid locations.

  • X_t_mask (xarray.Dataset | xarray.DataArray, optional) – 2D mask to apply to gridded X_t (zero/False will be NaNs). Will be interpolated to the same grid as X_t. Default None (no mask).

  • n_samples (int) – Number of joint samples to draw from the model. If 0, will not draw samples. Default 0.

  • forecasting_mode (bool) – If True, stored forecast predictions with an init_time and lead_time dimension, and a valid_time coordinate. If False, stores prediction at t=0 only (i.e. spatial interpolation), with only a single time dimension. Default False.

  • lead_times (List[pd.Timedelta], optional) – List of lead times to store in predictions. Must be provided if forecasting_mode is True. Default None.

assign(prediction_parameter, date, data, lead_times=None)[source]#

Args: prediction_parameter (str)

date (Union[str, pd.Timestamp])

data (np.ndarray)

If off-grid: Shape (N_var, N_targets) or (N_samples, N_var, N_targets). If on-grid: Shape (N_var, N_x1, N_x2) or (N_samples, N_var, N_x1, N_x2).

lead_time (pd.Timedelta, optional)

Lead time of the forecast. Required if forecasting_mode is True. Default None.

create_empty_spatiotemporal_xarray(X, dates, coord_names=None, data_vars=None, prepend_dims=None, prepend_coords=None)[source]#

Parameters:
  • X (xarray.Dataset | xarray.DataArray) –

  • dates (List[...]) –

  • coord_names (dict, optional) – Dict mapping from normalised coord names to raw coord names, by default {“x1”: “x1”, “x2”: “x2”}

  • data_vars (List[str], optional) – …, by default [“var”]

  • prepend_dims (List[str], optional) – …, by default None

  • prepend_coords (dict, optional) – …, by default None

Returns:

Raises:
  • ValueError – If data_vars contains duplicate values.

  • ValueError – If coord_names["x1"] is not uniformly spaced.

  • ValueError – If coord_names["x2"] is not uniformly spaced.

  • ValueError – If prepend_dims and prepend_coords are not the same length.

increase_spatial_resolution(X_t_normalised, resolution_factor, coord_names=None)[source]#

Parameters:
  • X_t_normalised

  • resolution_factor

  • coord_names (dict, optional) – Dict mapping from normalised coord names to raw coord names, by default {“x1”: “x1”, “x2”: “x2”}

Returns:

infer_prediction_modality_from_X_t(X_t)[source]#
Parameters:

X_t (Union[xr.DataArray, xr.Dataset, pd.DataFrame, pd.Series, pd.Index, np.ndarray]) –

Returns:

str – “on-grid” if X_t is an xarray object, “off-grid” if X_t is a pandas or numpy object.

Raises:

ValueError – If X_t is not an xarray, pandas or numpy object.