Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for K-means and Spectral Angle Mapper (SAM) #144

Merged
merged 10 commits into from
Oct 13, 2024
Merged

Add support for K-means and Spectral Angle Mapper (SAM) #144

merged 10 commits into from
Oct 13, 2024

Conversation

giswqs
Copy link
Member

@giswqs giswqs commented Oct 12, 2024

Compute cyanobacteria band ratios

import hypercoast
from hypercoast.pace import cyano_band_ratios

filepath = "data/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc"
dataset = hypercoast.read_pace(filepath)
da = cyano_band_ratios(dataset, plot=True)

image

@giswqs giswqs changed the title Add support for K-mean and Spectral Angle Mapper (SAM) Add support for K-means and Spectral Angle Mapper (SAM) Oct 12, 2024
Copy link

github-actions bot commented Oct 12, 2024

@github-actions github-actions bot temporarily deployed to pull request October 12, 2024 02:43 Inactive
@giswqs
Copy link
Member Author

giswqs commented Oct 12, 2024

K-means

import hypercoast
from hypercoast.pace import apply_kmeans

filepath = "data/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc"
dataset = hypercoast.read_pace(filepath)

cluster_labels, latitudes, longitudes = apply_kmeans(dataset, n_clusters=6)

image

@giswqs
Copy link
Member Author

giswqs commented Oct 12, 2024

PCA

import hypercoast
from hypercoast.pace import apply_pca

filepath = "data/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc"
dataset = hypercoast.read_pace(filepath)

pca_data = apply_pca(dataset, n_components=3, x_component=0, y_component=1)

image
image

@github-actions github-actions bot temporarily deployed to pull request October 12, 2024 03:19 Inactive
@giswqs
Copy link
Member Author

giswqs commented Oct 13, 2024

Apply K-means to selected pixels

import hypercoast
from hypercoast.pace import apply_kmeans

filepath = "data/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc"
dataset = hypercoast.read_pace(filepath)

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
    )

image

@github-actions github-actions bot temporarily deployed to pull request October 13, 2024 01:32 Inactive
@giswqs
Copy link
Member Author

giswqs commented Oct 13, 2024

Apply Spectral Angle Mapper

import hypercoast
from hypercoast.pace import apply_sam

filepath = "data/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc"
dataset = hypercoast.read_pace(filepath)

data, latitudes, longitudes = apply_sam(
    dataset,
    n_components=3, 
    n_clusters=6,
    )

image

extent = [-95, -85, 27, 33]
colors = ["#377eb8", "#ff7f00", "#4daf4a", "#f781bf", "#a65628", "#984ea3"]
data, latitudes, longitudes = apply_sam(
    dataset,
    n_components=3, 
    n_clusters=6,
    extent=extent,
    colors=colors,
    )

image

@giswqs
Copy link
Member Author

giswqs commented Oct 13, 2024

Add SAM filter condition

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"]

data, latitudes, longitudes = apply_sam(
    dataset,
    n_components=3, 
    n_clusters=6,
    filter_condition=filter_condition,
    extent=extent,
    colors=colors,
    )

image

@github-actions github-actions bot temporarily deployed to pull request October 13, 2024 02:34 Inactive
@giswqs
Copy link
Member Author

giswqs commented Oct 13, 2024

Add support for spectral library

import hypercoast
from hypercoast.pace import apply_sam_spectral

filepath = "data/PACE_OCI.20240730T181157.L2.OC_AOP.V2_0.NRT.nc"
dataset = hypercoast.read_pace(filepath)
url = "https://github.com/opengeos/datasets/releases/download/hypercoast/SAM_spectral_library.zip"
hypercoast.download_file(url)
spectral_library = "./SAM_spectral_library/*.csv"

extent = [-95, -85, 27, 33]
data, latitudes, longitudes = apply_sam_spectral(
    dataset,
    spectral_library=spectral_library,
    extent=extent,
    )

image
image

da = dataset["Rrs"]
extent = [-95, -85, 27, 33]
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))
)
data, latitudes, longitudes = apply_sam_spectral(
    da,
    spectral_library=spectral_library,
    filter_condition=filter_condition,
    extent=extent,
    )

image

@github-actions github-actions bot temporarily deployed to pull request October 13, 2024 03:38 Inactive
@giswqs giswqs merged commit b91b3d7 into main Oct 13, 2024
13 checks passed
@giswqs giswqs deleted the sam branch October 13, 2024 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant