def test_simple_single_point(self): aggregator = WeightedPercentileAggregator() percent = 50 kwargs = dict(percent=percent, weights=self.weights_simple) data = np.empty(self.cube_simple.shape) coords = [self.coord_simple] actual = aggregator.post_process(self.cube_simple, data, coords, **kwargs) self.assertEqual(actual.shape, self.cube_simple.shape) self.assertIs(actual.data, data) name = 'weighted_percentile_over_time' coord = actual.coord(name) expected = AuxCoord(percent, long_name=name) self.assertEqual(coord, expected)
def test_multi_single_point(self): aggregator = WeightedPercentileAggregator() percent = 70 kwargs = dict(percent=percent, weights=self.weights_multi) data = np.empty(self.cube_multi.shape) coords = [self.coord_multi_0] actual = aggregator.post_process(self.cube_multi, data, coords, **kwargs) self.assertEqual(actual.shape, self.cube_multi.shape) self.assertIs(actual.data, data) name = "weighted_percentile_over_time" coord = actual.coord(name) expected = AuxCoord(percent, long_name=name, units="percent") self.assertEqual(coord, expected)
def test_multi_multiple_points(self): aggregator = WeightedPercentileAggregator() percent = np.array([17, 29, 81]) kwargs = dict(percent=percent, weights=self.weights_multi) shape = self.cube_multi.shape + percent.shape data = np.empty(shape) coords = [self.coord_multi_0] actual = aggregator.post_process(self.cube_multi, data, coords, **kwargs) self.assertEqual(actual.shape, percent.shape + self.cube_multi.shape) expected = np.rollaxis(data, -1) self.assertArrayEqual(actual.data, expected) name = 'weighted_percentile_over_time' coord = actual.coord(name) expected = AuxCoord(percent, long_name=name) self.assertEqual(coord, expected)
def test_simple_multiple_points(self): aggregator = WeightedPercentileAggregator() percent = np.array([10, 20, 50, 90]) kwargs = dict(percent=percent, weights=self.weights_simple, returned=True) shape = self.cube_simple.shape + percent.shape data = np.empty(shape) total_weights = 1. coords = [self.coord_simple] actual = aggregator.post_process( self.cube_simple, (data, total_weights), coords, **kwargs) self.assertEqual(len(actual), 2) self.assertEqual(actual[0].shape, percent.shape + self.cube_simple.shape) expected = np.rollaxis(data, -1) self.assertArrayEqual(actual[0].data, expected) self.assertIs(actual[1], total_weights) name = 'weighted_percentile_over_time' coord = actual[0].coord(name) expected = AuxCoord(percent, long_name=name) self.assertEqual(coord, expected)