climateindices

neuralhydrology.datautils.climateindices.calculate_camels_us_dyn_climate_indices(data_dir: Path, basins: List[str], window_length: int, forcings: str, variable_names: Dict[str, str] = None, output_file: Path = None) Dict[str, pandas.DataFrame]

Calculate dynamic climate indices for the CAMELS US dataset.

Compared to the long-term static climate indices included in the CAMELS US data set, this function computes the same climate indices by a moving window approach over the entire data set. That is, for each time step, the climate indices are re-computed from the last window_length time steps. The resulting dictionary of DataFrames can be used with the additional_feature_files argument. Unlike in CAMELS, the ‘_freq’ indices will be fractions, not number of days. To compare the values to the ones in CAMELS, they need to be multiplied by 365.25.

Parameters:
  • data_dir (Path) – Path to the CAMELS US directory.

  • basins (List[str]) – List of basin ids.

  • window_length (int) – Look-back period to use to compute the climate indices.

  • forcings (str) – Can be e.g. ‘daymet’ or ‘nldas’, etc. Must match the folder names in the ‘basin_mean_forcing’ directory.

  • variable_names (Dict[str, str], optional) – Mapping of the forcings’ variable names, needed if forcings other than DayMet, Maurer, or NLDAS are used. If provided, this must be a dictionary that maps the keys ‘prcp’, ‘tmin’, ‘tmax’, ‘srad’ to the forcings’ respective variable names.

  • output_file (Path, optional) – If specified, stores the resulting dictionary of DataFrames to this location as a pickle dump.

Returns:

Dictionary with one time-indexed DataFrame per basin. By definition, the climate indices for a given day in the DataFrame are computed from the window_length previous time steps (including the given day).

Return type:

Dict[str, pd.DataFrame]

neuralhydrology.datautils.climateindices.calculate_dyn_climate_indices(precip: pandas.Series, tmax: pandas.Series, tmin: pandas.Series, pet: pandas.Series, window_length: int, raise_nan=False) pandas.DataFrame

Calculate dynamic climate indices.

Compared to the long-term static climate indices included in the CAMELS dataset, this function computes the same climate indices by a moving window approach over the entire dataset. That is, for each time step, the climate indices are re-computed from the last window_length time steps.

Parameters:
  • precip (pd.Series) – Time-indexed series of precipitation.

  • tmax (pd.Series) – Time-indexed series of maximum temperature.

  • tmin (pd.Series) – Time-indexed series of minimum temperature.

  • pet (pd.Series) – Time-indexed series of potential evapotranspiration.

  • window_length (int) – Look-back period to use to compute the climate indices.

  • raise_nan (bool, optional) – If True, will raise a ValueError if a climate index is NaN. Default: False.

Returns:

Time-indexed DataFrame of climate indices. By definition, the climate indices for a given day in the DataFrame are computed from the window_length previous time steps (including the given day).

Return type:

pd.DataFrame

Raises:

ValueError – If raise_nan is True and a calculated climate index is NaN at any point in time.