Example #1
0
class TestPlotting(TestCase):
    def setUp(self) -> None:
        self.predictors = [
            nc.band1, nc.band2, nc.band3, nc.band4, nc.band5, nc.band7
        ]
        self.stack = Raster(self.predictors)
        self.stack_single = Raster(self.predictors[0])

    def tearDown(self) -> None:
        self.stack.close()
        self.stack_single.close()

    def test_plotting_raster(self):

        # test basic raster matrix plot
        p = self.stack.plot()
        self.assertIsInstance(p, np.ndarray)

        # test with arguments
        p = self.stack.plot(
            cmap="plasma",
            norm=mpl.colors.Normalize(vmin=10, vmax=100),
            title_fontsize=10,
            label_fontsize=10,
            names=["band1", "band2", "band3", "band4", "band5", "band7"],
            figsize=(10, 5),
            legend_kwds={"orientation": "horizontal"})
        self.assertIsInstance(p, np.ndarray)

    def test_plotting_single(self):
        p = self.stack_single.plot(legend_kwds={
            "orientation": "horizontal",
            "fraction": 0.04
        })
        self.assertIsInstance(p, mpl.axes.Subplot)
Example #2
0
 def test_plotting_single(self):
     stack = Raster(self.predictors[0])
     p = stack.plot(legend_kwds={
         "orientation": "horizontal",
         "fraction": 0.04
     })
     self.assertIsInstance(p, mpl.axes.Subplot)
Example #3
0
    def test_plotting_raster(self):
        stack = Raster(self.predictors)

        # test basic raster matrix plot
        p = stack.plot()
        self.assertIsInstance(p, np.ndarray)

        # test with arguments
        p = stack.plot(
            cmap="plasma",
            norm=mpl.colors.Normalize(vmin=10, vmax=100),
            title_fontsize=10,
            label_fontsize=10,
            names=["band1", "band2", "band3", "band4", "band5", "band7"],
            figsize=(10, 5),
            legend_kwds={"orientation": "horizontal"})
        self.assertIsInstance(p, np.ndarray)
Example #4
0
import matplotlib.pyplot as plt
import pyspatialml.datasets.nc_dataset as nc
import tempfile
import rasterio

# First, import the extract and predict functions:
predictors = [nc.band1, nc.band2, nc.band3, nc.band4, nc.band5, nc.band7]

# Create a RasterStack instance
stack = Raster(predictors)
stack.count

# 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)
(stack.iloc[5] | stack.iloc[0]).plot()
plt.show()

# Perform AND operation (intersect two layers)
(stack.iloc[5] & stack.iloc[0]).plot()
plt.show()

# Perform XOR operation (symmetrical difference)
(stack.iloc[5] ^ stack.iloc[0]).plot()
plt.show()