Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check for nodata for entire period instead of retrieving all periods #26

Closed
veenstrajelmer opened this issue Mar 1, 2024 · 0 comments · Fixed by #33
Closed

add check for nodata for entire period instead of retrieving all periods #26

veenstrajelmer opened this issue Mar 1, 2024 · 0 comments · Fixed by #33

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Mar 1, 2024

  • ddlpy version: master
  • Python version: 3.11
  • Operating System: Windows

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

import datetime as dt
import ddlpy

locations = 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 location
records = selected.iloc[0]

# if we pass one row to the measurements function you can get all the measurements
measurements = 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:

import requests

# check of er waarnemingen zijn, snelle manier voor gehele periode
url_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)
if not resp.ok:
    raise Exception('%s for %s: %s'%(resp.reason, resp.url, str(resp.text)))
result = resp.json()
if not result['Succesvol']:
    raise Exception('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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant