def test_raster_no_Polygon(self): lon = np.random.random((10, 20)) lat = np.random.random((10, 20)) R = Raster(lon, lat) with self.assertRaises(ValueError): P = np.arange(10) R._rasterize_single_polygon(P)
def test_raster_multiple_polygon(self): # this is quite slow! lon = np.linspace(-180., 180., 361) lat = np.linspace(-90., 90., 181) LON, LAT = np.meshgrid(lon, lat) #~ #~ # test a single polygon poly = [] poly1 = [(-10., -10.), (-10., 20), (15., 0.), (0., -15.)] poly.append(Polygon(1, poly1)) #~ #~ poly2 = [(-50., -80.), (-50., -70.), (-40., -70.), (-40., -75.)] poly.append(Polygon(2, poly2)) #~ #~ R = Raster(LON, LAT) R.rasterize_polygons(poly) #~ #~ u = np.unique(R.mask[~R.mask.mask]) self.assertTrue(len(u) == 2) self.assertTrue(1 in u) self.assertTrue(2 in u)
def test_raster_single_polygon(self): lon = np.linspace(-180., 180., 361) lat = np.linspace(-90., 90., 181) LON, LAT = np.meshgrid(lon, lat) # test a single polygon poly = [(-10., -10.), (-10., 20), (15., 0.), (0., -25.)] P = Polygon(5, poly) R = Raster(LON, LAT) R.mask = np.zeros(LON.shape) * np.nan R._rasterize_single_polygon(P) print np.unique(R.mask) R.mask = np.ma.array(R.mask, mask=np.isnan(R.mask)) u = np.unique(R.mask[~R.mask.mask]) print R.mask print u self.assertTrue(len(u) == 1) self.assertTrue(5. in u)
def test_raster_wrong_latlon(self): lon = np.random.random(10) lat = np.random.random(10) print lon.ndim with self.assertRaises(ValueError): R = Raster(lon, lat)
def test_raster_wrong_geometry(self): lon = np.random.random((10, 20)) lat = np.random.random((11, 20)) with self.assertRaises(ValueError): R = Raster(lon, lat)