Lambert projection

Introduction

This module is aimed at using the Lambert Conformal Conic (LCC) projection in the same way as in Matlab or NCL. To use this projection in Basemap, you must provide the coordinates of the lower-left and upper right corners, which you don’t necessaryly know. In Matlab and NCL, this projection is initialised by providing the western and eastern longitudes, and the southern and northern latitudes. The lambert module allows to mimic this behaviour. Furthermore, it is not possible to use a masked projection in Basemap. This drawback is sorted out here.

Initialisation

As a first step, you need to initialise the nbtools.map.Lambert class, which is done by providing the domain coordinates:

from nbtools.map import Lambert

lon1=-80;lon2=30;lat1=20;lat2=80
lamb=Lambert(lon1,lon2,lat1,lat2)

During the initialisation, the lamb.lonmin, lamb.lonmax, lamb.latmin, lamb.latmax are set, which contains the western and eastern longitudes, and the southern and northern latitudes (used as arguments). The lamb.hemisphere attribute, which defines whether we are in the southern or northern hemisphere, is also created.

Note

The domain used in a LCC projection cannot cross the equator. Therefore, the lamb.latmin and lamb.latmax attributes must have the same sign.

During this initialisation phase, a mpl_toolkits.basemap.Basemap object, lamb.bmap, is also created, which you now can use to draw your map backgrounds (map grid, coastlines, filled continents, map backgrounds, etc).

Masking

A classical way to display LCC maps is to mask the map outside the domain boundaries. In this module, this is achieved by overlaying a dummy pcolor plot on top the map (transparent colors inside the domain, background colors outside). This is achieved by a call to the nbtools.map.Lambert.make_mask() function as follows:

lamb.make_mask()

Warning

Doesn’t work properly when saving PDF files

Map labels on masked LCC

Because of the way masking is achieved, map labels cannot be achieved by using the native Basemap functions. This is done by using the nbtools.map.Lambert.add_lc_labels() function (adapted from NCL) as follows:

lamb.add_lc_labels()

Example


# Example of using masked Lambert Projections

import pylab as plt
from nbtools.map import Lambert
import numpy as np

# defining plotting options
plt.rcParams['text.usetex'] = False
plt.rcParams['font.size'] = 9
plt.rcParams['lines.linewidth'] = 0.5

fig = plt.figure()
plt.subplots_adjust(hspace=0.0, wspace=0.15)

# defining nothern projection
lon1 = -80
lon2 = 30
lat1 = 20
lat2 = 80
lamb = Lambert(lon1, lon2, lat1, lat2)

ax = plt.subplot(2, 2, 1)
lamb.bmap.etopo()
lamb.bmap.drawcoastlines(color='k', linewidth=0.5)
lamb.bmap.drawparallels(np.arange(lat1, lat2+10, 10), labels=[1, 0, 0, 0])
lamb.bmap.drawmeridians(np.arange(lon1, lon2+20, 20), labels=[0, 0, 0, 1])

ax = plt.subplot(2, 2, 3)
lamb.bmap.etopo()
lamb.bmap.drawcoastlines(color='k', linewidth=0.5)
lamb.bmap.drawparallels(np.arange(lat1, lat2+10, 10), labels=[0, 0, 0, 0])
lamb.bmap.drawmeridians(np.arange(lon1, lon2+20, 20), labels=[0, 0, 0, 0])
lamb.make_mask()
lamb.add_lc_labels(spacelon=20, spacelat=10, fontsize=6)

# generating southern projection
lat1 = -80
lat2 = -20
lamb = Lambert(lon1, lon2, lat1, lat2)

ax = plt.subplot(2, 2, 2)
lamb.bmap.fillcontinents(color='lightgray')
lamb.bmap.drawcoastlines(color='k', linewidth=0.5)
lamb.bmap.drawparallels(np.arange(lat1, lat2+10, 10), labels=[0, 1, 0, 0])
lamb.bmap.drawmeridians(np.arange(lon1, lon2+20, 20), labels=[0, 0, 1, 0])

ax = plt.subplot(2, 2, 4)
lamb.bmap.fillcontinents(color='lightgray')
lamb.bmap.drawcoastlines(color='k', linewidth=0.5)
lamb.bmap.drawparallels(np.arange(lat1, lat2+10, 10), labels=[0, 0, 0, 0])
lamb.bmap.drawmeridians(np.arange(lon1, lon2+20, 20), labels=[0, 0, 0, 0])
lamb.make_mask()
lamb.add_lc_labels(spacelon=20, spacelat=10, fontsize=6)

plt.savefig('figure_lambert.png', bbox_inches='tight')
_images/figure_lambert.png