Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ profile = "black"

[tool.pylint.BASIC]
good-names = "log"
max-branches=25

[tool.pylint.MASTER]
disable = [
Expand Down
45 changes: 40 additions & 5 deletions src/openradardata_validator/odim2ordmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import numpy
import pandas as pd

from openradardata_validator.radar_cf import radar_cf
from openradardata_validator.radar_cf import (
country_naming_auth,
odim_acdd_attrs,
radar_cf,
)

current_filedir = Path(__file__).parent.resolve()

Expand Down Expand Up @@ -72,7 +76,7 @@ def find_source_type(source: str, sid: str) -> str:
return ret


def odim_datetime(odate: bytes, otime: bytes) -> datetime:
def odim_datetime(odate: bytes | str, otime: bytes | str) -> datetime:
if isinstance(odate, bytes):
odate = odate.decode("utf-8")
if isinstance(otime, bytes):
Expand Down Expand Up @@ -108,6 +112,7 @@ def parse_odim_source(odim: h5py.File, def_msg: dict[str, Any]) -> None:
wmo = find_source_type(source, "WMO")
nod = find_source_type(source, "NOD")
org = find_source_type(source, "ORG")
cty = find_source_type(source, "CTY")
station = find_source_type(source, "PLC")

if wigos:
Expand All @@ -123,15 +128,38 @@ def parse_odim_source(odim: h5py.File, def_msg: dict[str, Any]) -> None:
def_msg["properties"]["platform"] = "0-20010-0-" + "OPERA"
def_msg["properties"]["platform_name"] = "OPERA"

if "how" in odim:
for attr in odim_acdd_attrs:
od_attr = get_attr_str(odim["how"], attr)
if od_attr:
def_msg["properties"][attr] = od_attr

if nod:
if station:
def_msg["properties"]["platform_name"] = "[" + nod + "]" + " " + station
else:
def_msg["properties"]["platform_name"] = "[" + nod + "]"

cc = str(nod)[:2].lower()
if def_msg["properties"]["naming_authority"] == "eu.eumetnet":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that if the naming authority is already given in the message template, we don't change it? Or why is this if clause here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is a national product and the naming_authority is the default("eu.eumentnet"), the ingester updates naming_authority by country_naming_auth . Ingester skips this block when naming_authority was filled by NMS.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a single site case, I added the composite case also, see: 1a94444

if cc.lower() in country_naming_auth:
def_msg["properties"]["naming_authority"] = country_naming_auth[cc][
"naming_authority"
]
else:
def_msg["properties"]["naming_authority"] = cc
else:
if org == "247":
def_msg["properties"]["period_int"] = 300
def_msg["properties"]["period"] = "PT300S"
else:
if def_msg["properties"]["naming_authority"] == "eu.eumetnet":
for cc, country in country_naming_auth.items():
if int(org) in country["org"] or country["cty"] == int(cty): # type: ignore
def_msg["properties"]["naming_authority"] = country[
"naming_authority"
]
break


def parse_odim_object(odim: h5py.File, def_msg: dict[str, Any]) -> None:
Expand Down Expand Up @@ -255,7 +283,10 @@ def parse_odim_dataset_what(
)
td = et - st
period_int = int(td.total_seconds())
if "start_datetime" in dataset_msg["properties"] and "end_datetime" in dataset_msg["properties"]:
if (
"start_datetime" in dataset_msg["properties"]
and "end_datetime" in dataset_msg["properties"]
):
# If start_datetime and end_datetime in schema, use them
dataset_msg["properties"]["start_datetime"] = st.isoformat() + "Z"
dataset_msg["properties"]["end_datetime"] = et.isoformat() + "Z"
Expand Down Expand Up @@ -334,9 +365,13 @@ def parse_odim_dataset(
if f"{dataset_key}/what" in odim:
level = parse_odim_dataset_what(odim, dataset_msg, dataset_key, level)
elif f"{dataset_key}/data1/what" in odim:
level = parse_odim_dataset_what(odim, dataset_msg, dataset_key + "/data1", level)
level = parse_odim_dataset_what(
odim, dataset_msg, dataset_key + "/data1", level
)
else:
raise ValueError(f"ODIM dataset what group missing in {dataset_key} and {dataset_key}/data1")
raise ValueError(
f"ODIM dataset what group missing in {dataset_key} and {dataset_key}/data1"
)
dataset_msg["properties"]["level"] = level

data_index = 1
Expand Down
227 changes: 128 additions & 99 deletions src/openradardata_validator/radar_cf.py
Original file line number Diff line number Diff line change
@@ -1,99 +1,128 @@
radar_cf = {}
radar_cf["TH"] = "radar_linear_equivalent_reflectivity_factor_h"
radar_cf["TV"] = "radar_linear_equivalent_reflectivity_factor_v"
radar_cf["DBZH"] = "radar_equivalent_reflectivity_factor_h"
radar_cf["DBZV"] = "radar_equivalent_reflectivity_factor_v"
# ODIM deprecated
radar_cf["DBZ"] = "radar_equivalent_reflectivity_factor_h"

radar_cf["ZDR"] = "radar_differential_reflectivity_hv"
radar_cf["UZDR"] = "UZDR"
# ODIM deprecated
radar_cf["LZDR"] = "radar_differential_reflectivity_hv"

radar_cf["RHOHV"] = "radar_correlation_coefficient_hv"

radar_cf["URHOHV"] = ""

radar_cf["LDR"] = "radar_linear_depolarization_ratio"
radar_cf["ULDR"] = "ULDR"

radar_cf["PHIDP"] = "radar_differential_phase_hv"
radar_cf["UPHIDP"] = "UPHIDP"

radar_cf["PIA"] = "PIA"
radar_cf["KDP"] = "radar_specific_differential_phase_hv"
radar_cf["UKDP"] = "UKDP"

radar_cf["SQIH"] = "SQIH"
radar_cf["USQIH"] = "USQIH"
radar_cf["SQIV"] = "SQIV"
radar_cf["USQIV"] = "USQIV"
# ODIM deprecated
radar_cf["SQI"] = "SQI"

radar_cf["SNR"] = "radar_signal_to_noise_ratio"
radar_cf["SNRHC"] = "radar_signal_to_noise_ratio_copolar_h"
radar_cf["SNRHX"] = "radar_signal_to_noise_ratio_crosspolar_h"
radar_cf["SNRVC"] = "radar_signal_to_noise_ratio_copolar_v"
radar_cf["SNRVX"] = "radar_signal_to_noise_ratio_crosspolar_v"
radar_cf["USNRHC"] = "USNRHC"
radar_cf["USNRVC"] = "USNRVC"

radar_cf["CCORH"] = "CCOR_h"
radar_cf["CCORV"] = "CCOR_v"

radar_cf["CPA"] = "CPA"

radar_cf["RATE"] = "radar_estimated_precipitation_rate"
radar_cf["URATE"] = "URATE"

radar_cf["POR"] = "POR"
radar_cf["HI"] = "HI"
radar_cf["POH"] = "POH"
radar_cf["POSH"] = "POSH"

radar_cf["MESH"] = "MESH"

radar_cf["ACRR"] = "ACRR"
radar_cf["HGHT"] = "HGHT"
radar_cf["VIL"] = "VIL"

radar_cf["VRADH"] = "radial_velocity_of_scatterers_away_from_instrument_h"
radar_cf["UVRADH"] = "UVRADH"
radar_cf["VRADV"] = "radial_velocity_of_scatterers_away_from_instrument_v"
radar_cf["UVRADV"] = "UVRADV"
# ODIM deprecated
radar_cf["VRAD"] = "radial_velocity_of_scatterers_away_from_instrument_h"

radar_cf["VRADDH"] = "VRADDH"
radar_cf["VRADDV"] = "VRADDV"

radar_cf["WRADH"] = "radar_doppler_spectrum_width_h"
radar_cf["UWRADH"] = "UWRADH"
radar_cf["WRADV"] = "radar_doppler_spectrum_width_v"
radar_cf["UWRADV"] = "UWRADV"
# ODIM deprecated
radar_cf["WRAD"] = "radar_doppler_spectrum_width_h"

radar_cf["UWND"] = "UWND"
radar_cf["VWND"] = "VWND"

radar_cf["RSHR"] = "RSHR"
radar_cf["ASHR"] = "ASHR"
radar_cf["CSHR"] = "CSHR"
radar_cf["ESHR"] = "ESHR"
radar_cf["OSHR"] = "OSHR"
radar_cf["HSHR"] = "HSHR"
radar_cf["VSHR"] = "VSHR"
radar_cf["TSHR"] = "TSHR"
radar_cf["PSH"] = "PSH"
radar_cf["PSV"] = "PSV"

radar_cf["UPSPH"] = "UPSPH"
radar_cf["UPSPV"] = "UPSPV"

radar_cf["BRDR"] = "BRDR"
radar_cf["QIND"] = "QIND"

radar_cf["CLASS"] = "CLASS"
radar_cf = {
"ACRR": "ACRR",
"ASHR": "ASHR",
"BRDR": "BRDR",
"CCORH": "CCOR_h",
"CCORV": "CCOR_v",
"CLASS": "CLASS",
"CPA": "CPA",
"CSHR": "CSHR",
"DBZ": "radar_equivalent_reflectivity_factor_h",
"DBZH": "radar_equivalent_reflectivity_factor_h",
"DBZV": "radar_equivalent_reflectivity_factor_v",
"ESHR": "ESHR",
"HGHT": "HGHT",
"HI": "HI",
"HSHR": "HSHR",
"KDP": "radar_specific_differential_phase_hv",
"LDR": "radar_linear_depolarization_ratio",
"LZDR": "radar_differential_reflectivity_hv",
"MESH": "MESH",
"OSHR": "OSHR",
"PHIDP": "radar_differential_phase_hv",
"PIA": "PIA",
"POH": "POH",
"POR": "POR",
"POSH": "POSH",
"PSH": "PSH",
"PSV": "PSV",
"QIND": "QIND",
"RATE": "radar_estimated_precipitation_rate",
"RHOHV": "radar_correlation_coefficient_hv",
"RSHR": "RSHR",
"SNR": "radar_signal_to_noise_ratio",
"SNRHC": "radar_signal_to_noise_ratio_copolar_h",
"SNRHX": "radar_signal_to_noise_ratio_crosspolar_h",
"SNRVC": "radar_signal_to_noise_ratio_copolar_v",
"SNRVX": "radar_signal_to_noise_ratio_crosspolar_v",
"SQI": "SQI",
"SQIH": "SQIH",
"SQIV": "SQIV",
"TH": "radar_linear_equivalent_reflectivity_factor_h",
"TSHR": "TSHR",
"TV": "radar_linear_equivalent_reflectivity_factor_v",
"UKDP": "UKDP",
"ULDR": "ULDR",
"UPHIDP": "UPHIDP",
"UPSPH": "UPSPH",
"UPSPV": "UPSPV",
"URATE": "URATE",
"URHOHV": "URHOHV",
"USNRHC": "USNRHC",
"USNRVC": "USNRVC",
"USQIH": "USQIH",
"USQIV": "USQIV",
"UVRADH": "UVRADH",
"UVRADV": "UVRADV",
"UWND": "UWND",
"UWRADH": "UWRADH",
"UWRADV": "UWRADV",
"UZDR": "UZDR",
"VIL": "VIL",
"VRAD": "radial_velocity_of_scatterers_away_from_instrument_h",
"VRADDH": "VRADDH",
"VRADDV": "VRADDV",
"VRADH": "radial_velocity_of_scatterers_away_from_instrument_h",
"VRADV": "radial_velocity_of_scatterers_away_from_instrument_v",
"VSHR": "VSHR",
"VWND": "VWND",
"WRAD": "radar_doppler_spectrum_width_h",
"WRADH": "radar_doppler_spectrum_width_h",
"WRADV": "radar_doppler_spectrum_width_v",
"ZDR": "radar_differential_reflectivity_hv",
}

odim_acdd_attrs = [
"license",
"naming_authority",
"institution",
"creator_name",
"creator_email",
"creator_url",
"publisher_name",
"publisher_email",
"publisher_url",
"creator_type",
"creator_institution",
"publisher_type",
"publisher_institution",
]

country_naming_auth = {
"at": {"naming_authority": "at.austrocontrol", "org": [224], "cty": 602, "cc": 40},
"be": {"naming_authority": "be.meteo", "org": [227], "cty": 605, "cc": 56},
"ch": {"naming_authority": "ch.meteoswiss", "org": [215], "cty": 644, "cc": 756},
"cy": {"naming_authority": "cy.gov.moa.dom", "org": [230], "cty": 609, "cc": 196},
"cz": {"naming_authority": "cz.chmi", "org": [89], "cty": 610, "cc": 203},
"de": {"naming_authority": "de.dwd", "org": [78, 79], "cty": 616, "cc": 276},
"dk": {"naming_authority": "dk.dmi", "org": [94], "cty": 611, "cc": 208},
"ee": {"naming_authority": "ee.envir", "org": [231], "cty": 612, "cc": 233},
"es": {"naming_authority": "es.aemet", "org": [214], "cty": 642, "cc": 724},
"fi": {"naming_authority": "fi.fmi", "org": [86], "cty": 613, "cc": 246},
"fr": {"naming_authority": "fr.meteo", "org": [84, 85], "cty": 614, "cc": 250},
"gr": {"naming_authority": "gr.hnms", "org": [96], "cty": 617, "cc": 300},
"hr": {"naming_authority": "hr.dhz.cirus", "org": [221], "cty": 608, "cc": 191},
"hu": {"naming_authority": "hu.met", "org": [218], "cty": 618, "cc": 348},
"ie": {"naming_authority": "ie.met", "org": [233], "cty": 620, "cc": 372},
"il": {"naming_authority": "il.gov.ims", "org": [234], "cty": 621, "cc": 376},
"is": {"naming_authority": "is.vedur", "org": [213], "cty": 619, "cc": 352},
"lt": {"naming_authority": "lt.meteo", "org": [238], "cty": 627, "cc": 440},
"lv": {"naming_authority": "lv.lvgmc", "org": [236], "cty": 625, "cc": 428},
"md": {"naming_authority": "md.gov.meteo", "org": [246], "cty": 0, "cc": 498},
"mt": {"naming_authority": "mt", "org": [240], "cty": 629, "cc": 470},
"nl": {"naming_authority": "nl.knmi", "org": [99], "cty": 632, "cc": 528},
"no": {"naming_authority": "no.met", "org": [88], "cty": 633, "cc": 578},
"pl": {"naming_authority": "pl.imgw", "org": [220], "cty": 634, "cc": 616},
"pt": {"naming_authority": "pt.ipma", "org": [212], "cty": 635, "cc": 620},
"ro": {"naming_authority": "ro.meteoromania", "org": [242], "cty": 637, "cc": 642},
"rs": {"naming_authority": "rs.gov.hidmet", "org": [87], "cty": 639, "cc": 688},
"se": {"naming_authority": "se.smhi", "org": [82, 83], "cty": 643, "cc": 752},
"si": {"naming_authority": "si.gov", "org": [219], "cty": 641, "cc": 705},
"sk": {"naming_authority": "sk.shmu", "org": [217], "cty": 640, "cc": 703},
"uk": {
"naming_authority": "uk.gov.metoffice",
"org": [74, 75],
"cty": 649,
"cc": 826,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"content": {
"encoding": "utf-8",
"standard_name": "",
"unit": "text",
"unit": "%",
"size": 1,
"value": "0"
}
Expand Down
5 changes: 2 additions & 3 deletions src/openradardata_validator/schemas/openradardata-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,15 @@
},
"if": {"properties": {"object": {"const": "COMP"}}},
"then": {"required": ["LL_lat", "LL_lon", "UL_lat", "UL_lon", "UR_lat", "UR_lon", "LR_lat", "LR_lon"]},
"oneOf": [
"anyOf": [
{
"required": [
"object"
]
},
{
"required": [
"profuct"
"product"
]
}
]
Expand Down Expand Up @@ -763,7 +763,6 @@
},
"required": [
"level",
"period",
"function",
"naming_authority",
"Conventions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"content": {
"encoding": "utf-8",
"standard_name": "DBZH",
"unit": "text",
"unit": "%",
"size": 1,
"value": "0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"content": {
"encoding": "utf-8",
"standard_name": "RATE",
"unit": "text",
"unit": "%",
"size": 1,
"value": "0"
},
Expand Down
Loading