def test_get_bucket_indices(self): """Test calculation of array indices.""" # Ensure nothing is calculated with dask.config.set(scheduler=CustomScheduler(max_computes=0)): self.resampler._get_indices() x_idxs, y_idxs = da.compute(self.resampler.x_idxs, self.resampler.y_idxs) np.testing.assert_equal(x_idxs, np.array([1710, 1710, 1707, 1705])) np.testing.assert_equal(y_idxs, np.array([465, 465, 459, 455])) # Additional small test case adef = create_area_def(area_id='test', projection={'proj': 'latlong'}, width=2, height=2, center=(0, 0), resolution=10) lons = da.from_array(np.array( [-10.0, -9.9, -0.1, 0, 0.1, 9.9, 10.0, -10.1, 0]), chunks=2) lats = da.from_array(np.array( [-10.0, -9.9, -0.1, 0, 0.1, 9.9, 10.0, 0, 10.1]), chunks=2) resampler = bucket.BucketResampler(source_lats=lats, source_lons=lons, target_area=adef) resampler._get_indices() np.testing.assert_equal(resampler.x_idxs, np.array([-1, 0, 0, 1, 1, 1, -1, -1, -1])) np.testing.assert_equal(resampler.y_idxs, np.array([-1, 1, 1, 1, 0, 0, -1, -1, -1]))
def test_init(self, get_indices, prj): resampler = bucket.BucketResampler(self.adef, self.lons, self.lats) get_indices.assert_called_once() prj.assert_called_once_with(self.adef.proj_dict) self.assertTrue(hasattr(resampler, 'target_area')) self.assertTrue(hasattr(resampler, 'source_lons')) self.assertTrue(hasattr(resampler, 'source_lats')) self.assertTrue(hasattr(resampler, 'x_idxs')) self.assertTrue(hasattr(resampler, 'y_idxs')) self.assertTrue(hasattr(resampler, 'idxs')) self.assertTrue(hasattr(resampler, 'get_sum')) self.assertTrue(hasattr(resampler, 'get_count')) self.assertTrue(hasattr(resampler, 'get_average')) self.assertTrue(hasattr(resampler, 'get_fractions')) self.assertIsNone(resampler.counts)
def setUp(self): self.resampler = bucket.BucketResampler(self.adef, self.lons, self.lats)