Skip to content

Helper helpingpredictor

Class: HelpingPredictor#

The HelpingPredictor class within the helper.predictors submodule is designed to manage and prepare predictor data that aids in the estimation of missing values within a target dataset. It initializes with a specific variable from a dataset and aligns predictor data accordingly, handling both the extraction and storage of the processed data.

Constructor#

def __init__(self, ds: xr.Dataset, variable: str, ds_predictor: xr.DataArray, predictor_path: str,
            predictor: str = 'lccs_class', layer_dim: str = None)
Parameters#
  • ds (xarray.Dataset): The dataset containing the target variable.
  • variable (str): The target variable to estimate.
  • ds_predictor (xarray.DataArray): The dataset containing the predictor variable.
  • predictor_path (str): Path to save the processed predictor data.
  • predictor (str): Name of the predictor variable. Defaults to lccs_class.
  • layer_dim (str): Dimension along which to iterate. First dimension is default if not specified.

Methods#

The get_predictor_data method is designed to fetch and prepare the predictor in order to conduct the gap filling process. It extracts relevant data that align with the target dataset, processes this data if necessary, and saves it in a format that is easily accessible for further analysis.

def get_predictor_data(self) -> str

Parameters#
  • None: This method has no input parameters.
Returns#
  • str: The file path of the saved .zarr file containing the processed predictor data.

Example#

import xarray as xr
from ml4xcube.gapfilling.helper.predictors import HelpingPredictor

# Example data and paths
ds = xr.open_dataset('path_to_dataset')
ds_predictor = xr.open_dataarray('path_to_predictor_data')
predictor_path = 'path_to_store_processed_data'

# Initialize the HelpingPredictor
predictor = HelpingPredictor(ds, 'temperature', ds_predictor, predictor_path)

# Get and process predictor data
predictor_data_path = predictor.get_predictor_data()
print(f'Processed predictor data saved to: {predictor_data_path}')