time_to_centre_of_mass
- postprocessinglib.evaluation.metrics.time_to_centre_of_mass(df: DataFrame, stations: list[int] = [], use_jday: bool = False) float
Calculates the time it takes to obtain 50% of the stream flow in a given year
- Parameters:
df (pd.DataFrame) – the observed or simulated dataframe
stations (list[int]) – numbers pointing to the location of the stations in the list of stations. Values can be any number from 1 to number of stations in the data
use_jday (bool, default False) – If True, treats data as JDAY-style (fixed 366-day years). If False, uses datetime index logic.
- Returns:
Dataframe containing the average time to the centre of mass for the stations
- Return type:
pd.DataFrame
Example
Calculation of the time to center of mass
>>> from postprocessinglib.evaluation import metrics, data >>> path = 'MESH_output_streamflow_1.csv' >>> DATAFRAMES = data.generate_dataframes(csv_fpath=path, warm_up=365) >>> observed = DATAFRAMES["DF_OBSERVED"] >>> simulated = DATAFRAMES["DF_SIMULATED"] >>> print(observed) QOMEAS_05BB001 QOMEAS_05BA001 YEAR JDAY 1980 366 10.20 NaN 1981 1 9.85 NaN 2 10.20 NaN 3 10.00 NaN 4 10.10 NaN ... ... ... 2017 361 NaN NaN 362 NaN NaN 363 NaN NaN 364 NaN NaN 365 NaN NaN >>> . >>> print(simulated) QOSIM_05BB001 QOSIM_05BA001 YEAR JDAY 1980 366 2.530770 1.006860 1981 1 2.518999 1.001954 2 2.507289 0.997078 3 2.495637 0.992233 4 2.484073 0.987417 ... ... ... 2017 361 4.418050 1.380227 362 4.393084 1.372171 363 4.368303 1.364174 364 4.343699 1.356237 365 4.319275 1.348359
>>> # Calculating the time to center of mass >>> ttcom = metrics.time_to_centre_of_mass(df=observed) >>> print(ttcom) ttcom Station 1 185.0 Station 2 166.0