def test_fails_with_multi_point_coord(self): """Test that if an error is raised if a coordinate with more than one point is given""" emsg = 'the expand bounds function should only be used on a' with self.assertRaisesRegex(ValueError, emsg): CubeCombiner.expand_bounds(self.cubelist[0], self.cubelist, 'latitude', 'mid')
def test_basic_time_upper(self): """Test that expand_bound produces sensible bounds when given arg 'upper'""" result = CubeCombiner.expand_bounds(self.cubelist[0], self.cubelist, 'time', 'upper') expected_result = iris.coords.DimCoord( [402195], bounds=[[402192, 402195]], standard_name='time', units=Unit('hours since 1970-01-01 00:00:00', calendar='gregorian')) self.assertEqual(result.coord('time'), expected_result)
def test_time_mid_data_precision(self): """Test that expand_bound does not escalate precision when input is of dtype int32""" expected_result = iris.coords.DimCoord(np.array([5400], dtype=np.int32), bounds=np.array([0, 10800], dtype=np.int32), standard_name='forecast_period', units='seconds') result = CubeCombiner.expand_bounds(self.cubelist[0], self.cubelist, 'forecast_period', 'mid') self.assertEqual(result.coord('forecast_period'), expected_result) self.assertEqual(result.coord('forecast_period').dtype, np.int32)
def test_basic_no_time_bounds(self): """ Test that it fails if there are no time bounds """ c_list = self.cubelist for cube in c_list: cube.coord('time').bounds = None result = CubeCombiner.expand_bounds(self.cubelist[0], self.cubelist, 'time', 'mid') expected_result = iris.coords.DimCoord( [402194], bounds=[[402193, 402195]], standard_name='time', units=Unit('hours since 1970-01-01 00:00:00', calendar='gregorian')) self.assertEqual(result.coord('time'), expected_result)
def test_basic_time_upper(self): """Test that expand_bound produces sensible bounds when given arg 'upper'""" time_point = np.around( date2num(dt(2015, 11, 19, 3), TIME_UNIT, CALENDAR)).astype(np.int64) expected_result = iris.coords.DimCoord( [time_point], bounds=self.expected_bounds_seconds, standard_name='time', units=TIME_UNIT) result = CubeCombiner.expand_bounds(self.cubelist[0], self.cubelist, 'time', 'upper') self.assertEqual(result.coord('time'), expected_result)
def test_float_time_mid(self): """Test that expand_bound produces sensible bounds when given arg 'mid' for times in hours""" time_unit = 'hours since 1970-01-01 00:00:00' for cube in self.cubelist: cube.coord("time").convert_units(time_unit) time_point = date2num(dt(2015, 11, 19, 1, 30), time_unit, CALENDAR) expected_result = iris.coords.DimCoord( [time_point], bounds=self.expected_bounds_hours, standard_name='time', units=time_unit) result = CubeCombiner.expand_bounds(self.cubelist[0], self.cubelist, 'time', 'mid') self.assertEqual(result.coord('time'), expected_result) self.assertEqual(result.coord('time').dtype, np.float32)
def test_basic_no_time_bounds(self): """Test that it creates appropriate bounds if there are no time bounds """ for cube in self.cubelist: cube.coord('time').bounds = None time_point = np.around( date2num(dt(2015, 11, 19, 2), TIME_UNIT, CALENDAR)).astype(np.int64) time_bounds = [ np.around(date2num(dt(2015, 11, 19, 1), TIME_UNIT, CALENDAR)).astype(np.int64), np.around(date2num(dt(2015, 11, 19, 3), TIME_UNIT, CALENDAR)).astype(np.int64) ] expected_result = iris.coords.DimCoord(time_point, bounds=time_bounds, standard_name='time', units=TIME_UNIT) result = CubeCombiner.expand_bounds(self.cubelist[0], self.cubelist, 'time', 'mid') self.assertEqual(result.coord('time'), expected_result)