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

Update bufr.py for carra2 for local observations #35

Merged
merged 7 commits into from
Jan 24, 2024
48 changes: 36 additions & 12 deletions pysurfex/bufr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""bufr treatment."""
import logging
import sys
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not needed?

from math import exp

import numpy as np
Expand Down Expand Up @@ -86,6 +87,7 @@ def __init__(
"heightOfStation",
"stationNumber",
"blockNumber",
"stationOrSiteName",
]
processed_threshold = 0
nerror = {}
Expand Down Expand Up @@ -113,6 +115,10 @@ def __init__(
"/heightOfSensorAboveLocalGroundOrDeckOfMarinePlatform=1.5"
"/dewpointTemperature"
)
keys.append(
"/heightOfSensorAboveLocalGroundOrDeckOfMarinePlatform=2"
"/relativeHumidity"
)
elif var == "airTemperatureAt2M":
keys.append("airTemperatureAt2M")
keys.append(
Expand Down Expand Up @@ -171,7 +177,9 @@ def __init__(
stid = "NA"
station_number = -1
block_number = -1
site_name = "NA"
t2m = np.nan
rh2m = np.nan
td2m = np.nan
s_d = np.nan
temp = np.nan
Expand Down Expand Up @@ -223,6 +231,8 @@ def __init__(
station_number = val
if key == "blockNumber":
block_number = val
if key == "stationOrSiteName":
site_name = val
if key == "airTemperatureAt2M":
t2m = val
if (
Expand All @@ -234,6 +244,12 @@ def __init__(
"/airTemperature"
):
temp = val
if (
key
== "/heightOfSensorAboveLocalGroundOrDeckOfMarinePlatform=2"
"/relativeHumidity"
):
rh2m = val
if key == "dewpointTemperatureAt2M":
td2m = val
if (
Expand Down Expand Up @@ -279,24 +295,29 @@ def __init__(
if not exists:
logging.debug("Pos does not exist %s %s", pos, var)
if var == "relativeHumidityAt2M":
if not np.isnan(t2m) and not np.isnan(td2m):
if not np.isnan(t2m) and not np.isnan(td2m) and np.isnan(rh2m):
try:
value = self.td2rh(td2m, t2m)
value = value * 0.01
value = value * 0.01
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the white-spaces

except Exception:
logging.debug("Got exception for %s:", var)
value = np.nan
elif not np.isnan(temp) and not np.isnan(t_d) and np.isnan(rh2m):
try:
value = self.td2rh(t_d, temp)
value = value * 0.01
except Exception:
logging.debug(
"Got exception for %s",
var,
)
value = np.nan
else:
if not np.isnan(temp) and not np.isnan(t_d):
try:
value = self.td2rh(t_d, temp)
value = value * 0.01
except Exception:
logging.debug(
"Got exception for %s",
var,
)
value = np.nan
value = np.nan

if np.isnan(value) and not np.isnan(rh2m):
value = 0.01 * rh2m

elif var == "airTemperatureAt2M":
if np.isnan(t2m):
if not np.isnan(temp):
Expand Down Expand Up @@ -385,6 +406,9 @@ def __init__(
)
if station_number > 0 and block_number > 0:
stid = str((block_number * 1000) + station_number)
if stid == "NA" and site_name != "NA" and site_name.isnumeric():
stid = site_name

observations.append(
Observation(
obs_dtg,
Expand Down
Loading