You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When retrieving data for a station/period where no data is present, ddlpy loops over all months which can be avoided by using the CheckWaarnemingenAanwezig waterwebservice.
What I Did
importdatetimeasdtimportddlpylocations=ddlpy.locations()
bool_stations=locations.index.isin(['OTDM'])
bool_grootheid=locations['Grootheid.Code'].isin(['WATHTE'])
selected=locations.loc[bool_stations&bool_grootheid]
# numtiple parameters avaialble per locationrecords=selected.iloc[0]
# if we pass one row to the measurements function you can get all the measurementsmeasurements=ddlpy.measurements(records, dt.datetime(2019,1,1), dt.datetime(2020,1,1))
print(len(measurements)==0)
The above code returns an empty list since there was no data. However, all 12 months were checked first. Make this more efficient by adding a check for data availability like so:
importrequests# check of er waarnemingen zijn, snelle manier voor gehele periodeurl_ddl='https://waterwebservices.rijkswaterstaat.nl/ONLINEWAARNEMINGENSERVICES_DBO/CheckWaarnemingenAanwezig'request_ddl= {"AquoMetadataLijst" :
[{"Compartiment":{"Code":"OW"},"Eenheid":{"Code":"cm"}}],
# "Groeperingsperiode" : "Week","LocatieLijst" : [{"X" :518882.333320247,"Y" :5760829.11729589,"Code":"EURPFM"}],
"Periode" : {"Begindatumtijd" : "2012-01-16T14:00:00.000+01:00","Einddatumtijd": "2012-01-16T16:00:00.000+01:00"
}
}
resp=requests.post(url_ddl, json=request_ddl)
ifnotresp.ok:
raiseException('%s for %s: %s'%(resp.reason, resp.url, str(resp.text)))
result=resp.json()
ifnotresult['Succesvol']:
raiseException('query not succesful, Foutmelding: %s from %s'%(result['Foutmelding'],url_ddl))
print(result['WaarnemingenAanwezig'])
Additional info
Also consider preventing empty list as returned object, instead return empty dataframe or maybe None?
The text was updated successfully, but these errors were encountered:
Description
When retrieving data for a station/period where no data is present, ddlpy loops over all months which can be avoided by using the
CheckWaarnemingenAanwezig
waterwebservice.What I Did
The above code returns an empty list since there was no data. However, all 12 months were checked first. Make this more efficient by adding a check for data availability like so:
Additional info
Also consider preventing empty list as returned object, instead return empty dataframe or maybe None?
The text was updated successfully, but these errors were encountered: