Principal Component Analysis (PCA)¶
PCA is a technique used to emphasize variation and bring out strong patterns in a dataset. It's often used to make data easy to explore and visualize. In this notebook, we'll perform PCA on a multi-spectral imagery to reduce the dimensionality of the data and visualize the results.
In [1]:
Copied!
import hypercoast
import hypercoast
In [2]:
Copied!
url = "https://github.com/opengeos/datasets/releases/download/hypercoast/Planet_2022-09-23.tif"
filepath = "data/Planet_2022-09-23.tif"
hypercoast.download_file(url, filepath)
url = "https://github.com/opengeos/datasets/releases/download/hypercoast/Planet_2022-09-23.tif"
filepath = "data/Planet_2022-09-23.tif"
hypercoast.download_file(url, filepath)
Out[2]:
'/home/runner/work/HyperCoast/HyperCoast/docs/examples/data/Planet_2022-09-23.tif'
In [3]:
Copied!
output_file = filepath.replace(".tif", "_pca.tif")
output_file = filepath.replace(".tif", "_pca.tif")
In [4]:
Copied!
hypercoast.pca(filepath, output_file, n_components=3)
hypercoast.pca(filepath, output_file, n_components=3)
In [5]:
Copied!
m = hypercoast.Map()
m.add_basemap("Hybrid")
m.add_dataset(
filepath, indexes=[6, 4, 2], vmin=0, vmax=2500, layer_name="Planet Image", nodata=0
)
m.add_dataset(
output_file, indexes=[0, 1, 2], vmin=0, vmax=2500, layer_name="PCA Image", nodata=0
)
m.add("spectral")
m
m = hypercoast.Map()
m.add_basemap("Hybrid")
m.add_dataset(
filepath, indexes=[6, 4, 2], vmin=0, vmax=2500, layer_name="Planet Image", nodata=0
)
m.add_dataset(
output_file, indexes=[0, 1, 2], vmin=0, vmax=2500, layer_name="PCA Image", nodata=0
)
m.add("spectral")
m
Out[5]: