def test_bin_spatial_counts(self): """ this will test both good and bad points within the region. 1) 2 inside the domain 2) outside the bbox but not in domain 3) completely outside the domain we will check that only 1 event is placed in the grid and ensure its location is correct. """ # create some arbitrary grid nx = 8 ny = 10 dh = 0.1 x_points = numpy.arange(nx) * dh y_points = numpy.arange(ny) * dh origins = list(itertools.product(x_points, y_points)) # grid is missing first and last block origins.pop(0) origins.pop(-1) cart_grid = CartesianGrid2D( [Polygon(bbox) for bbox in compute_vertices(origins, dh)], dh ) catalog = MockCatalog() catalog.region = cart_grid test_result = catalog.spatial_counts() # we have tested 2 inside the domain self.assertEqual(numpy.sum(test_result), 2) # we know that (0.05, 0.15) corresponds to index 0 self.assertEqual(test_result[0], 1) # we know that (0.15, 0.05) corresponds too index 9 self.assertEqual(test_result[9], 1)
def test_polygon_mask_all_masked(self): polygons = [Polygon(bbox) for bbox in compute_vertices(self.origins, self.dh)] n_poly = len(polygons) # this should mask every polygon for easy checking test_grid = CartesianGrid2D(polygons, self.dh, mask=numpy.zeros(n_poly)) self.assertEqual(n_poly, test_grid.num_nodes) numpy.testing.assert_array_equal(test_grid.bbox_mask, 1) numpy.testing.assert_array_equal(test_grid.poly_mask, 0)
def setUp(self): # create some arbitrary grid self.nx = 8 self.ny = 10 self.dh = 0.1 x_points = numpy.arange(self.nx)*self.dh y_points = numpy.arange(self.ny)*self.dh self.origins = list(itertools.product(x_points, y_points)) # grid is missing first and last block self.origins.pop(0) self.origins.pop(-1) self.num_nodes = len(self.origins) # this is kinda ugly, maybe we want to create this in a different way, class method? self.cart_grid = CartesianGrid2D([Polygon(bbox) for bbox in compute_vertices(self.origins, self.dh)], self.dh)
def test_bin_probability(self): # we have tested 2 inside the domain nx = 8 ny = 10 dh = 0.1 x_points = numpy.arange(nx) * dh y_points = numpy.arange(ny) * dh origins = list(itertools.product(x_points, y_points)) # grid is missing first and last block origins.pop(0) origins.pop(-1) cart_grid = CartesianGrid2D( [Polygon(bbox) for bbox in compute_vertices(origins, dh)], dh) catalog = MockCatalog() catalog.region = cart_grid test_result = catalog.spatial_event_probability() self.assertEqual(numpy.sum(test_result), 2) # we know that (0.05, 0.15) corresponds to index 0 from the above test self.assertEqual(test_result[0], 1) self.assertEqual(test_result[9], 1)
def setUp(self): # create some arbitrary grid self.nx = 8 self.ny = 10 self.dh = 1 x_points = numpy.arange(1.5, self.nx) * self.dh y_points = numpy.arange(1.5, self.ny) * self.dh # spatial grid starts at (1.5, 1.5); so the event at (1, 1) should be removed. self.origins = list(itertools.product(x_points, y_points)) self.num_nodes = len(self.origins) self.cart_grid = CartesianGrid2D([Polygon(bbox) for bbox in compute_vertices(self.origins, self.dh)], self.dh) # define dummy cat date1 = strptime_to_utc_epoch('2009-01-01 00:00:00.0000') date2 = strptime_to_utc_epoch('2010-01-01 00:00:00.0000') date3 = strptime_to_utc_epoch('2011-01-01 00:00:00.0000') catalog = [(b'1', date1, 1.0, 1.0, 1.0, 1.0), (b'2', date2, 2.0, 2.0, 2.0, 2.0), (b'3', date3, 3.0, 3.0, 3.0, 3.0)] self.test_cat1 = CSEPCatalog(data=catalog)