Repository: ESMValGroup/ESMValCore

Issue:
Dataset problem: Automatic fixing for errors in AERmon cmor data?
Hello, 
I work with yaml recipes and when 
I run the recipe copied below it terminates with an error for all of the
CMIP6 AERmon datasets listed in the recipe that are:

 - CESM2 pb air_pressure
`- {dataset:   CESM2, grid: gn, institute: NCAR, mip: AERmon,
 ensemble: r1i1p1f1,
 exp: amip, project: CMIP6 , alias: CESM2, start_year: 1979, end_year: 2014}`

- CESM2-WACCM pb air_pressure
 `- {dataset:  CESM2-WACCM , grid: gn, institute: NCAR,mip: AERmon, ensemble: r1i1p1f1,
     exp: amip, project: CMIP6 , alias: CESM2-WACCM, start_year: 1979, end_year: 2014}`

- MPI-ESM-1-2-HAM pb found 2 air pressure
`- {dataset:      MPI-ESM-1-2-HAM, grid: gn,  institute:
HAMMOZ-Consortium, mip: AERmon, ensemble: r1i1p1f1,
   exp: amip, project: CMIP6 , alias: MPI-ESM, start_year: 1979, end_year: 1998}`                                                 

- EC-Earth-Consortium pb found 2 air pressure
 `- {dataset:      EC-Earth3-AerChem, grid: gn,  institute:  EC-Earth-Consortium,  mip: AERmon, ensemble: r1i1p1f1,     exp: amip, project: CMIP6 , alias: EC-Earth,  start_year: 1979, end_year: 1979}`

I have the following questions:

- I guess if there would be ESMValCore "CMOR fixing scripts" for the
  above dataset they would be automatically applyed, or if not what
  are the commands lines in the yml recipe to apply then ? 

- if "CMOR fixing scripts" do not exist already for the above datasets
  , I would be grateful
  for developements so the community can deal with these AERmon
  datasets. For a number of chemical fields, CMIP6 model outputs exist
  only for this AERmon table

All the best,
Martine Michou

```
-----
# ESMValTool
---
documentation:
  title: Ozone test diags
  description: >
    Test recipe for simple ozone diagnostics..
  authors:
    - lauer_axel
  maintainer:
    - lauer_axel

# les années ci dessous sont celles pour la variable oh pas terrible...    
datasets: 
     # CESM2 pb air_pressure
#  - {dataset:   CESM2, grid: gn, institute: NCAR, mip: AERmon,
# ensemble: r1i1p1f1, exp: amip, project: CMIP6 , alias: CESM2, start_year: 1979, end_year: 2014}
# CESM2-WACCM pb air_pressure
#  - {dataset:  CESM2-WACCM , grid: gn, institute: NCAR,mip: AERmon,
# ensemble: r1i1p1f1,   exp: amip, project: CMIP6 , alias: CESM2-WACCM, start_year: 1979, end_year: 2014}
# MPI-ESM-1-2-HAM pb found 2 air pressure
 # - {dataset:      MPI-ESM-1-2-HAM, grid: gn,  institute:
  #  HAMMOZ-Consortium, mip: AERmon, ensemble: r1i1p1f1,   exp: amip, project: CMIP6 , alias: MPI-ESM, start_year: 1979, end_year: 1998}                                                  
 #  EC-Earth-Consortium pb found 2 air pressure
  - {dataset:      EC-Earth3-AerChem, grid: gn,  institute:    EC-Earth-Consortium,  mip: AERmon, ensemble: r1i1p1f1,   exp: amip, project: CMIP6 , alias: EC-Earth,  start_year: 1979, end_year: 1979}


preprocessors:
  pp_timeseries1000:
    custom_order: true  # makes preprocessor much faster since input for extract_levels is smaller
    regrid:
      target_grid: 2x2
      scheme: linear
    extract_levels:
      levels: 100000
      scheme: linear
      coordinate: air_pressure
    extract_region:
      start_latitude: -90
      end_latitude: 90
      start_longitude: 0
      end_longitude: 360      
    area_statistics:
      operator: mean   



diagnostics:

  oh_timeseries1000:
    description: Plot times series oh at 1000 hPA
    variables:
      oh:
        preprocessor: pp_timeseries1000
    scripts:
      plot:
        script: /home/michou/ESMValTool_2.10cnrm/Recipes_tested/From_ALauer/multi_datasets.py
        plot_folder: '{plot_dir}'
        plot_filename: '{plot_type}_{real_name}_{dataset}_{mip}'
        plots:
          timeseries:
            

```

Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/ESMValGroup/ESMValCore/pull/2634?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ESMValGroup) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 94.97%. Comparing base [(`542a374`)](https://app.codecov.io/gh/ESMValGroup/ESMValCore/commit/542a374a0d69843dd0c2ced91581e844977a6692?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ESMValGroup) to head [(`ea8c87b`)](https://app.codecov.io/gh/ESMValGroup/ESMValCore/commit/ea8c87b2537c38e87d0accc2d760c3b16f5f932f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ESMValGroup).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main    #2634   +/-   ##
=======================================
  Coverage   94.96%   94.97%           
=======================================
  Files         253      253           
  Lines       14706    14714    +8     
=======================================
+ Hits        13966    13974    +8     
  Misses        740      740           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/ESMValGroup/ESMValCore/pull/2634?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ESMValGroup).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ESMValGroup).

valeriupredoi: NB Mme Michou's [recipe](https://github.com/ESMValGroup/ESMValCore/issues/2613#issuecomment-2556548372)
 now runs fine :smiley: 
valeriupredoi: thanks a lot, gents! :beers: 

Patch:
diff --git a/esmvalcore/cmor/_fixes/cmip6/ec_earth3_aerchem.py b/esmvalcore/cmor/_fixes/cmip6/ec_earth3_aerchem.py
new file mode 100644
index 000000000..d480bfdf9
--- /dev/null
+++ b/esmvalcore/cmor/_fixes/cmip6/ec_earth3_aerchem.py
@@ -0,0 +1,35 @@
+"""Fixes for EC-Earth3-AerChem model."""
+
+from ..fix import Fix
+
+
+class Oh(Fix):
+    """Fixes for oh."""
+
+    def fix_metadata(self, cubes):
+        """Fix standard name for ps.
+
+        Fix standard_name for Surface Air Pressure (ps).
+        See discussion in
+        https://github.com/ESMValGroup/ESMValCore/issues/2613
+        Cube has two coordinates called air_pressure: an AuxCoord ps
+        and a DerivedCoord that is 4D and derived using formula terms,
+        we are setting the former's standard_name to "surface_air_pressure".
+
+        Parameters
+        ----------
+        cubes : iris.cube.CubeList
+            Input cubes.
+
+        Returns
+        -------
+        iris.cube.CubeList
+        """
+        cube = self.get_cube_from_list(cubes)
+
+        for cube in cubes:
+            for coord in cube.coords():
+                if coord.var_name == "ps":
+                    coord.standard_name = "surface_air_pressure"
+
+        return cubes


Test patch:
diff --git a/tests/integration/cmor/_fixes/cmip6/test_ec_earth3_aerchem.py b/tests/integration/cmor/_fixes/cmip6/test_ec_earth3_aerchem.py
new file mode 100644
index 000000000..c29562ffa
--- /dev/null
+++ b/tests/integration/cmor/_fixes/cmip6/test_ec_earth3_aerchem.py
@@ -0,0 +1,41 @@
+"""Tests for EC-Earth3-AerChem model."""
+
+import iris
+import pytest
+
+from esmvalcore.cmor._fixes.cmip6.ec_earth3_aerchem import Oh
+from esmvalcore.cmor.fix import Fix
+from esmvalcore.cmor.table import get_var_info
+
+
+@pytest.fixture
+def oh_cubes():
+    air_pressure_coord = iris.coords.DimCoord(
+        [1000.09, 600.6, 200.0],
+        bounds=[[1200.00001, 800], [800, 400.8], [400.8, 1.9]],
+        var_name="ps",
+        standard_name="air_pressure",
+        units="pa",
+    )
+    oh_cube = iris.cube.Cube(
+        [0.0, 1.0, 2.0],
+        var_name="oh",
+        dim_coords_and_dims=[(air_pressure_coord, 0)],
+    )
+    return iris.cube.CubeList([oh_cube])
+
+
+def test_get_oh_fix():
+    """Test getting of fix."""
+    fix = Fix.get_fixes("CMIP6", "EC-Earth3-AerChem", "AERmonZ", "oh")
+    assert Oh(None) in fix
+
+
+def test_oh_fix_metadata(oh_cubes):
+    """Test ``fix_metadata`` for ``oh``."""
+    vardef = get_var_info("CMIP6", "AERmonZ", "oh")
+    fix = Oh(vardef)
+    fixed_cubes = fix.fix_metadata(oh_cubes)
+    for coord in fixed_cubes[0].coords():
+        if coord.var_name == "ps":
+            assert coord.standard_name == "surface_air_pressure"