Skip to content

Commit 8af46d4

Browse files
authored
Ensure lat/lon bounds in FGOALS-l3 atmos variables are contiguous (#1571)
* Add tas ecearth fix * Remove uneeded fix * Add fix for non contiguous bounds * Add test * Expand test * Define wrong bounds as noncontiguous but monotic * Revert "Add tas ecearth fix" This reverts commit e8ae0ba. * Fix flake * Add check before guessing bounds
1 parent 3c556a8 commit 8af46d4

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

esmvalcore/cmor/_fixes/cmip6/fgoals_f3_l.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def fix_metadata(self, cubes):
3232
"""
3333
for cube in cubes:
3434
if cube.attributes['table_id'] == 'Amon':
35+
for coord in ['latitude', 'longitude']:
36+
cube_coord = cube.coord(coord)
37+
bounds = cube_coord.bounds
38+
if np.any(bounds[:-1, 1] != bounds[1:, 0]):
39+
cube_coord.bounds = None
40+
cube_coord.guess_bounds()
3541
time = cube.coord('time')
3642
if np.any(time.bounds[:-1, 1] != time.bounds[1:, 0]):
3743
times = time.units.num2date(time.points)

tests/integration/cmor/_fixes/cmip6/test_fgoals_f3_l.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for the fixes of FGOALS-f3-L."""
22

3+
import numpy as np
34
import iris
45
import pytest
56
from cf_units import Unit
@@ -24,15 +25,48 @@ def cubes():
2425
standard_name='time',
2526
units=Unit('days since 0001-01-01 00:00:00', calendar='365_day'))
2627

27-
correct_cube = iris.cube.Cube([10., 10., 10.],
28+
correct_lat_coord = iris.coords.DimCoord(
29+
[0.0, 1.0],
30+
bounds=[[-0.5, 0.5], [0.5, 1.5]],
31+
var_name='lat',
32+
standard_name='latitude',
33+
units='degrees')
34+
35+
wrong_lat_coord = iris.coords.DimCoord(
36+
[0.0, 1.0],
37+
bounds=[[-0.5, 0.5], [1.5, 2.]],
38+
var_name='lat',
39+
standard_name='latitude',
40+
units='degrees')
41+
42+
correct_lon_coord = iris.coords.DimCoord(
43+
[0.0, 1.0],
44+
bounds=[[-0.5, 0.5], [0.5, 1.5]],
45+
var_name='lon',
46+
standard_name='longitude',
47+
units='degrees')
48+
49+
wrong_lon_coord = iris.coords.DimCoord(
50+
[0.0, 1.0],
51+
bounds=[[-0.5, 0.5], [1.5, 2.]],
52+
var_name='lon',
53+
standard_name='longitude',
54+
units='degrees')
55+
56+
correct_cube = iris.cube.Cube(10 * np.ones((3, 2, 2)),
2857
var_name='tas',
29-
dim_coords_and_dims=[(correct_time_coord, 0)
58+
dim_coords_and_dims=[(correct_time_coord, 0),
59+
(correct_lat_coord, 1),
60+
(correct_lon_coord, 2)
3061
],
3162
attributes={'table_id': 'Amon'},
3263
units=Unit('degC'))
33-
wrong_cube = iris.cube.Cube([10., 10., 10.],
64+
65+
wrong_cube = iris.cube.Cube(10 * np.ones((3, 2, 2)),
3466
var_name='tas',
35-
dim_coords_and_dims=[(wrong_time_coord, 0)],
67+
dim_coords_and_dims=[(wrong_time_coord, 0),
68+
(wrong_lat_coord, 1),
69+
(wrong_lon_coord, 2)],
3670
attributes={'table_id': 'Amon'},
3771
units=Unit('degC'))
3872

@@ -50,7 +84,11 @@ def test_allvars_fix_metadata(cubes):
5084
assert cubes is out_cubes
5185
for cube in out_cubes:
5286
time = cube.coord('time')
87+
lat = cube.coord('latitude')
88+
lon = cube.coord('longitude')
5389
assert all(time.bounds[1:, 0] == time.bounds[:-1, 1])
90+
assert all(lat.bounds[1:, 0] == lat.bounds[:-1, 1])
91+
assert all(lon.bounds[1:, 0] == lon.bounds[:-1, 1])
5492

5593

5694
def test_tos_fix():

0 commit comments

Comments
 (0)