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

Support Quality Controlled Rain Gauge Data from KNMI Data Platform #203

Open
martinvonk opened this issue Apr 2, 2024 · 0 comments
Open
Assignees

Comments

@martinvonk
Copy link
Collaborator

martinvonk commented Apr 2, 2024

KNMI Data Platform provides Quality Controlled Rain Gauge Data.

We can read KNMI Data Platform with NLMOD and the Quality Controlled Rain Gauge Data with the FEWS reader in HydroPandas. I am not suggesting that we include this per se. But it could be a nice addition to the existing KNMI data. I could not find any metadata on the stations locations so that is a problem if we don't know the locations beforehand..

Example Script:

# %%
import nlmod
import nlmod.read.knmi_data_platform as kdp
import pandas as pd
from xml.etree import ElementTree as ET
from pathlib import Path
nlmod.util.get_color_logger("INFO")
import pastastore as pst
import matplotlib.pyplot as plt


#%%
dataset_names = [
    "watercompany_raingauge_quality_controlled_waternet",
    "watercompany_raingauge_quality_controlled_pwn",
    "waterboard_raingauge_quality_controlled_rijnland",
    "waterboard_raingauge_quality_controlled_noorderzijlvest",
    "waterboard_raingauge_quality_controlled_limburg",
    "waterboard_raingauge_quality_controlled_hhnk",
    "waterboard_raingauge_quality_controlled_delfland",
    "waterboard_raingauge_quality_controlled_dommel",
    "waterboard_raingauge_quality_controlled_hunzeenaas",
    "waterboard_raingauge_quality_controlled_aaenmaas",
    "waterboard_raingauge_quality_controlled_hdsr"
]

dataset_name_all = "waterboard_raingauge_quality_controlled_all_combined"

# %%
dataset_name = dataset_name_all
dataset_version = "1.0"
files = kdp.get_list_of_files(
    dataset_name=dataset_name,
    dataset_version=dataset_version,
)

# %%
kdp.download_files(
    dataset_name=dataset_name,
    dataset_version=dataset_version,
    fnames=files[-1:],
    dirname=dataset_name,
    api_key=own_api_key
)

#%%
dfiles = list(Path(dataset_name).glob("*.xml"))
tree = ET.parse(dfiles[0])
root = tree.getroot()

obsd = {}
for item in root:
    if item.tag.endswith("series"):
        header = {}
        date = []
        time = []
        events = []
        for subitem in item:
            if subitem.tag.endswith("header"):
                for subsubitem in subitem:
                    prop = subsubitem.tag.split("}")[-1]
                    val = subsubitem.text
                    if prop == "x" or prop == "y" or prop == "lat" or prop == "lon":
                        val = float(val)
                    header[prop] = val
            elif subitem.tag.endswith("event"):
                date.append(subitem.attrib.pop("date"))
                time.append(subitem.attrib.pop("time"))
                events.append({**subitem.attrib})
        index = pd.to_datetime(
            [d + " " + t for d, t in zip(date, time)], errors="coerce"
        )
        ts = pd.DataFrame(events, index=index)
    obsd[header["locationId"]] = {"header": header, "series": ts}
@martinvonk martinvonk changed the title Quality Controlled Rain Gauge Data from KNMI Data Platform Support Quality Controlled Rain Gauge Data from KNMI Data Platform Apr 2, 2024
@martinvonk martinvonk self-assigned this Apr 12, 2024
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

No branches or pull requests

1 participant