Skip to content

Instantly share code, notes, and snippets.

@robintw
Created July 21, 2016 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robintw/127ceac799d03e68af2a687e1be0b30f to your computer and use it in GitHub Desktop.
Save robintw/127ceac799d03e68af2a687e1be0b30f to your computer and use it in GitHub Desktop.
Steps I took:
1. Download as .py from the Jupyter Notebook
2. Delete the irrelevant comments with In [3], etc
3. Deleted the gdalInfo bit from the very top - not needed
4. Ran autopep8 on the file to format it nicely (from a terminal: autopep8 -i FILENAME)
5. Tidied up geoloc function (rename xml to geoloc_xml for clarity)
6. Actually decided that the warp and geoloc functions could be combined as they're both very small. Created a new function called `geolocate_and_warp`.
7. Tidied up the line breaks and spacing, and removed extra brackets around the content of the `warp` function (not sure why they were there...)
8. Decided that the geolocate_and_warp function should take two parameters: input_filename and output_filename - then we can call the output whatever we want and store it wherever we want.
9. Added a docstring to the geolocate_and_warp function.
10. Decided it was a good idea to add a configurable output co-ordinate system to the function, so we could run it for other areas and produce output in the Indian National Grid (or whatever) rather than OSGB. I've done this as a 'default argument' so that it assumes OSGB unless you tell it otherwise - look at the beginning of the function for how I've done that.
11. Moved the bit for getting the list of filenames from glob down to put it next to the for loop, so it's clearer where filenames are coming from.
12. Created a preprocess_MAIAC function to put all of the filenames stuff and loop stuff in. Very helpfully you've already created the input_folder, output_folder etc variables, so I just used arguments with those names.
13. Gradually went through the code in this new function, cleaning it up, adding comments etc. Specifically, I:
a) Created a variable called 'output_basename', which is the sort of 'base' filename that we add other bits on to get filenames that we actually use. So, when we have blah/blah/blah/trfhsfregsh_proj.tif this is all of the bit before the _proj.tif
b) Decided that we want to be sure we know what our output files contain, as we will create both AOT and PM2.5 ones - so instead of using _proj.tif I used _projAOT.tif
14. Commented out the gdal.Translate lines at the top of the file, or they would execute every time we ran 'import FILENAME'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment