fit.py

swxg.fit.fit_copulae(data: DataFrame, resolution: str, precip_fit_years: list[int], ar_lag: int, copula_families: list[str]) dict

Function that fits and validates the temperature data through fitting of hydroclimatic copulae. Precipitation and temperature data are both first assessed by their Kendall and Spearman correlations. Next, they are passed through an AR(n) filter – default AR(1) – to calculate residuals. These residuals can be visually assessed for stationarity and their dependence structure (Kendall plots). Pseudo-observations are created from the residuals, and then copulae of different families are fit to the pseudo-observations (Independence, Frank, and Gaussian copula families are available in the current version).

Parameters

data: pd.DataFrame

Temporal reformat of raw_data where each year, month, day have their own column in the DataFrame

resolution: str

The temporal resolution of the input data. Can be ‘monthly’ or ‘daily’

precip_fit_years: list[int]

Years that precipitation was fit to

ar_lag: int

The time lag to consider in the AR fit step

copula_families: list[str]

The type of copula to consider when choosing a best-fitting family

Returns

pt_dict: dict

Dictionary containing statistical information related to fitting of copulae/temp data

swxg.fit.fit_data(data: DataFrame, resolution: str, validation: bool, dirpath: str, fit_kwargs: dict) list[dict, dict]

Managing function that fits the raw climate/weather data as a reformatted DataFrame, with statistics and sampling schemes for precipitation, additional parameters (i.e. temperature), and the relationship between the two

Parameters

data: pd.DataFrame

Temporally reformatted data to be used for the fitting

resolution: str

The temporal resolution of the input data. Can be ‘monthly’ or ‘daily’

validation: bool

Flag for producing figures to validate each step of the generator

dirpath: str

Path for where to save the validation figures

fit_kwargs: dict

Dictionary with the fit keyword arguments

Returns

precip_fit_dict: dict

Dictionary containing statistical information related to fitting of precipitation data

copulaetemp_fit_dict: dict

Dictionary containing statistical information related to conditional fitting of temperature data through copulae

swxg.fit.fit_precip(data: DataFrame, resolution: str, min_states: int, max_states: int, fixed_states: int) dict

Function that fits and validates the precipitation data. Precipitation is transformed to a log-scale, annualized (summed), and fit to a Gaussian mixture Hidden Markov model (GMHMM)

Parameters

data: pd.DataFrame

Temporal reformat of raw_data where each year, month, day have their own column in the DataFrame

resolution: str

The temporal resolution of the input data. Can be ‘monthly’ or ‘daily’

min_states: int

The minimum number of hidden states to try fitting

max_states: int

The maximum number of hidden states to try fitting. More than ~6 tends to perform poorly in terms of best fit and length of computation

fixed_states: int

Do not try fitting for best number of hidden states and only use this value

Returns

precip_fit_dict: dict

Dictionary containing statistical information related to fitting of precipitation data