Skip to content

Commit

Permalink
Merge pull request #1251 from metno/fix-mda8
Browse files Browse the repository at this point in the history
MDA8 fix
  • Loading branch information
lewisblake authored Jul 9, 2024
2 parents 3b8f12a + 2dad9c7 commit 647669c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
7 changes: 7 additions & 0 deletions pyaerocom/aeroval/experiment_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pyaerocom.aeroval.setupclasses import EvalSetup
from pyaerocom.aeroval.varinfo_web import VarinfoWeb
from pyaerocom.exceptions import EntryNotAvailable, VariableDefinitionError
from pyaerocom.stats.mda8.const import MDA8_INPUT_VARS, MDA8_OUTPUT_VARS
from pyaerocom.stats.stats import _init_stats_dummy
from pyaerocom.variable_helpers import get_aliases

Expand Down Expand Up @@ -698,6 +699,12 @@ def _is_part_of_experiment(self, obs_name, obs_var, mod_name, mod_var) -> bool:
True if this combination is valid, else False.
"""

# MDA8 is computed on-the-fly ONLY if a MDA8_INPUT_VAR at hourly freq is detected.
# Consequently, it is not specified in a config but should be included as part of the experiment.
if obs_var in MDA8_OUTPUT_VARS and mod_var in MDA8_OUTPUT_VARS:
return True

# get model entry for model name
try:
mcfg = self.cfg.model_cfg.get_entry(mod_name)
Expand Down
1 change: 1 addition & 0 deletions pyaerocom/aeroval/glob_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@
vmrso2=["SO2", "3D", "Gas volume mixing ratio"],
concso4=["SO4", "3D", "Particle concentrations"],
vmro3=["O3", "3D", "Volume mixing ratios"],
vmro3mda8=["O3 (MDA8)", "3D", "Valume mixing ratios"],
vmro3max=["O3Max", "3D", "Volume mixing ratios"],
vmrox=["OX", "3D", "Gas volume mixing ratio"],
concco=["CO", "3D", "Particle concentration"],
Expand Down
15 changes: 7 additions & 8 deletions pyaerocom/colocation/colocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from pyaerocom.io import ReadCAMS2_83, ReadGridded, ReadUngridded
from pyaerocom.io.helpers import get_all_supported_ids_ungridded
from pyaerocom.io.mscw_ctm.reader import ReadMscwCtm
from pyaerocom.stats.mda8.const import MDA_VARS
from pyaerocom.stats.mda8.const import MDA8_INPUT_VARS
from pyaerocom.stats.mda8.mda8 import mda8_colocated_data

from .colocated_data import ColocatedData
Expand Down Expand Up @@ -383,17 +383,16 @@ def run(self, var_list: list = None):
) # note this can be ColocatedData or ColocatedDataLists
data_out[mod_var][obs_var] = coldata

if obs_var in MDA_VARS:
mda8 = None
if obs_var in MDA8_INPUT_VARS:
try:
mda8 = mda8_colocated_data(
coldata, obs_var=f"{obs_var}mda8", mod_var=f"{mod_var}mda8"
)
except ValueError:
logger.warning(
"Tried calculating mda8 for [%s, %s], but failed.", obs_var, mod_var
)
finally:
except ValueError as e:
logger.debug(e)
else:
self._save_coldata(mda8)
logger.info("Successfully calculated mda8 for [%s, %s].", obs_var, mod_var)
data_out[f"{mod_var}mda8"][f"{obs_var}mda8"] = mda8

self._processing_status.append([mod_var, obs_var, 1])
Expand Down
4 changes: 4 additions & 0 deletions pyaerocom/data/variables.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3105,6 +3105,10 @@ unit = ug m-3
description=Mass concentration of ozone
unit = ug m-3

[vmro3mda8]
description=MDA8 of O3 VMR.
unit = nmol mol-1

[concco]
description=Mass concentration of organic carbon
unit = ug m-3
Expand Down
3 changes: 2 additions & 1 deletion pyaerocom/stats/mda8/const.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Variable names for which mda8 values are to be calculated.
MDA_VARS = ("conco3", "vmro3")
MDA8_INPUT_VARS = ("conco3", "vmro3")
MDA8_OUTPUT_VARS = ("vmro3mda8",)
5 changes: 5 additions & 0 deletions pyaerocom/stats/mda8/mda8.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import logging

import numpy as np
import xarray as xr

from pyaerocom.colocation.colocated_data import ColocatedData

logger = logging.getLogger(__name__)


def min_periods_max(x: np.ndarray, /, min_periods=1) -> float:
"""Calculates the max of a 1-dimensional array, returning
Expand Down Expand Up @@ -44,6 +48,7 @@ def mda8_colocated_data(coldat: ColocatedData, /, obs_var: str, mod_var: str) ->

cd = ColocatedData(_calc_mda8(coldat.data))
cd.data.attrs["var_name"] = [obs_var, mod_var]
cd.metadata["var_name_input"] = [obs_var, mod_var]
return cd


Expand Down

0 comments on commit 647669c

Please sign in to comment.