Quiz: Normalized difference vegetation index in Python

In this quiz, you want to develop an open-source Python application that is capable of calculating the normalized difference vegetation index (NDVI). This application should take one 4-band (R, G, B, and NIR) GeoTIFF file, calculate its NDVI, and save it as a GeoTIFF file. For testing, use m_3408350_nw_17_060_20191023.tif. Submit your Python script in FirstLastname_ndvi.py.

Allowed modules:

Penalties:

Grading: -3 per debugged line up to the total points per question

1   Read the red and NIR bands of a GeoTIFF file as NumPy arrays

16 points

Using the GDAL module, open band 1 and read its content as an array into r. Repeat this process using band 4 for nir.

2   Normalize the red and NIR arrays

16 points

Normalize the r and nir arrays such that they range from 0 to 1.

3   Calculate the NDVI

16 points

Using the following equation, calculate ndvi. \[\text{NDVI} = \frac{\text{NIR} - R}{\text{NIR} + R}\]

4   Save the NDVI as a single-band GeoTIFF file

16 points

Using the GDAL module, save the ndvi array as a single-band GeoTIFF file into C:\tmp\ndvi.tif. The output file should properly be georeferenced using the geotransform matrix from the input GeoTIFF file.

5   Plot the NDVI

16 points

Using the matplotlib.pyplot submodule, plot ndvi.

ndvi.png

6   Create a GUI

20 points

Using the PySimpleGUI module, create a GUI for your NDVI calculator. Remove any hard-coded input and output file paths for any previous questions.

gui.png

7   Solutions

If you cannot solve any specific questions, you may use my solution files and move to the next one. In this case, you’ll lose the total points for the skipped question(s). To avoid downloads by mistake, you should’ve received the download password. There will be no excuse for downloading any solutions by accident.

Questions skippedLoss of pointsSolution
1161_read_r_nir.py
2162_normalize_r_nir.py
3163_calculate_ndvi.py
4164_save_ndvi.py
5165_plot_ndvi.py
6206_gui.py
1–23212_normalize_r_nir.py
1–348123_calculate_ndvi.py
1–4641234_save_ndvi.py
1–58012345_plot_ndvi.py
1–6100123456_gui.py