Today's exercises have to be done with help of the python standard library alone! No external module can be used.
SRTM is a digital elevation model at ~90 m resolution covering almost the entire globe (up to $\pm$ 60° latitude). The data is organized in 5°x5° tiles. To see a map of the tiles have a look at this download page. This tool is nice to use if you know which tile you want, but not very useful if you want more than one tile at different places of the globe.
Fortunately, the entire dataset is available on this server: http://srtm.csi.cgiar.org/SRT-ZIP/SRTM_V41/SRTM_Data_GeoTiff/
In order to protect from naive "download all" behavior, the files stored here cannot be listed (i.e. automated data scraping won't work). Fortunately for us , the file naming convention is very simple:
Here are some examples of locations and their associated tile:
And so forth.
A. Write a script which, given a longitude and a latitude as arguments, downloads the corresponding file in the current directory. The function should raise an error when the given location is not valid.
Hint 1: define "valid" locations first: some are easy to catch, some cannot be caught automatically. Do we really have to deal with those?
Hint 2: unlike last week where we asked for user input, here I'm asking for a script with command line arguments.
B. Extend this script to be a bit more clever: download the data file only if the file isn't already available in the current directory. This is particularly important because since last year their server has changed and the new one is much slower. Now you'd better not download the files two times...
C. Extend this script to be even more clever: given a range of longitudes and latitudes, it should download all the files covering this area. For example, the range 9°W to 18°W and 44°N to 47°N would download 6 files.
Note 1: we will have a look at the data later in the course. But If you want to display them now, you can open them with the qgis software for example.
Note 2: at the edge of the tiles (i.e. coordinates -175, 55) the problem might be not well defined because of accuracy errors (we will get back to these). You shouldn't care about this for now and try to get things right for everywhere but at the exact boundaries.
Note 3: you'll find numerous examples online for command line arguments. For example, here is my script call for the optional exercise C when called from ipython:
%run download_srtm.py 9 44 18 47
Back to the table of contents