Exercise 6#
Deadline
Please complete this exercise by the end of day on Thursday, 19 December, 2024 (the day before next week’s work session).
Help us improve the course!
By providing course feedback, help us improve this course for the following years: course feedback form
To start this assignment, accept the GitHub classroomassignment, and clone your own repository, e.g., in a CSC Noppe instance. Make sure you commit and push all changes you make (you can revisit instructions on how to use git
and the JupyterLab git-plugin on the website of the Geo-Python course.
To preview the exercise without logging in, you can find the open course copy of the course’s GitHub repository at github.com/Automating-GIS-processes-II-2024/Exercise-6. Don’t attempt to commit changes to that repository, but rather work with your personal GitHub classroom copy (see above).
Hints#
Division by zero in raster calculation#
When working with raster files or bands, one of the quickest ways to upset the mathematical gods of Python is to divide by zero. It’s like giving Python a riddle it can’t solve—it just throws its hands up (and an error). To avoid this, you can replace the zero values with NaN
. This way, Python knows how to handle NaN
s . Here’s an example:
# Avoid division by zero by setting NDVI to NaN where NIR + Red is zero
NDVI = NDVI.where((nir_data + red_data) != 0)
[ ]: