Skip to content

Commit 201972f

Browse files
committed
Convert units in Flexpart-ICON output by 1e-12 as for COSMO and IFS to get [Bq m-3] for concentrations and [Bq m-2] for deposition.
1 parent 114e727 commit 201972f

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.3
1+
1.1.4

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "pyflexplot"
10-
version = "1.1.3"
10+
version = "1.1.4"
1111
description = "PyFlexPlot - Visualize and post-process FLEXPART dispersion simulation results stored in NetCDF format"
1212
readme = "README.md"
1313
keywords = [

src/pyflexplot/input/fix_nc_input.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
class FlexPartDataFixer:
17-
"""Fix issues with wrong units in Flexpart NetCDF output."""
17+
"""Fix issues with FlexPart NetCDF output."""
1818

1919
cosmo_models = [
2020
"COSMO-2",
@@ -36,16 +36,21 @@ def __init__(self, file_reader):
3636
def fix_nc_var_fld(
3737
self, fld: np.ndarray, model: str, var_ncattrs: Mapping[str, Any]
3838
) -> None:
39+
"""Convert wrong or inadequate units in Flexpart NetCDF output variables."""
3940
unit = var_ncattrs["units"]
4041
if model in self.cosmo_models:
41-
if unit in ["ng kg-1", "1e-12 kg m-2"]:
42+
if unit in ["ng kg-1", "1e-12 kg m-2", "1e-12 Bq m-3", "1e-12 Bq m-2"]:
4243
fact = 1.0e-12
4344
else:
45+
msg = f"model {model}: unrecognized unit '{unit}'; skip variable fixes"
46+
log(wrn=msg)
4447
return
4548
elif model in self.ifs_models:
46-
if unit in ["ng m-3", "1e-12 kg m-2"]:
49+
if unit in ["ng m-3", "1e-12 kg m-2", "1e-12 Bq m-3", "1e-12 Bq m-2"]:
4750
fact = 1.0e-12
4851
else:
52+
msg = f"model {model}: unrecognized unit '{unit}'; skip variable fixes"
53+
log(wrn=msg)
4954
return
5055
else:
5156
raise NotImplementedError(f"model '{model}'")
@@ -60,17 +65,16 @@ def fix_meta_data(
6065
integrate: bool,
6166
mdata: Union[MetaData, Sequence[MetaData]],
6267
) -> None:
68+
"""Adapt wrong or inadequate unit strings in Flexpart NetCDF output metadata."""
6369
if isinstance(mdata, Sequence):
6470
for mdata_i in mdata:
6571
self.fix_meta_data(model, plot_variable, integrate, mdata_i)
6672
return
6773
unit = str(mdata.variable.unit)
6874
if model in self.cosmo_models:
69-
if unit == "1e-12 Bq m-3": # Correct, add time unit for integrated values
70-
new_unit = "1e-12 Bq h m-3" if integrate else unit
71-
elif unit == "ng kg-1":
75+
if unit in ["ng kg-1", "1e-12 Bq m-3"]:
7276
new_unit = "Bq h m-3" if integrate else "Bq m-3"
73-
elif unit == "1e-12 kg m-2":
77+
elif unit in ["1e-12 kg m-2", "1e-12 Bq m-2"]:
7478
# new_unit = "Bq h m-2" if integrate else "Bq m-2"
7579
new_unit = "Bq m-2"
7680
# SR_TMP <
@@ -84,13 +88,13 @@ def fix_meta_data(
8488
new_unit = "Bq m-2"
8589
# SR_TMP >
8690
else:
91+
msg = f"model {model}: unrecognized unit '{unit}'; skip meta data fixes"
92+
log(wrn=msg)
8793
return
8894
elif model in self.ifs_models:
89-
if unit == "1e-12 Bq m-3": # Correct, add time unit for integrated values
90-
new_unit = "1e-12 Bq h m-3" if integrate else unit
91-
elif unit == "ng m-3":
95+
if unit in ["ng m-3", "1e-12 Bq m-3"]:
9296
new_unit = "Bq h m-3" if integrate else "Bq m-3"
93-
elif unit == "1e-12 kg m-2":
97+
elif unit in ["1e-12 kg m-2", "1e-12 Bq m-2"]:
9498
# new_unit = "Bq h m-2" if integrate else "Bq m-2"
9599
new_unit = "Bq m-2"
96100
# SR_TMP <
@@ -104,6 +108,8 @@ def fix_meta_data(
104108
new_unit = "Bq m-2"
105109
# SR_TMP >
106110
else:
111+
msg = f"model {model}: unrecognized unit '{unit}'; skip meta data fixes"
112+
log(wrn=msg)
107113
return
108114
else:
109115
raise NotImplementedError(f"model '{model}'")

0 commit comments

Comments
 (0)