In which you apply the skills that you have learned so far to start your climb out of the desert of despair!
Your first assessment is a race around the world! Specifically, I want you to:
Using
data/natural_earth/ne_10m_admin_0_countries.shp
, write an algorithm that can calculate the shortest international border in the world as quickly as possible, and draw me a lovely map of it.
For the purposes of this analysis, we will define an international border as: a shared boundary between two countries that can be crossed from one country to another.
Your code should be accompanied by a report of up to 1,000 words describing your process and discussing your result.
Make sure that you read this whole document before you start!
Contents
Rules of Engagement
Submission
This work must be submitted by 14:00 on Thursday 7th November 2024 (Week 7).
You must submit your code and a report of up to up to 1,000 words in length describing the choices that you made in order to create an accurate and efficient algorithm. Code snippets can be used in the report where appropriate (once again, not included in the word count) - but remember that I do not just want a line by line description of your code (that is what your comments are for)!
Note that you must submit your assessment as described here - not having read the below instructions will not be accepted as a reason for late or incorrect submission
- The Code part of your submission must be compressed into a
.zip
(not *.rar or any other format) file and submitted via a Dropbox File Request: - links provided below. The filename should be named using your student number in the format123456789.zip
. Please note that the same Dropbox should be used even if you have an extension. - The Report part of your submission must be submitted as usual via the Turnitin on the Assessment page of the Blackboard site. The report should contain the map(s) that you have produced. Submitted files should be named in the format:
123456789.docx
or123456789.pdf
etc.
Code Template
In order to assess the efficiency of your algorithm, I need to be able to time how long your code takes to execute the task. Accordingly, you must use the below template for your code, and ALL of your code must be between the # NO CODE ABOVE HERE
and # NO CODE BELOW HERE
comments.
"""
Understanding GIS: Assessment 1
@author [INSERT STUDENT NUMBER HERE]
Calculate the length of the World's Shortest Border, as fast as possible
"""
from time import time
# set start time
start_time = time() # NO CODE ABOVE HERE
'''ALL CODE MUST BE INSIDE HERE'''
# report runtime
print(f"completed in: {time() - start_time} seconds") # NO CODE BELOW HERE
In addition to this, please do not use any libraries that are not already available within the understandinggis
anaconda environment.
Zip File Structure
Remember that your submission must include all files that are required for your code to run successfully must be included (otherwise your code won’t work!).
I would recommend the following file structure within your main Assessment folder:
- assessment1/
- 123456789.py
- data/
- ne_10m_admin_0_countries.shp
- ne_10m_admin_0_countries.dbf
- ne_10m_admin_0_countries.prj
- ne_10m_admin_0_countries.shx
- [any other data files you might need]
- out/
- shortest_border.png
It is also important thet all of your file paths are relative file paths (e.g. ./data/ne_10m_admin_0_countries.shp
). If you use absolute file paths (e.g. C:/jimbob/understandingis/assessment1/data/ne_10m_admin_0_countries.shp
) then your code will not work when I run it!
A good way to ensure that this has worked is to either:
- write your code in a new directory that is not inside your
understandinggis
directory - this will avoid accidentally pointing to the wrong version of your datasets (i.e. the one that you use in the practicals)
or:
- write your code inside your
understandinggis
directory as normal, then just before submission extract your zip file to a location elsewhere on your machine and test to see if it still works
If you don’t know how to zip a folder, you can see how to do so here:
Please make sure that you use .zip
format (as per the instructions) - and not other forms of compression (e.g. .rar
, .tar
, .gz
, .7z
etc.).
Some Pointers
This assessment has been designed in order to combine the skills and knowledge that you have learned over the course so far, including:
- Producing a Map and selecting an appropriate CRS
- Calculating and measuring the length of a border
- Making a spatial analysis as efficient as possible
- Demonstrating an understanding of issues that might affect the veracity of your result
From a Python perspective, it will give you an opportunity to utilise skills such as: variables, lists, loops, conditional statements, functions and so on.
The intention is that, by having the opportunity to apply your knowledge to a project in this way, you will more fully understand what we have been doing, and be better positioned to move into the second part of the course.
Remember, you have generic examples of all of the major operations that we have covered available in the Hints page, and the solutions for all of the previous practicals are available on the Solutions page. If you get stuck, you can get help via the forum!
Pseudocode
Remember the golden rule: Don’t Panic! You have done almost every part of this assessment in the course already, this is just a matter of finding the right bits and putting them together!
Conceptually, this is not too difficult a question to answer. You just need to think like a programmer and break it down into small tasks (all of which you have done before…). For example you could break it down into something along the lines of the following process:
start your timer
loop through each country (country_a):
loop through each country (country_b):
if there is a border between country_a and country_b:
calculate and measure the length of the border
if the length is the smallest so far so far:
store the length, both countries and the border
draw a map of the resulting countries and border
end your timer and print the result
Not too complicated, right? All you need to do is keep breaking down each stage into smaller and smaller jobs until you have a clear idea of how the program should look (think back to our session on computational thinking).
Do not be daunted by this assessment, there is nothing here that you haven’t done before! Just take a deep breath and start planning it out like I have taught you. Remember - if something seems too complicated, break it down into increasingly small steps - the smaller the steps, the easier solution!
Code Presentation
Broadly speaking, your code should be presented in the following form:
import
statements- functions
- main code
You code should be well commented (remember the rule of thirds!) and do not leave in any unnecessaary testing material, such as print()
statements that do not contribute to the user experience.
Also make sure that you are using all of the libraries that you have imported - if you import a lot of unnecessary libraries, this demonstrates poor understanding, as well as slowing down your code!
Error Messages
Remember, when you get an error message in the console, it is not the computer telling you off or making fun of you - it is trying to help you! If you read it carefully it will tell you both what the problem is and even which line of code is causing it - so don’t get upset when you get a lot of errors, find the line of code that is causing the problem, read the description (Paste it into Google if you don’t understand it) and see if you can solve it - you’ll probably find that in most cases you can!
It is also worth remembering that the error message is extremely unlikely to be incorrect (though it can have been caused by another problem just above it); and it is extremely unlikely that there is an error in one of the libraries in the understandinggis
environment. If, for example, it says it can’t find a file and you are sure that it’s there, then either your file path or the working directory (top right hand corner of Spyder) is wrong.
The fact is, programming is 20% writing code and 80% debugging it. This doesn’t change as you get more experienced, the errors just get more complicated!!
Hints & Tips
- This is not like an essay that you can bash out the night before - the longer you give yourself to complete this, the easier you will make it for yourself.
- Pay attention to the TYPE (
.geom_type
) of geometry that you extract from countries. - Look back to the lectures and practical material, and make use of the Hints and Solutions pages.
- When designing your CRS, you might also find this
geopandas
function worth investigating. In either case, the justification of your choice is the most important thing! - When explaining what you are doing - remember that I am more interested in your solution (i.e., what you are doing and why) than your implementation (i.e., which library or function you used). For example - if you used a spatial index I would like to know what it does and why this is helpful, not that you used a particular function from the
rtree
library. - If you do feel like you are starting to panic - don’t suffer in silence - let me know!
Marking Criteria
Assessment 1 is worth 40% of the final grade for the course.
Marks will be given based upon:
- The quality of the report (35% of assignment grade), including:
- A Justification for any key methodological choices that were made (benefits and limitations) in the design of both the algorithm and the map. This is not a line by line description of your code (your comments do this), just an explanation of why you chose any key elements that contributed to the elegance, efficiency or robustness of this algorithm; and the quality of the map. As above (see Hints & Tips) you should focus on the solution (the Geographical Information Science) rather than the implementation (specific libraries and functions) when describing what you have done.
- A discussion on the Limitations of your analysis, including a clear demonstration of the understanding of the Geographical Information Science involved in these decisions (i.e. what factors affect the measurement of international borders?)
- A justification of your chosen CRS.
- In all of the above, you would expect clear links to the material that we have covered in class - so think carefully!
- The quality of the algorithm (35% of assignment grade), including:
- Efficiency (the speed with which your algorithm resolves the problem)
- Robustness (the script will not fail if it encounters ’normal’ problems, such as incorrect file paths, missing data, unexpected inputs, and so on).
- The quality of the code (20% of assignment grade), including:
- Neatness and Elegance (the script is well written and well presented)
- Comments (demonstrating a thorough understanding of the approaches that you have used)
- The cartographic quality of the resulting map(s) (10% of assignment grade), including:
- Aesthetic quality and readability
- Selection (and justification) of a suitable projection
The key to this is in the name of the course: In both your code and report I want you to demonstrate a clear Understanding of what you have done - this is why comments are so important in your code!