Assignment 01
Spatial interpolation
Deadline is 2022-11-29 17:00
Late submission? 10% will be removed for each day that you are late.
This is an individual assignment.
- What you are given to start
- What you have to do
- Good to know
- Marking
- What to submit and how to submit it
The aim of this assignment is to implement (part of) four interpolation methods used for modelling terrains:
- nearest neighbour [NN]
- one variant of IDW [IDW]
- linear interpolation in TIN (based on a Delaunay triangulation) [TIN]
- natural neighbour interpolation [NNI]
You have to complete the 4 functions given and they should return the interpolated value (or specific exceptions, see below).
What you are given to start
Code is in the /hw/01/
folder of the GitLab repository of the course.
We give you the skeleton of the Python program:
geo1015_hw01.py
is the main(). You are not allowed to modify this file! This main reads the fileparams.json
, calls the interpolation functions inmycode_hw01.py
, and creates a raster file (which you can view in QGIS; use it to test/visualise your solutions).mycode_hw01.py
is where all your code should go. The 4 functions defined there must be completed, and you are not allowed to change the input parameters. You are of course allowed to add any other functions you want in that unit (please do not include any other unit you code, add your code to that single file). You are only allowed to import modules from the Python standard library (anything you installed throughpip
is thus not allowed, except scipy, numpy, and startinpy).raster.py
contains the classRaster
, which is used to store the array of elevation and has a write function to export to a text file.params.json
: a very simple JSON file that defines what the input file is, which interpolation methods to execute, with what parameters, and where to store the output.samples.xyz
: an example of an input file with sample points. All input files that the program reads will be like this one: a CSV file with headers (x y z), each line is one point, and the delimiters between x y z is a space.- the folder
/other-samples
contains some areas with part of a GeoTIFF raster file we took somewhere, and we generated randomly samples from it insamples.xyz
To run the code you need to install the following libraries:
pip install numpy
pip install scipy
pip install startinpy
What you have to do
You have to write the code for the 4 functions in mycode_hw01.py
.
Each function returns the z-value (as a float) of the estimation of the elevation.
However, if the (x, y)-coordinates are outside the convex hull of the input points, then the functions need to throw an Exception: raise Exception("Outside convex hull")
.
For IDW, if there are no points inside the search radius, then: raise Exception("No point in search radius")
.
Good to know
- the file
mycode_hw01.py
gives you hints, read its content - each of the 4 functions receives as input parameters the scipy kd-tree (
kd
) and the startinpy Delaunay triangulation (dt
), it is up to you to decide which one(s) you need to implement the function - the time it takes for your program to terminate has no influence on the marks you’ll get
- what is a kd-tree actually? Read quickly the Section 12.2 of the book, details are not important now (they will be later in the quarter however)
- you do not need to code yourself the Delaunay triangulator: you have to use startinpy. Study its docs
- you are not allowed to use directly the builtin functions in startinpy for the interpolation, you have to code them yourself
- the marking will be automatic, I will test your
mycode_hw01.py
with several of my inputs (others than those given) and verify whether you return the correct values and handle all the cases
Marking
Criterion | Points |
---|---|
followed all rules and compiles/runs without modifications | 1 |
nn interpolation | 1 |
idw interpolation | 2 |
tin interpolation | 2 |
natural neighbour interpolation | 4 |
What to submit and how to submit it
You have to submit one file: my_code_hw01.py
where your name and student number is clearly identified at the top.
Oh, and no report is necessary.
Upload the file to this Dropbox page.
[last updated: 2022-11-17 08:21]