Geospatial Python – Intermediate – Image Classification

Hello!

These are the joining instructions for the GRSG Geospatial Python – Intermediate – Image Classification – virtual course

GRSG

Pre-Course

To really get the value from this day course it would be good to have

a) had 1-2 years experience with Python. and

b) some experience with Geospatial Python

If you cannot write for loops, understand data types, conditional statements etc then this course will not be suitable for you.

I understand and appreciate that everyone has their own unique computer setup. This is something that can cause Python users some problems. It can be confusing.

https://m.xkcd.com/1987/

Because of this I recommend you install Anaconda. However you can use your own setup if you prefer.

Recommended Python Set up (Windows)

Important please check before course starts

I recommend using Anaconda https://www.anaconda.com/download/ This course is for Python 3

You may need to open the Anaonda Prompt as an Administrator, by doing this it should remove any permission errors. Right click and select Run As Administrator.

If you can type ‘python’ into a the anaconda prompt then you should be good to go

type exit() to leave the Python environment and return to the command prompt. It will look like

(base) your directory (eg C:/users/…)

To install gdal (the most critical step).

conda install -c conda-forge gdal

It may take a while eventually you will get a prompt asking whether you wish to install, select Y (for yes) and press enter.

Update May 2020. If you area having problems installing gdal I have found on Windows OS and Mac OS in a anaconda environment these commands will work

conda config --set allow_conda_downgrades true
conda install conda=4.6.14
conda install -c conda-forge gdal

Please also install the following packages

sklearn install

conda install -c anaconda scikit-learn

skimage install

conda install -c anaconda scikit-image (you don’t need to install this for the classification course)

raster stats install

conda install -c conda-forge rasterstats

scipy install

conda install -c anaconda scipy

rasterio install

conda install -c anaconda rasterio

GeoPandas install

conda install -c conda-forge geopandas

Shapely install (we will not be using this on this course, but it is well worth installing)

conda install -c conda-forge shapely

Open an anaconda prompt and check that gdal is installed

type

python

then…

from osgeo import gdal,ogr

(shown below)

type exit() to leave the Python environment

Anaconda comes pre cooked with jupyter notebook

type (you might wish to change directory, for example, to the root of  D: first – cd d:)

jupyter notebook

into the command prompt and it should open up a web browser within your directory of all your folder/files and notebooks.


I have written two detailed blog posts that should be of help if you have any issues

and

I will cover Jupyter Notebooks in this course, so you don’t need to read this post.

Further useful software

  1. Notepad ++ https://notepad-plus-plus.org/
  2. OSGeo4W for QGIS https://trac.osgeo.org/osgeo4w/

A note on Mac installation.

I run this course on a Windows 10 machine. If you need to install gdal on a Mac then I have been told that the following commands work:

Firstly:

conda install -c conda-forge/label/cf201901 gdal

I think that ensures gdal is correctly installed.

Secondly:

gdalinfo –version

To check I had gdal on the system

Thirdly:

conda install krb5

Apparently this is a dependency of gdal but isn’t installed by default.

I don’t have access to a Mac so please let me know if this doesn’t work (I am not sure what will work if it doesn’t)

Update May 2020. If you area having problems installing gdal I have found on Windows OS and Mac OS in a anaconda environment these commands will work

conda config --set allow_conda_downgrades true
conda install conda=4.6.14
conda install -c conda-forge gdal

Please attempt to install gdal prior to attending the course, it is not fair on the other attendees if you don’t have a working installation and we have to spend time getting you setup. On the virtual courses we will meet for an hour the day before to ensure you are up and working. We will NOT spend anytime on the day with setup.


Course Data

I run the course through a folder on my computer. I suggest you create a folder on your machine

D:\GRSG_Course_Classification

Please download the course data data_package.zip (approx 24mb)

Extract this to

D:\GRSG_Course_Classification\data_package

Code

I will make the course code available the day before the course. I would like you to try and follow the examples as we go, but don’t worry about mistakes this is all good practice.

Challenges

Throughout the course as our learning progresses I have created a couple of challenges. These are to aid your learning, help you practice. The aim is to experiment try new things.

Structure

Morning (start 10am)

  • Rasterio, read/write and manipulate data
  • Masking satellite images using Shapefiles

Break

  • Extract image boundary from Satellite data
  • Using K-Means for unsupervised image classification

Lunch

  • Part 1 preparing data for supervised machine learning using Scikit-learn
  • Part 2 using Scikit-learn for machine learning on satellite data

Break

  • Using Rasterstats to extract zonal information
  • Geopandas
  • Recap

End 4:00pm