Skip to content

module TopoPyScale.topo_compare


function correct_trend

correct_trend(df, reference_col='obs', target_col='dow', apply_correction=True)

Function to estimate linear trend correction.

Args: df (dataframe): - reference_col (str): name of the reference column, i.e. observation timeseries - target_col (str): name of the target column, i.e. downscale timeseries - apply_correction (bool): applying correction to target data

Returns:

  • dict: metrics of the linear trend estimate
  • dataframe (optional): corrected values

function correct_seasonal

correct_seasonal(
    df,
    reference_col='obs',
    target_col='dow',
    plot=True,
    apply_correction=True
)

Function to correct for seasonal signal. 1. it groups all days by day_of_year and extract the median difference. 2. it computes the 31 day rolling mean (padded on both sides)

Args:

  • df (dataframe): index must be a datetime, with daily timestep. other columns are reference and target.
  • reference_col (str): name of the reference column, i.e. observation timeseries
  • target_col (str): name of the target column, i.e. downscale timeseries plot (bool):
  • apply_correction (bool): apply correction and return corrected data

Returns: dataframe - correction for each day of year, starting on January 1.


function obs_vs_downscaled

obs_vs_downscaled(
    df,
    reference_col='obs',
    target_col='dow',
    trend_correction=True,
    seasonal_correction=True,
    param={'xlab': 'Downscaled [unit]', 'ylab': 'Observation [unit]', 'xlim': (-20, 20), 'ylim': (-20, 20), 'title': None},
    plot='heatmap'
)

Function to compare Observation to Downscaled for one given variable.

Args:

  • df (dataframe): pandas dataframe containing corresponding Observation and Downscaled values
  • reference_col (str): name of the reference column. Observation
  • target_col (str): name of the target column. Downscaled timeseries
  • trend_correction (bool): remove trend by applying a linear regression
  • seasonal_correction (bool): remove seasonal signal by deriving median per day of the year and computing the rolling mean over 31d on the median
  • param (dict): parameter for comparison and plotting
  • plot (str): plot type: heatmap or timeseries

Returns:

  • dict: metrics of regression and comparison
  • dataframe: dataframe containing the seasonal corrections to applied
  • dataframe: corrected values

Inspired by this study: https://reader.elsevier.com/reader/sd/pii/S0048969722015522?token=106483481240DE6206D83D9C7EC9D4990C2C3DE6F669EDE39DCB54FF7495A31CC57BDCF3370A6CA39D09BE293EACDDBB&originRegion=eu-west-1&originCreation=20220316094240


This file was automatically generated via lazydocs.