예제 #1
0
 def test_extract_time_no_slice(self):
     """Test fail of extract_time."""
     with self.assertRaises(ValueError) as ctx:
         extract_time(self.cube, 2200, 1, 1, 2200, 12, 31)
     msg = ("Time slice 2200-01-01 to 2200-12-31 is outside"
            " cube time bounds 1950-01-16 00:00:00 to 1951-12-07 00:00:00.")
     assert ctx.exception.args == (msg, )
예제 #2
0
 def test_extract_time_one_time(self):
     """Test extract_time with one time step."""
     cube = _create_sample_cube()
     cube.coord('time').guess_bounds()
     cube = cube.collapsed('time', iris.analysis.MEAN)
     sliced = extract_time(cube, 1950, 1, 1, 1952, 12, 31)
     assert_array_equal(np.array([360.]), sliced.coord('time').points)
예제 #3
0
 def test_extract_time_no_time(self):
     """Test extract_time with no time step."""
     cube = _create_sample_cube()[0]
     sliced = extract_time(cube, 1950, 1, 1, 1950, 12, 31)
     print('sliced', sliced, sliced.shape)
     print('cube', cube, cube.shape)
     assert cube == sliced
예제 #4
0
 def test_extract_time(self):
     """Test extract_time."""
     sliced = extract_time(self.cube, 1950, 1, 1, 1950, 12, 31)
     iris.coord_categorisation.add_month_number(sliced, 'time')
     assert_array_equal(
         np.arange(1, 13, 1),
         sliced.coord('month_number').points)
예제 #5
0
 def test_extract_time_non_gregorian_day(self):
     """Test extract time when the day is not in the Gregorian calendar"""
     cube = Cube(np.arange(0, 720), var_name='co2', units='J')
     cube.add_dim_coord(
         iris.coords.DimCoord(
             np.arange(0., 720., 1.),
             standard_name='time',
             units=Unit('days since 1950-01-01 00:00:00',
                        calendar='360_day'),
         ),
         0,
     )
     sliced = extract_time(cube, 1950, 2, 30, 1950, 3, 1)
     assert_array_equal(np.array([59]), sliced.coord('time').points)
예제 #6
0
 def test_extract_time_limit(self):
     """Test extract time when limits are included"""
     cube = Cube(np.arange(0, 720), var_name='co2', units='J')
     cube.add_dim_coord(
         iris.coords.DimCoord(
             np.arange(0., 720., 1.),
             standard_name='time',
             units=Unit('days since 1950-01-01 00:00:00',
                        calendar='360_day'),
         ),
         0,
     )
     sliced = extract_time(cube, 1950, 1, 1, 1951, 1, 1)
     assert_array_equal(np.arange(0, 360), sliced.coord('time').points)
예제 #7
0
 def test_extract_time_no_time(self):
     """Test extract_time with no time step."""
     cube = _create_sample_cube()[0]
     sliced = extract_time(cube, 1950, 1, 1, 1950, 12, 31)
     assert cube == sliced
예제 #8
0
 def test_extract_time_no_slice(self):
     """Test fail of extract_time."""
     with self.assertRaises(ValueError):
         extract_time(self.cube, 2200, 1, 1, 2200, 12, 31)
예제 #9
0
 def test_extract_time(self):
     """Test extract_time."""
     sliced = extract_time(self.cube, 1950, 1, 1, 1950, 12, 31)
     assert_array_equal(np.arange(1, 13, 1),
                        sliced.coord('month_number').points)