Skip to content

Commit

Permalink
Add filter condition
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Oct 13, 2024
1 parent a19e83d commit ce49c9c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hypercoast/pace.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ def apply_sam(
n_components: int = 3,
n_clusters: int = 6,
random_state: int = 0,
filter_condition: Optional[Callable[[xr.DataArray], xr.DataArray]] = None,
plot: bool = True,
figsize: tuple[int, int] = (8, 6),
extent: list[float] = None,
Expand All @@ -991,6 +992,7 @@ def apply_sam(
n_components (int, optional): Number of principal components to compute. Defaults to 3.
n_clusters (int, optional): Number of clusters for K-means. Defaults to 6.
random_state (int, optional): Random state for K-means. Defaults to 0.
filter_condition (Callable[[xr.DataArray], xr.DataArray], optional): A function to filter the data. Defaults to None.
plot (bool, optional): Whether to plot the data. Defaults to True.
figsize (Tuple[int, int], optional): Figure size for the plot. Defaults to (8, 6).
extent (List[float], optional): The extent to zoom in to the specified region. Defaults to None.
Expand Down Expand Up @@ -1058,6 +1060,9 @@ def spectral_angle_mapper(pixel, reference):
best_match_full[~np.isnan(reshaped_data).any(axis=1)] = best_match
best_match_full = best_match_full.reshape(original_shape)

if filter_condition is not None:
best_match_full = np.where(filter_condition, best_match_full, np.nan)

latitudes = da.coords["latitude"].values
longitudes = da.coords["longitude"].values

Expand Down

0 comments on commit ce49c9c

Please sign in to comment.