Mapping Cyanobacteria with PACE data¶
Install packages¶
Uncomment the following cell to install the HyperCoast package.
In [1]:
Copied!
# %pip install -U "hypercoast[extra]"
# %pip install -U "hypercoast[extra]"
Import libraries¶
In [2]:
Copied!
import earthaccess
import hypercoast
from hypercoast.pace import (
cyano_band_ratios,
apply_kmeans,
apply_pca,
apply_sam,
apply_sam_spectral,
)
import earthaccess
import hypercoast
from hypercoast.pace import (
cyano_band_ratios,
apply_kmeans,
apply_pca,
apply_sam,
apply_sam_spectral,
)
Download PACE data¶
To download and access the PACE AOP data, you will need to create an Earthdata login. You can register for an account at urs.earthdata.nasa.gov. Once you have an account, run the following cell and enter your NASA Earthdata login credentials.
In [3]:
Copied!
earthaccess.login(persist=True)
earthaccess.login(persist=True)
Out[3]:
<earthaccess.auth.Auth at 0x7f431c7e7260>
Search for PACE AOP data:
In [4]:
Copied!
results = hypercoast.search_pace(
bounding_box=(-83, 25, -81, 28),
temporal=("2024-07-30", "2024-08-15"),
short_name="PACE_OCI_L2_AOP_NRT",
count=1,
)
results = hypercoast.search_pace(
bounding_box=(-83, 25, -81, 28),
temporal=("2024-07-30", "2024-08-15"),
short_name="PACE_OCI_L2_AOP_NRT",
count=1,
)
Download PACE AOP data:
In [5]:
Copied!
hypercoast.download_pace(results[:1], out_dir="data")
hypercoast.download_pace(results[:1], out_dir="data")
Read PACE data¶
Read PACE AOP data as an xarray.Dataset
:
In [6]:
Copied!
filepath = "data/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc"
dataset = hypercoast.read_pace(filepath)
# dataset
filepath = "data/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc"
dataset = hypercoast.read_pace(filepath)
# dataset
Compute band ratios¶
In [7]:
Copied!
da = cyano_band_ratios(dataset, plot=True)
da = cyano_band_ratios(dataset, plot=True)
The spectra of cyanobacteria bloom:¶
Cyanobacteria and Spectral Angle Mapper¶
Spectral Angle Mapper: Spectral similarity Input: library of Cyanobacteria bloom Rrs spectra with Chla at different levels
Spectral Mixture Analysis: unmix different cyanobacteria species based on spectral difference.
K-means applied to the whole image¶
In [8]:
Copied!
cluster_labels, latitudes, longitudes = apply_kmeans(dataset, n_clusters=6)
cluster_labels, latitudes, longitudes = apply_kmeans(dataset, n_clusters=6)
K-means applied to selected pixels¶
In [9]:
Copied!
da = dataset["Rrs"]
filter_condition = (
(da.sel(wavelength=650) > da.sel(wavelength=620))
& (da.sel(wavelength=701) > da.sel(wavelength=681))
& (da.sel(wavelength=701) > da.sel(wavelength=450))
)
extent = [-95, -85, 27, 33]
colors = ["#e41a1c", "#377eb8", "#4daf4a", "#f781bf", "#a65628", "#984ea3"]
cluster_labels, latitudes, longitudes = apply_kmeans(
da, n_clusters=6, filter_condition=filter_condition, extent=extent, colors=colors
)
da = dataset["Rrs"]
filter_condition = (
(da.sel(wavelength=650) > da.sel(wavelength=620))
& (da.sel(wavelength=701) > da.sel(wavelength=681))
& (da.sel(wavelength=701) > da.sel(wavelength=450))
)
extent = [-95, -85, 27, 33]
colors = ["#e41a1c", "#377eb8", "#4daf4a", "#f781bf", "#a65628", "#984ea3"]
cluster_labels, latitudes, longitudes = apply_kmeans(
da, n_clusters=6, filter_condition=filter_condition, extent=extent, colors=colors
)
Principal Component Analysis (PCA)¶
In [10]:
Copied!
pca_data = apply_pca(dataset, n_components=3, x_component=0, y_component=1)
pca_data = apply_pca(dataset, n_components=3, x_component=0, y_component=1)