environmentaltools.temporal.fit_marginal_distribution
- environmentaltools.temporal.fit_marginal_distribution(df: DataFrame, parameters: dict, verbose: bool = False)[source]
Fits a stationary (or not), simple or mixed probability model to data.
Additional information can be found in Cobos et al., 2022, ‘MarineTools.temporal: A Python package to simulate Earth and environmental time series’. Environmental Modelling and Software.
- Parameters:
df (pd.DataFrame) – The raw time series
parameters (dict) –
The initial guess parameters of the probability models with the following keys:
- ’var’str
Name of the variable
- ’type’str
Defines circular or linear variables
- ’fun’list
List of strings with the name of the probability model
- ’non_stat_analysis’bool
False for stationary, True for non-stationary
- ’ws_ps’float or list
Initial guess of percentiles or weights of PMs
- ’basis_function’dict or None
GFS expansion specification:
- ’method’str
Option for the GFS
- ’no_terms’int
Number of terms of GFS
- ’periods’list
Periods of oscillation for NS-PMs
- ’transform’dict or None
Normalization options:
- ’make’bool
Whether to apply transformation
- ’method’str
’box-cox’ or ‘yeo-johnson’
- ’plot’bool
Whether to plot
- ’detrend’dict or None
Removing trends options:
- ’make’bool
Whether to detrend
- ’method’str
GFS option (commonly polynomial approaches)
- ’optimization’dict
Parameters for scipy.optimize.minimize:
- ’method’str
e.g., “SLSQP”
- ’maxiter’float
Maximum iterations
- ’ftol’float
Function tolerance
- ’eps’float
Step size for numerical derivatives
- ’bounds’float
Bounds for optimization
- ’weighted’bool
For weighted data along time axis
- ’giter’int
Number of global iterations
- ’initial_parameters’dict or None
Initial parameters for unique optimization mode:
- ’make’bool
Whether to use initial parameters
- ’mode’list
Mode to be computed independently
- ’par’list
Initial guess of parameters for given mode
- ’file_name’str, optional
Path where analysis will be saved
verbose (bool, optional) – If True, shows information of the fitting process. Default is False.
- Returns:
The fitting parameters
- Return type:
dict
Examples
>>> param = {'Hs': {'var': 'Hs', ... 'fun': {0: 'norm'}, ... 'type': 'linear', ... 'non_stat_analysis': True, ... 'basis_function': {"method": "trigonometric", ... "no_terms": 4, ... "periods": [1, 2, 4]}, ... 'ws_ps': 1, ... 'transform': {"make": True, ... "plot": False, ... "method": "box-cox"}, ... 'detrend': {"make": True, ... "method": "polynomial"}, ... 'optimization': {'method': 'SLSQP', ... 'eps': 1e-7, ... 'ftol': 1e-4, ... 'maxiter': 1e2, ... 'bounds': 0.5}, ... 'giter': 10, ... 'scale': False, ... 'bic': True, ... 'file_name': 'output.pkl' ... } ... }