Deltares-research / kenmerkendewaarden

Derive indicators from waterlevel measurements
https://deltares-research.github.io/kenmerkendewaarden/
GNU General Public License v3.0
1 stars 0 forks source link

ddlpy retrieval with yearly freq #22

Closed veenstrajelmer closed 4 months ago

veenstrajelmer commented 4 months ago

Retrieve per year instead of month For timeseries it might not matter whether the measurements are retrieved per year or per month, per month is even slightly faster, so maybe avoid the try/catch and only retrieve extremes per year:

import ddlpy
import dateutil

locations = ddlpy.locations()
bool_hoedanigheid = locations['Hoedanigheid.Code'].isin(['NAP'])
bool_stations = locations.index.isin(['HOEKVHLD', 'IJMDBTHVN','SCHEVNGN'])
bool_grootheid = locations['Grootheid.Code'].isin(['WATHTE'])
bool_groepering_ts = locations['Groepering.Code'].isin(['NVT'])
bool_groepering_ext = locations['Groepering.Code'].isin(['GETETM2'])
selected_ts = locations.loc[bool_grootheid & bool_hoedanigheid & bool_groepering_ts & bool_stations]
selected_ext = locations.loc[bool_grootheid & bool_hoedanigheid & bool_groepering_ext & bool_stations]

start_date = "2017-01-01"
end_date = "2020-02-01"

print("yearly timeseries")
measurements = ddlpy.measurements(selected_ts.iloc[0], start_date, end_date, freq=dateutil.rrule.YEARLY)
# 100%|██████████| 4/4 [01:07<00:00, 16.81s/it]

print("monthly timeseries")
measurements = ddlpy.measurements(selected_ts.iloc[0], start_date, end_date)
# 100%|██████████| 37/37 [00:56<00:00,  1.52s/it]

print("yearly extremes")
measurements = ddlpy.measurements(selected_ext.iloc[0], start_date, end_date, freq=dateutil.rrule.YEARLY)
# 100%|██████████| 4/4 [00:03<00:00,  1.09it/s]

print("monthly extremes")
measurements = ddlpy.measurements(selected_ext.iloc[0], start_date, end_date)
# 100%|██████████| 37/37 [00:24<00:00,  1.52it/s]