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])
def test_default(self): cube = self._1d_cube() constraint = TimeConstraint() sub_cube = constraint.extract(cube) self.assertIs(sub_cube, cube)
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)
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_wrong_type(self): with self.assertRaises(ValueError): constraint = TimeConstraint(hour='quangle')
def test(self): constraint = TimeConstraint(hour=9) self.assertEqual(repr(constraint), 'TimeConstraint(hour=9)')
def test_negative(self): with self.assertRaises(ValueError): constraint = TimeConstraint(hour=-3)
def test_too_large(self): with self.assertRaises(ValueError): constraint = TimeConstraint(hour=24)
def test_default(self): constraint = TimeConstraint() self.assertIsNone(constraint.hour) self.assertEqual(constraint.coord, 'time')
def test_explicit(self): constraint = TimeConstraint(hour=4, coord='quee') self.assertEqual(constraint.hour, 4) self.assertEqual(constraint.coord, 'quee')
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)