def test_coordinates_outside_grid_in_col_ungridded_to_ungridded_in_2d( self): from cis.collocation.col_implementations import GeneralUngriddedCollocator, nn_pressure, SepConstraintKdtree import datetime as dt ug_data = mock.make_regular_4d_ungridded_data() sample_points = HyperPointList() sample_points.append( HyperPoint(lat=0.0, lon=0.0, pres=0.1, t=dt.datetime(1984, 8, 29, 8, 34))) sample_points.append( HyperPoint(lat=0.0, lon=0.0, pres=91.0, t=dt.datetime(1984, 9, 2, 1, 23))) sample_points.append( HyperPoint(lat=0.0, lon=0.0, pres=890.0, t=dt.datetime(1984, 9, 4, 15, 54))) sample_points = UngriddedData.from_points_array(sample_points) col = GeneralUngriddedCollocator() new_data = col.collocate(sample_points, ug_data, SepConstraintKdtree(), nn_pressure())[0] eq_(new_data.data[0], 1.0) eq_(new_data.data[1], 46.0) eq_(new_data.data[2], 46.0)
def test_already_collocated_in_col_ungridded_to_ungridded_in_2d(self): from cis.collocation.col_implementations import GeneralUngriddedCollocator, nn_pressure, SepConstraintKdtree import datetime as dt ug_data = mock.make_regular_4d_ungridded_data() sample_points = UngriddedData.from_points_array( [HyperPoint(lat=0.0, lon=0.0, pres=80.0, t=dt.datetime(1984, 9, 4, 15, 54))]) col = GeneralUngriddedCollocator() new_data = col.collocate(sample_points, ug_data, SepConstraintKdtree(), nn_pressure())[0] eq_(new_data.data[0], 41.0)
def test_basic_col_with_incompatible_points_throws_a_TypeError(self): from cis.collocation.col_implementations import GeneralUngriddedCollocator, nn_pressure, SepConstraintKdtree ug_data = mock.make_regular_4d_ungridded_data() # Make sample points with no time dimension specified sample_points = UngriddedData.from_points_array( [HyperPoint(1.0, 1.0), HyperPoint(4.0, 4.0), HyperPoint(-4.0, -4.0)]) col = GeneralUngriddedCollocator() with self.assertRaises(AttributeError): new_data = col.collocate(sample_points, ug_data, SepConstraintKdtree(), nn_pressure())[0]
def test_get_kernel(self): from cis.collocation.col_implementations import moments, nn_pressure, mean from cis.collocation.col import get_kernel assert isinstance(get_kernel('moments'), moments) assert isinstance(get_kernel(nn_pressure()), nn_pressure) assert isinstance(get_kernel('mean', default=moments), mean) assert isinstance(get_kernel('', default=moments), moments) with assert_raises(ValueError): get_kernel('foo') with assert_raises(ValueError): get_kernel('foo', default=moments)
def test_basic_col_with_incompatible_points_throws_a_TypeError(self): from cis.collocation.col_implementations import GeneralUngriddedCollocator, nn_pressure, SepConstraintKdtree ug_data = mock.make_regular_4d_ungridded_data() # Make sample points with no time dimension specified sample_points = UngriddedData.from_points_array([ HyperPoint(1.0, 1.0), HyperPoint(4.0, 4.0), HyperPoint(-4.0, -4.0) ]) col = GeneralUngriddedCollocator() with self.assertRaises(AttributeError): new_data = col.collocate(sample_points, ug_data, SepConstraintKdtree(), nn_pressure())[0]
def test_coordinates_outside_grid_in_col_ungridded_to_ungridded_in_2d(self): from cis.collocation.col_implementations import GeneralUngriddedCollocator, nn_pressure, SepConstraintKdtree import datetime as dt ug_data = mock.make_regular_4d_ungridded_data() sample_points = HyperPointList() sample_points.append(HyperPoint(lat=0.0, lon=0.0, pres=0.1, t=dt.datetime(1984, 8, 29, 8, 34))) sample_points.append(HyperPoint(lat=0.0, lon=0.0, pres=91.0, t=dt.datetime(1984, 9, 2, 1, 23))) sample_points.append(HyperPoint(lat=0.0, lon=0.0, pres=890.0, t=dt.datetime(1984, 9, 4, 15, 54))) sample_points = UngriddedData.from_points_array(sample_points) col = GeneralUngriddedCollocator() new_data = col.collocate(sample_points, ug_data, SepConstraintKdtree(), nn_pressure())[0] eq_(new_data.data[0], 1.0) eq_(new_data.data[1], 46.0) eq_(new_data.data[2], 46.0)
def test_already_collocated_in_col_ungridded_to_ungridded_in_2d(self): from cis.collocation.col_implementations import GeneralUngriddedCollocator, nn_pressure, SepConstraintKdtree import datetime as dt ug_data = mock.make_regular_4d_ungridded_data() sample_points = UngriddedData.from_points_array([ HyperPoint(lat=0.0, lon=0.0, pres=80.0, t=dt.datetime(1984, 9, 4, 15, 54)) ]) col = GeneralUngriddedCollocator() new_data = col.collocate(sample_points, ug_data, SepConstraintKdtree(), nn_pressure())[0] eq_(new_data.data[0], 41.0)
def test_basic_col_in_4d(self): from cis.collocation.col_implementations import GeneralUngriddedCollocator, nn_pressure, DummyConstraint import datetime as dt ug_data = mock.make_regular_4d_ungridded_data() sample_points = HyperPointList() sample_points.append(HyperPoint(lat=1.0, lon=1.0, pres=12.0, t=dt.datetime(1984, 8, 29, 8, 34))) sample_points.append(HyperPoint(lat=4.0, lon=4.0, pres=34.0, t=dt.datetime(1984, 9, 2, 1, 23))) sample_points.append(HyperPoint(lat=-4.0, lon=-4.0, pres=89.0, t=dt.datetime(1984, 9, 4, 15, 54))) sample_points = UngriddedData.from_points_array(sample_points) col = GeneralUngriddedCollocator() new_data = col.collocate(sample_points, ug_data, DummyConstraint(), nn_pressure())[0] eq_(new_data.data[0], 6.0) eq_(new_data.data[1], 16.0) eq_(new_data.data[2], 46.0)
def test_coordinates_exactly_between_points_in_col_ungridded_to_ungridded_in_2d(self): """ This works out the edge case where the points are exactly in the middle or two or more datapoints. The nn_pressure algorithm will start with the first point as the nearest and iterates through the points finding any points which are closer than the current closest. If two distances were exactly the same the first point to be chosen. """ from cis.collocation.col_implementations import GeneralUngriddedCollocator, nn_pressure, SepConstraintKdtree import datetime as dt ug_data = mock.make_regular_4d_ungridded_data() # Choose a time at midday sample_points = UngriddedData.from_points_array( [HyperPoint(lat=0.0, lon=0.0, pres=8, t=dt.datetime(1984, 8, 29, 12))]) col = GeneralUngriddedCollocator() new_data = col.collocate(sample_points, ug_data, SepConstraintKdtree(), nn_pressure())[0] eq_(new_data.data[0], 1.0)
def test_coordinates_exactly_between_points_in_col_ungridded_to_ungridded_in_2d( self): """ This works out the edge case where the points are exactly in the middle or two or more datapoints. The nn_pressure algorithm will start with the first point as the nearest and iterates through the points finding any points which are closer than the current closest. If two distances were exactly the same the first point to be chosen. """ from cis.collocation.col_implementations import GeneralUngriddedCollocator, nn_pressure, SepConstraintKdtree import datetime as dt ug_data = mock.make_regular_4d_ungridded_data() # Choose a time at midday sample_points = UngriddedData.from_points_array([ HyperPoint(lat=0.0, lon=0.0, pres=8, t=dt.datetime(1984, 8, 29, 12)) ]) col = GeneralUngriddedCollocator() new_data = col.collocate(sample_points, ug_data, SepConstraintKdtree(), nn_pressure())[0] eq_(new_data.data[0], 1.0)