class TestToCrs(TestCase): def setUp(self) -> None: # inputs self.predictors = [ nc.band1, nc.band2, nc.band3, nc.band4, nc.band5, nc.band7 ] self.stack = Raster(self.predictors) training_py = gpd.read_file(nc.polygons) self.crop_bounds = training_py.loc[0, "geometry"].bounds # outputs self.cropped = None def tearDown(self) -> None: self.stack.close() self.cropped.close() def test_crop_defaults(self): self.cropped = self.stack.crop(self.crop_bounds) # check raster object self.assertIsInstance(self.cropped, Raster) self.assertEqual(self.cropped.count, self.stack.count) self.assertEqual(self.cropped.read(masked=True).count(), 1440) # test nodata value is recognized self.assertEqual(self.cropped.read(masked=True).min(), 35.0) self.assertEqual(self.cropped.read(masked=True).max(), 168.0) def test_crop_in_memory(self): self.cropped = self.stack.crop(self.crop_bounds, in_memory=True) self.assertIsInstance(self.cropped, Raster)
calculation = stack.calc(function=compute) calculation.plot() # masking training_py = geopandas.read_file(nc.polygons) mask_py = training_py.iloc[0:1, :] mask_py.plot() masked_object = stack.mask(mask_py, invert=False, pad=True) masked_object.plot() # cropping training_py = geopandas.read_file(nc.polygons) crop_bounds = training_py.loc[0, 'geometry'].bounds stack_cropped = stack.crop(crop_bounds) stack_cropped.plot() # reprojection stack_prj = stack.to_crs({'init': 'EPSG:4326'}) stack_prj.plot() # Perform band math ndvi = (stack.iloc[3] - stack.iloc[2]) / (stack.iloc[3] + stack.iloc[2]) ndvi = Raster(ndvi) ndvi.plot() tmp = ndvi.aggregate(out_shape=(50, 50)) tmp.plot() # Perform OR operation (union two layers)