Using baseplot for Ploting Geographical Coordinates

Basemap is a great tool for creating maps using python in a simple way. It’s a matplotlib extension, so it has got all its features to create data visualizations, and adds the geographical projections and some datasets to be able to plot coast lines, countries, and so on directly from the library [1].

In this article I demonstrate the usage of basemap for a particular use case. I will use a historical weather data from the Global Historical Climatology Network. Their archives contain (among other things) lists of weather observations from various weather stations formatted as CSV files like this:

 US1FLSL0019,20130101,PRCP,0,,,N,
 US1FLSL0019,20130101,SNOW,0,,,N,
 US1TXTV0133,20130101,PRCP,30,,,N,
 USC00178998,20130101,TMAX,-22,,,7,0700
 USC00178998,20130101,TMIN,-117,,,7,0700
 USC00178998,20130101,TOBS,-28,,,7,0700
 USC00178998,20130101,PRCP,0,T,,7,0700
 USC00178998,20130101,SNOW,0,T,,7,
 USC00178998,20130101,SNWD,0,,,7,
 USC00242347,20130101,TMAX,6,,,7,0800

The fields are the weather station; the date (Jan 1 2013 in these lines); the observation (min/max temperature, amount of precipitation, etc); the value (an integer); and four more columns we won’t use. The readme file in the archive explains the fields in detail. We will worry about the min and max temperature (TMIN, TMAX) which are given as °C × 10.

For this article, I have downloaded a few data files and uploaded into my google drive. The weather data spans a period from 2000 – 2016 and covers many stations around the globe. There are many possible questions to study. Use a python plotting library of your choice, such as matplotlib.

Installing Basemap

The first task is to install basemap. As I will demonstrate all the visualization using a Jupyter notebook, I installed the basemap using conda. The following command on the command line should work.

shanto@shanto:~$ $ conda install basemap

However, after this installation was done, I could not import basemap and it was giving some error. I found the following solution, which worked perfectly.

shanto@shanto:~$ conda install -c conda-forge basemap
Solving environment: done

## Package Plan ##

  environment location: /home/shanto/anaconda3

  added / updated specs: 
    - basemap

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    certifi-2017.11.5          |           py36_0         195 KB  conda-forge
    openssl-1.0.2n             |                0         3.5 MB  conda-forge
    ca-certificates-2017.11.5  |                0         145 KB  conda-forge
    basemap-1.1.0              |           py36_3        15.4 MB  conda-forge
    pyproj-1.9.5.1             |           py36_0         3.4 MB  conda-forge
    geos-3.6.2                 |                1        19.9 MB  conda-forge
    pyshp-1.2.12               |             py_0          22 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        42.5 MB

The following NEW packages will be INSTALLED:

    pyproj:          1.9.5.1-py36_0             conda-forge
    pyshp:           1.2.12-py_0                conda-forge

The following packages will be UPDATED:

    basemap:         1.0.7-np113py36_0                      --> 1.1.0-py36_3     conda-forge
    ca-certificates: 2017.08.26-h1d4fec5_0                  --> 2017.11.5-0      conda-forge
    certifi:         2017.7.27.1-py36h8b7b77e_0             --> 2017.11.5-py36_0 conda-forge
    geos:            3.5.0-0                                --> 3.6.2-1          conda-forge
    openssl:         1.0.2l-h9d1a558_3                      --> 1.0.2n-0         conda-forge

Proceed ([y]/n)? y

Downloading and Extracting Packages
certifi 2017.11.5: ##################################################### | 100% 
openssl 1.0.2n: ######################################################## | 100% 
ca-certificates 2017.11.5: ############################################# | 100% 
basemap 1.1.0: ######################################################### | 100% 
pyproj 1.9.5.1: ######################################################## | 100% 
geos 3.6.2: ############################################################ | 100% 
pyshp 1.2.12: ########################################################## | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
shanto@shanto:~$ 

Now I can import basemap and everything should work fine. Let’s move to the problem.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s