Skip to content

Commit

Permalink
moved ddl example script to ddlpy (#202)
Browse files Browse the repository at this point in the history
* moved ddl example script to ddlpy

* updated whatsnew

* moved ddlpy_to_hatyan() to getonlinedata.py
  • Loading branch information
veenstrajelmer authored Mar 1, 2024
1 parent 33262c5 commit 528c635
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 154 deletions.
2 changes: 2 additions & 0 deletions docs/whats-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- added metadata to timeseries and components and passing it between those objects in the hatyan process by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#131](https://github.com/Deltares/hatyan/pull/131)
- improved metadata in component files by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#131](https://github.com/Deltares/hatyan/pull/131)
- replaced `times_ext` `timestep_min` and `times_pred_all` for `prediction()` with `times` argument by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#131](https://github.com/Deltares/hatyan/pull/143)
- integrated ddlpy to in ddl example script by [@veenstrajelmer](https://github.com/veenstrajelmer) in [#202](https://github.com/Deltares/hatyan/pull/202)


## 2.7.0 (2023-08-03)

Expand Down
32 changes: 32 additions & 0 deletions hatyan/getonlinedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,38 @@ def get_DDL_stationmetasubset(catalog_dict, station_dict=None, meta_dict=None, e
return cat_aquometadatalijst_sel, cat_locatielijst_sel


def ddlpy_to_hatyan(ddlpy_meas):
cols_mustbe_unique = ['Grootheid.Code','Groepering.Code','Typering.Code','Hoedanigheid.Code']
for col in cols_mustbe_unique:
if len(ddlpy_meas[col].drop_duplicates()) != 1:
raise Exception(f"ddlpy_meas['{col}'] is not unique")

import pandas as pd
if 'Meetwaarde.Waarde_Numeriek' in ddlpy_meas.columns:
key_numericvalues = 'Meetwaarde.Waarde_Numeriek'
isnumeric = True
else:
#alfanumeric values for 'Typering.Code':'GETETTPE' #DDL IMPROVEMENT: also include numeric values for getijtype. Also, it is quite complex to get this data in the first place, would be convenient if it would be a column when retrieving 'Groepering.Code':'GETETM2' or 'GETETBRKD2'
key_numericvalues = 'Meetwaarde.Waarde_Alfanumeriek'
isnumeric = False
ts_pd = pd.DataFrame({'values':ddlpy_meas[key_numericvalues].values,
'QC':pd.to_numeric(ddlpy_meas['WaarnemingMetadata.KwaliteitswaardecodeLijst'].str[0],downcast='integer').values, # DDL IMPROVEMENT: should be possible with .astype(int), but pd.to_numeric() is necessary for HARVT10 (eg 2019-09-01 to 2019-11-01) since QC contains None values that cannot be ints (in that case array of floats with some nans is returned) >> replace None with int code
'Status':ddlpy_meas['WaarnemingMetadata.StatuswaardeLijst'].str[0].values,
#'Bemonsteringshoogte':measurements_wathte['WaarnemingMetadata.BemonsteringshoogteLijst'].str[0].astype(int).values,
#'Referentievlak':measurements_wathte['WaarnemingMetadata.ReferentievlakLijst'].str[0].values,
#'OpdrachtgevendeInstantie':measurements_wathte['WaarnemingMetadata.OpdrachtgevendeInstantieLijst'].str[0].values,
},
index=pd.to_datetime(ddlpy_meas['Tijdstip']))

if isnumeric:
ts_pd['values'] /= 100 #convert from cm to m

# sort on time values # TODO: do this in ddlpy or in ddl
ts_pd = ts_pd.sort_index()

return ts_pd


def convert_HWLWstr2num(ts_measwlHWLW,ts_measwlHWLWtype):
"""
TVL;1;1;hoogwater
Expand Down
Loading

0 comments on commit 528c635

Please sign in to comment.