1
1
"""Test MIROC-ESM fixes."""
2
2
import unittest
3
3
4
+ import numpy as np
4
5
from cf_units import Unit
5
6
from iris .coords import DimCoord
6
7
from iris .cube import Cube
@@ -79,6 +80,22 @@ def setUp(self):
79
80
calendar = 'gregorian' )), 0 )
80
81
self .cube .add_dim_coord (DimCoord ([0 , 1 ], long_name = 'AR5PL35' ), 1 )
81
82
83
+ time_units = Unit ('days since 1950-1-1 00:00:00' , calendar = 'gregorian' )
84
+
85
+ # Setup wrong time coordinate that is present in some files
86
+ # (-711860.5 days from 1950-01-01 is < year 1)
87
+ time_coord = DimCoord (
88
+ [- 711845.0 , - 711814.0 ],
89
+ bounds = [[- 711860.5 , - 711829.5 ], [- 711829.5 , - 711800.0 ]],
90
+ var_name = 'time' ,
91
+ standard_name = 'time' ,
92
+ long_name = 'time' ,
93
+ units = time_units ,
94
+ )
95
+ self .cube_with_wrong_time = Cube ([0.0 , 1.0 ], var_name = 'co2' ,
96
+ units = 'ppm' ,
97
+ dim_coords_and_dims = [(time_coord , 0 )])
98
+
82
99
self .fix = AllVars (None )
83
100
84
101
def test_get (self ):
@@ -100,3 +117,27 @@ def test_fix_metadata_no_plev(self):
100
117
cube = self .fix .fix_metadata ([self .cube ])[0 ]
101
118
with self .assertRaises (CoordinateNotFoundError ):
102
119
cube .coord ('air_pressure' )
120
+
121
+ def test_fix_metadata_correct_time (self ):
122
+ """Test fix for time."""
123
+ fixed_cube = self .fix .fix_metadata ([self .cube ])[0 ]
124
+ time_coord = fixed_cube .coord ('time' )
125
+ np .testing .assert_allclose (time_coord .points , [0 , 1 ])
126
+ assert time_coord .bounds is None
127
+
128
+ def test_fix_metadata_wrong_time (self ):
129
+ """Test fix for time."""
130
+ fixed_cube = self .fix .fix_metadata ([self .cube_with_wrong_time ])[0 ]
131
+ time_coord = fixed_cube .coord ('time' )
132
+ np .testing .assert_allclose (time_coord .points , [- 711841.5 , - 711810.5 ])
133
+ np .testing .assert_allclose (
134
+ time_coord .bounds ,
135
+ [[- 711857.0 , - 711826.0 ], [- 711826.0 , - 711796.5 ]])
136
+
137
+ def test_fix_metadata_wrong_time_no_bounds (self ):
138
+ """Test fix for time."""
139
+ self .cube_with_wrong_time .coord ('time' ).bounds = None
140
+ fixed_cube = self .fix .fix_metadata ([self .cube_with_wrong_time ])[0 ]
141
+ time_coord = fixed_cube .coord ('time' )
142
+ np .testing .assert_allclose (time_coord .points , [- 711845.0 , - 711814.0 ])
143
+ assert time_coord .bounds is None
0 commit comments