Skip to content

Commit 1a39199

Browse files
authored
Create NDVI.md
1 parent 476821c commit 1a39199

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

NDVI.md

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Introduction
2+
The Normalized Difference Vegetation Index (NDVI) is a simple but powerful index used to assess vegetation cover, biomass, and health. The NDVI is calculated from the reflectance values of two wavelengths, typically the red and near-infrared bands.
3+
4+
In this tutorial, we'll create an EO application package that calculates the NDVI from Sentinel-2 data using CWL. The package will include a CWL workflow and a CommandLineTool that performs the actual calculation.
5+
6+
# Prerequisites
7+
To follow this tutorial, you'll need:
8+
9+
* A CWL runner installed on your machine. We recommend using `cwltool`, which can be installed using `pip`.
10+
* Access to Sentinel-2 data. You can download Sentinel-2 data from the Copernicus Open Access Hub: https://scihub.copernicus.eu/dhus/#/home or directly from your Ellip account
11+
12+
# Creating the Workflow
13+
14+
Let's start by creating the CWL workflow. The workflow will take a Sentinel-2 scene as input and output the NDVI raster.
15+
Here's what the workflow YAML file should look like:
16+
17+
````yaml
18+
cwlVersion: v1.0
19+
class: Workflow
20+
inputs:
21+
input_scene:
22+
type: File
23+
inputBinding:
24+
position: 1
25+
outputs:
26+
ndvi_raster:
27+
type: File
28+
outputBinding:
29+
glob: $(inputs.input_scene.basename).ndvi.tif
30+
steps:
31+
ndvi_calculation:
32+
in:
33+
input_scene: input_scene
34+
out:
35+
ndvi_raster: ndvi_raster
36+
run:
37+
class: CommandLineTool
38+
baseCommand: gdal_calc.py
39+
inputs:
40+
input_raster:
41+
type: File
42+
inputBinding:
43+
position: 1
44+
ndvi_raster:
45+
type: File
46+
outputBinding:
47+
glob: $(inputs.input_raster.basename).ndvi.tif
48+
arguments:
49+
- --outfile=$(inputs.ndvi_raster.path)
50+
- --calc="(B05 - B04) / (B05 + B04)"
51+
- --type=Float32
52+
````
53+
54+
Let's break down each part of the workflow:
55+
56+
* `inputs`: This section specifies the input to the workflow. In this case, we have one input, `input_scene`, which is a Sentinel-2 scene in GeoTIFF format.
57+
* `outputs`: This section specifies the output of the workflow. In this case, we have one output, `ndvi_raster`, which is the NDVI raster in GeoTIFF format.
58+
* `steps`: This section contains the steps of the workflow. In this case, we have one step, `ndvi_calculation`, which performs the NDVI calculation using the `gdal_calc.py` CommandLineTool.
59+
* `ndvi_calculation`: This step references the gdal_calc.py CommandLineTool and specifies the input and output of the step.
60+
61+
Note that the `gdal_calc.py` CommandLineTool is not included in this workflow. We'll create the CommandLineTool in the next step.
62+
63+
## Creating the CommandLineTool
64+
Now let's create the gdal_calc.py CommandLineTool. This CommandLineTool will perform the actual NDVI calculation using the GDAL library.
65+
66+
Here's what the CommandLineTool YAML file should look like:
67+
68+
````yaml
69+
cwlVersion: v1.0
70+
class: CommandLineTool
71+
baseCommand: gdal_calc.py
72+
inputs:
73+
input_raster:
74+
type: File
75+
inputBinding:
76+
position: 1
77+
ndvi_raster:
78+
type: File
79+
outputBinding:
80+
glob
81+
outputs:
82+
ndvi_raster:
83+
type: File
84+
outputBinding:
85+
glob: $(inputs.ndvi_raster.basename).tif
86+
arguments:
87+
- $(inputs.input_raster.path)
88+
- --outfile=$(inputs.ndvi_raster.path)
89+
- --calc="(B05 - B04) / (B05 + B04)"
90+
- --type=Float32
91+
````
92+
93+
Let's break down each part of the CommandLineTool:
94+
95+
* `inputs`: This section specifies the input to the CommandLineTool. In this case, we have two inputs, input_raster and ndvi_raster. input_raster is the Sentinel-2 scene in GeoTIFF format, and ndvi_raster is the output NDVI raster in GeoTIFF format.
96+
* `outputs`: This section specifies the output of the CommandLineTool. In this case, we have one output, ndvi_raster, which is the NDVI raster in GeoTIFF format.
97+
* `arguments`: This section specifies the arguments to the gdal_calc.py command. We pass the input raster, specify the output file using the --outfile option, specify the NDVI calculation using the --calc option, and set the output data type to Float32 using the --type option.
98+
99+
Packaging the Application
100+
Now that we've created the workflow and the CommandLineTool, let's package them into an EO application package.
101+
102+
The EO application package should have the following structure:
103+
104+
````kotlin
105+
.
106+
├── cwl
107+
│ ├── ndvi_calculation.cwl
108+
│ └── gdal_calculation.cwl
109+
├── data
110+
│ └── sentinel_scene.tif
111+
└── README.md
112+
````
113+
114+
* `cwl`: This directory contains the CWL files for the workflow and the CommandLineTool.
115+
* `data`: This directory contains the Sentinel-2 scene used as input.
116+
* `README.md`: This file contains instructions on how to use the EO application package.
117+
118+
Here's what the README.md file could look like:
119+
120+
````yaml
121+
# EO Application Package for calculating the NDVI from Sentinel-2
122+
123+
This EO application package calculates the NDVI from Sentinel-2 data using the Common Workflow Language (CWL).
124+
125+
## Prerequisites
126+
127+
To run this EO application package, you'll need:
128+
129+
- A CWL runner installed on your machine. We recommend using `cwltool`, which can be installed using `pip`.
130+
- Access to Sentinel-2 data. You can download Sentinel-2 data from the Copernicus Open Access Hub: https://scihub.copernicus.eu/dhus/#/home or directly from your Ellip account
131+
132+
## Usage
133+
134+
1. Download the EO application package from GitHub: https://github.com/yourusername/eo-app-ndvi-sentinel2
135+
2. Extract the package to a directory of your choice.
136+
3. Change to the directory where you extracted the package.
137+
4. Run the following command to execute the workflow:
138+
`cwltool cwl/ndvi_calculation.cwl data/sentinel_scene.tif`
139+
140+
This will calculate the NDVI from the `sentinel_scene.tif` input and output the NDVI raster as `sentinel_scene.ndvi.tif`.
141+
142+
# License
143+
144+
This EO application package is licensed under the MIT License. See the LICENSE file for more information.
145+
146+
````
147+
148+
## Conclusion
149+
In this tutorial, we created an EO application package that calculates the NDVI from Sentinel-2 data using CWL. We created a CWL workflow and a CommandLineTool that performs the actual calculation, and packaged them into an application package. The application package includes instructions on
150+
151+
152+
153+

0 commit comments

Comments
 (0)