def test_multi_dimensional(self):
     time = AuxCoord(np.arange(12).reshape(3, 4), 'time',
                     units='hours since 2013-10-29 18:00:00')
     cube = Cube(np.arange(12).reshape(3, 4))
     cube.add_aux_coord(time, (0, 1))
     constraint = TimeConstraint(hour=12)
     with self.assertRaises(CoordinateMultiDimError):
         sub_cube = constraint.extract(cube)
 def test_3d_data(self):
     time = DimCoord(np.arange(12) * 6, 'time',
                     units='hours since 2013-10-29 18:00:00')
     cube = Cube(np.arange(12 * 5 * 6).reshape(12, 5, 6))
     cube.add_dim_coord(time, 0)
     constraint = TimeConstraint(hour=12)
     sub_cube = constraint.extract(cube)
     self.assertArrayEqual(sub_cube.coord('time').points, [18, 42, 66])
Exemple #3
0
 def test_multi_dimensional(self):
     time = AuxCoord(np.arange(12).reshape(3, 4),
                     'time',
                     units='hours since 2013-10-29 18:00:00')
     cube = Cube(np.arange(12).reshape(3, 4))
     cube.add_aux_coord(time, (0, 1))
     constraint = TimeConstraint(hour=12)
     with self.assertRaises(CoordinateMultiDimError):
         sub_cube = constraint.extract(cube)
Exemple #4
0
 def test_3d_data(self):
     time = DimCoord(np.arange(12) * 6,
                     'time',
                     units='hours since 2013-10-29 18:00:00')
     cube = Cube(np.arange(12 * 5 * 6).reshape(12, 5, 6))
     cube.add_dim_coord(time, 0)
     constraint = TimeConstraint(hour=12)
     sub_cube = constraint.extract(cube)
     self.assertArrayEqual(sub_cube.coord('time').points, [18, 42, 66])
 def test_default(self):
     cube = self._1d_cube()
     constraint = TimeConstraint()
     sub_cube = constraint.extract(cube)
     self.assertIs(sub_cube, cube)
Exemple #6
0
 def test_scalar_time_coord_no_match(self):
     cube = self._cube(0)
     constraint = TimeConstraint(hour=12)
     sub_cube = constraint.extract(cube)
     self.assertIsNone(sub_cube)
Exemple #7
0
 def test_1d_data(self):
     cube = self._1d_cube()
     constraint = TimeConstraint(hour=12)
     sub_cube = constraint.extract(cube)
     self.assertArrayEqual(sub_cube.coord('time').points, [18, 42, 66])
Exemple #8
0
 def test_wrong_type(self):
     with self.assertRaises(ValueError):
         constraint = TimeConstraint(hour='quangle')
Exemple #9
0
 def test(self):
     constraint = TimeConstraint(hour=9)
     self.assertEqual(repr(constraint), 'TimeConstraint(hour=9)')
Exemple #10
0
 def test_negative(self):
     with self.assertRaises(ValueError):
         constraint = TimeConstraint(hour=-3)
Exemple #11
0
 def test_too_large(self):
     with self.assertRaises(ValueError):
         constraint = TimeConstraint(hour=24)
Exemple #12
0
 def test_default(self):
     constraint = TimeConstraint()
     self.assertIsNone(constraint.hour)
     self.assertEqual(constraint.coord, 'time')
Exemple #13
0
 def test_explicit(self):
     constraint = TimeConstraint(hour=4, coord='quee')
     self.assertEqual(constraint.hour, 4)
     self.assertEqual(constraint.coord, 'quee')
Exemple #14
0
 def test_no_coord_match(self):
     cube = self._1d_cube()
     constraint = TimeConstraint(hour=12)
     sub_cube = constraint.extract(cube)
     self.assertIsNone(sub_cube)
 def test_none(self):
     cube = self._1d_cube()
     constraint = TimeConstraint(hour=None)
     sub_cube = constraint.extract(cube)
     self.assertIs(sub_cube, cube)
Exemple #16
0
 def test_none(self):
     cube = self._1d_cube()
     constraint = TimeConstraint(hour=None)
     sub_cube = constraint.extract(cube)
     self.assertIs(sub_cube, cube)
Exemple #17
0
 def test_default(self):
     cube = self._1d_cube()
     constraint = TimeConstraint()
     sub_cube = constraint.extract(cube)
     self.assertIs(sub_cube, cube)
 def test_no_coord_match(self):
     cube = self._1d_cube()
     constraint = TimeConstraint(hour=12)
     sub_cube = constraint.extract(cube)
     self.assertIsNone(sub_cube)
 def test_1d_data(self):
     cube = self._1d_cube()
     constraint = TimeConstraint(hour=12)
     sub_cube = constraint.extract(cube)
     self.assertArrayEqual(sub_cube.coord('time').points, [18, 42, 66])
 def test_scalar_time_coord_no_match(self):
     cube = self._cube(0)
     constraint = TimeConstraint(hour=12)
     sub_cube = constraint.extract(cube)
     self.assertIsNone(sub_cube)