Skip to content

Commit

Permalink
adds bands as parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricebrito committed Oct 19, 2023
1 parent 0f70077 commit cd02a8b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
12 changes: 8 additions & 4 deletions water-bodies/app-package-cloud-native.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cwlVersion: v1.0

$namespaces:
s: https://schema.org/
s:softwareVersion: 1.2.1
s:softwareVersion: 1.3.0
schemas:
- http://schema.org/version/9.0/schemaorg-current-http.rdf

Expand Down Expand Up @@ -31,6 +31,11 @@ $graph:
label: Sentinel-2 STAC items
doc: list of Sentinel-2 COG STAC items
type: string[]
bands:
label: bands used for the NDWI
doc: bands used for the NDWI
type: string[]
default: ["green", "nir"]

outputs:
- id: stac_catalog
Expand All @@ -45,6 +50,7 @@ $graph:
item: stac_items
aoi: aoi
epsg: epsg
bands: bands
out:
- detected_water_body
scatter: item
Expand Down Expand Up @@ -78,7 +84,6 @@ $graph:
bands:
doc: bands used for the NDWI
type: string[]
default: ["green", "nir"]
item:
doc: STAC item
type: string
Expand All @@ -96,8 +101,7 @@ $graph:
item: item
aoi: aoi
epsg: epsg
band:
default: ["green", "nir"]
band: bands
out:
- cropped
scatter: band
Expand Down
12 changes: 8 additions & 4 deletions water-bodies/app-package.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cwlVersion: v1.0

$namespaces:
s: https://schema.org/
s:softwareVersion: 1.2.1
s:softwareVersion: 1.3.0
schemas:
- http://schema.org/version/9.0/schemaorg-current-http.rdf

Expand Down Expand Up @@ -31,6 +31,11 @@ $graph:
label: Sentinel-2 STAC items
doc: list of staged Sentinel-2 COG STAC items
type: Directory[]
bands:
label: bands used for the NDWI
doc: bands used for the NDWI
type: string[]
default: ["green", "nir"]

outputs:
- id: stac_catalog
Expand All @@ -45,6 +50,7 @@ $graph:
item: stac_items
aoi: aoi
epsg: epsg
bands: bands
out:
- detected_water_body
scatter: item
Expand Down Expand Up @@ -78,7 +84,6 @@ $graph:
bands:
doc: bands used for the NDWI
type: string[]
default: ["green", "nir"]
item:
doc: staged STAC item
type: Directory
Expand All @@ -96,8 +101,7 @@ $graph:
item: item
aoi: aoi
epsg: epsg
band:
default: ["green", "nir"]
band: bands
out:
- cropped
scatter: band
Expand Down
13 changes: 13 additions & 0 deletions water-bodies/command-line-tools/norm_diff/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Normalized difference"""
import click
from osgeo import gdal
import cv2
import numpy as np

gdal.UseExceptions()
Expand All @@ -19,6 +20,8 @@ def normalized_difference(rasters):
ds1 = gdal.Open(rasters[0])
ds2 = gdal.Open(rasters[1])



driver = gdal.GetDriverByName("GTiff")

dst_ds = driver.Create(
Expand All @@ -36,6 +39,16 @@ def normalized_difference(rasters):
array1 = ds1.GetRasterBand(1).ReadAsArray().astype(float)
array2 = ds2.GetRasterBand(1).ReadAsArray().astype(float)

# resizes the arrays to the biggest common size
if array1.shape != array2.shape:
max_x = max(array1.shape[0], array2.shape[0])
max_y = max(array1.shape[1], array2.shape[1])

resized_array1 = cv2.resize(array1, (max_x, max_y), interpolation=cv2.INTER_NEAREST)

array1 = array1[:min_x, :min_y]
array2 = array2[:min_x, :min_y]

norm_diff = (array1 - array2) / (array1 + array2)

dst_ds.GetRasterBand(1).WriteArray(norm_diff)
Expand Down
1 change: 1 addition & 0 deletions water-bodies/command-line-tools/otsu/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from osgeo import gdal
from skimage.filters import threshold_otsu

gdal.UseExceptions()

def threshold(data):
"""Returns the Otsu threshold of a numpy array"""
Expand Down

0 comments on commit cd02a8b

Please sign in to comment.