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 function for number of measurements per year/day #36

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

add function for number of measurements per year/day #36

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

Comments

@veenstrajelmer
Copy link
Collaborator

veenstrajelmer commented Mar 1, 2024

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

Description

Follow up from #34. The option to retrieve the number of measurements per year from the webwaterservices is not exposed in ddlpy. Alternative example for hoekvhld large data gaps example code in Deltares-research/kenmerkendewaarden#4

What I Did

import requests
import pandas as pd
import datetime as dt
import pytz

dtstart = dt.datetime.now()

# get number of waarnemingen
# TODO: takes long for long timeseries
url_ddl = 'https://waterwebservices.rijkswaterstaat.nl/ONLINEWAARNEMINGENSERVICES_DBO/OphalenAantalWaarnemingen'
request_ddl = {"AquoMetadataLijst" :
               [{"Compartiment":{"Code":"OW"},"Eenheid":{"Code":"cm"},
                 "Grootheid":{"Code":"WATHTE"},
                 "Hoedanigheid":{"Code":"NAP"},
                 "Groepering":{"Code":"NVT"},
                 }],
                "Groeperingsperiode" : "Dag",
               "LocatieLijst" : [{"X" :518882.333320247,"Y" :5760829.11729589,"Code":"EURPFM"}],
               # "Periode" : {"Begindatumtijd" : "1912-01-16T14:00:00.000+01:00","Einddatumtijd": "2024-01-16T16:00:00.000+01:00"}
               "Periode" : {"Begindatumtijd" : pytz.UTC.localize(dt.datetime(1900,1,1)).isoformat(timespec="milliseconds"),
                            "Einddatumtijd": pytz.UTC.localize(dt.datetime.now()).isoformat(timespec="milliseconds")}
               }
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))
for one in result['AantalWaarnemingenPerPeriodeLijst']:
    print(one['AquoMetadata']['Grootheid'])
    print(one['AquoMetadata']['Hoedanigheid'])
    print(one['AquoMetadata']['Groepering'])
    # print(one['AantalMetingenPerPeriodeLijst'])
    df = pd.json_normalize(one['AantalMetingenPerPeriodeLijst'])
    print(df)
print(f'retrieving took: {(dt.datetime.now()-dtstart).total_seconds():.2f} sec')

date_min = dt.datetime(df.iloc[0]["Groeperingsperiode.Jaarnummer"],
                       df.iloc[0]["Groeperingsperiode.Maandnummer"],
                       df.iloc[0]["Groeperingsperiode.Dag"])
@veenstrajelmer veenstrajelmer changed the title add function for number of measurements per year add function for number of measurements per year/day Mar 4, 2024
@veenstrajelmer veenstrajelmer linked a pull request Mar 11, 2024 that will close this issue
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