def test_extract_categorical_season(self): test_cube_a = common._generate_extended_cube() constraint = iris.Constraint(season='son') test_cube_a = ch.extract_categorical(test_cube_a, 'season', constraint=constraint) self.assertIsNotNone(test_cube_a) self.assertEqual(test_cube_a.coord('season').points[0], 'son') self.assertEqual(test_cube_a.coord('time').points[0], 3575.5)
def test_extract_categorical_day_of_year(self): test_cube_a = common._generate_extended_cube() constraint = iris.Constraint(day_of_year=134) test_cube_a = ch.extract_categorical(test_cube_a, 'day_of_year', constraint=constraint) self.assertIsNotNone(test_cube_a) self.assertEqual(test_cube_a.coord('day_of_year').points[0], 134) self.assertEqual(test_cube_a.coord('time').points[0], 3420.0)
def test_extract_categorical_month_number(self): test_cube_a = common._generate_extended_cube() constraint = iris.Constraint(month_number=12) test_cube_a = ch.extract_categorical(test_cube_a, 'month_number', constraint=constraint) self.assertIsNotNone(test_cube_a) self.assertEqual(test_cube_a.coord('month_number').points[0], 12) self.assertEqual(test_cube_a.coord('time').points[0], 3636.5)
def test_extract_categorical_weekday_number(self): test_cube_a = common._generate_extended_cube() constraint = iris.Constraint(weekday_number=5) test_cube_a = ch.extract_categorical(test_cube_a, 'weekday_number', constraint=constraint) self.assertIsNotNone(test_cube_a) self.assertEqual(test_cube_a.coord('weekday_number').points[0], 5) self.assertEqual(test_cube_a.coord('time').points[0], 3498.5)
def test_extract_categorical_weekday_fullname(self): test_cube_a = common._generate_extended_cube() constraint = iris.Constraint(weekday_fullname='Saturday') test_cube_a = ch.extract_categorical(test_cube_a, 'weekday_fullname', constraint=constraint) self.assertIsNotNone(test_cube_a) self.assertEqual( test_cube_a.coord('weekday_fullname').points[0], 'Saturday') self.assertEqual(test_cube_a.coord('time').points[0], 3498.5)
def test_extract_categorical_year(self): test_cube_a = common._generate_extended_cube() const = iris.Constraint(year=lambda cell: cell > 1970 and cell < 1976) test_cube_a = ch.extract_categorical(test_cube_a, 'year', constraint=const) self.assertIsNotNone(test_cube_a) self.assertEqual(test_cube_a.coord('year').points[0], 1971) self.assertEqual(test_cube_a.coord('year').points[4], 1975) self.assertEqual(test_cube_a.coord('time').points[0], 547.0) self.assertEqual(test_cube_a.coord('time').points[4], 2008.0)
def test_extract_categorical_compounds(self): test_cube_a = common._generate_extended_cube() constraint = iris.Constraint( clim_season='djf', season_year=lambda cell: cell >= 1970 and cell <= 1980) test_cube_a = ch.extract_categorical(test_cube_a, 'annual_seasonal_mean', constraint=constraint) self.assertIsNotNone(test_cube_a) self.assertEqual(test_cube_a.coord('time').bounds[0][0], 0) self.assertEqual(test_cube_a.coord('time').bounds[0][1], 58.0) self.assertEqual(test_cube_a.coord('time').points[0], 29.0) self.assertEqual(test_cube_a.coord('clim_season').points[0], 'djf') self.assertEqual(test_cube_a.coord('season_year').points[0], 1970)
def test_extract_categorical_day_of_month(self): test_cube_a = common._generate_extended_cube() constraint = iris.Constraint( day_of_month=lambda cell: cell > 0 and cell < 17) test_cube_a = ch.extract_categorical(test_cube_a, 'day_of_month', constraint=constraint) self.assertEqual(test_cube_a.coord('day_of_month').points[0], 1) self.assertEqual(test_cube_a.coord('day_of_month').points[5], 6) self.assertEqual(test_cube_a.coord('day_of_month').points[10], 11) self.assertEqual(test_cube_a.coord('day_of_month').points[15], 16) self.assertEqual(test_cube_a.coord('time').points[0], 3499.5) self.assertEqual(test_cube_a.coord('time').points[5], 3490.5) self.assertEqual(test_cube_a.coord('time').points[10], 3495.5) self.assertEqual(test_cube_a.coord('time').points[15], 3500.5)