Skip to main content

Publication quality maps using Earth Engine and Cartopy!

Project description

cartoee

Publication quality maps using Earth Engine and Cartopy! alt-text

Installation

cartoee is available to install via pip. To install the package, you can use pip install for your Python environment:

pip install cartoee

Or, you can install the package manually from source code using the following commands:

git clone https://github.com/kmarkert/cartoee.git
cd cartoee
pip install -e .

Working with cartoee

cartoee aims to do only one thing well: getting processing results from Earth Engine into a publication quality mapping interface. cartoee simply gets results from Earth Engine and plots it with the correct geographic projections leaving ee and cartopy to do more of the processing and visualization.

A simple case

Here is what a simple workflow looks like to visualize SRTM data on a map:

import cartoee as cee
import ee

ee.Initialize()

# get an earth engine image
srtm = ee.Image("CGIAR/SRTM90_V4")

# plot the result using cartoee
ax = cee.plot(srtm,region=[-180,-90,180,90],visParams={'min':0,'max':3000})

ax.coastlines()
plt.show()

alt-text

Now that we have our EE image as a cartopy/matplotlib object, we can start styling our plot for the publication using the cartopy API.

import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LATITUDE_FORMATTER, LONGITUDE_FORMATTER

# set gridlines and spacing
xticks = [-180,-120,-60,0,60,120,180]
yticks = [-90,-60,-30,0,30,60,90]
ax.gridlines(xlocs=xticks, ylocs=yticks,linestyle='--')

# set custom formatting for the tick labels
ax.xaxis.set_major_formatter(LONGITUDE_FORMATTER)
ax.yaxis.set_major_formatter(LATITUDE_FORMATTER)

# set tick labels
ax.set_xticks([-180,-120,-60, 0, 60, 120, 180], crs=ccrs.PlateCarree())
ax.set_yticks([-90, -60, -30, 0, 30, 60, 90], crs=ccrs.PlateCarree())

alt-text

Doing more...

Now that we have a grasp on a simple example, we can use Earth Engine to to some processing and make a pretty map.

# function to add NDVI band to imagery
def calc_ndvi(img):
    ndvi = img.normalizedDifference(['Nadir_Reflectance_Band2','Nadir_Reflectance_Band1'])
    return img.addBands(ndvi.rename('ndvi'))

# MODIS Nadir BRDF-Adjusted Reflectance with NDVI band
modis = ee.ImageCollection('MODIS/006/MCD43A4')\
        .filterDate('2010-01-01','2016-01-01')\
        .map(calc_ndvi)

# define color ramp for visualization
cb = 'd73027,fc8d59,fee08b,ffffbf,d9ef8b,91cf60,1a9850'

# get the cartopy map with EE results
ax = cee.plot(modis.mean(),
    visParams={'min':-0.5,'max':0.85,'bands':'ndvi','palette':cb},
    region=[-180,-90,180,90])
ax.coastlines()

alt-text

You can see from the example that we calculated NDVI on MODIS imagery from 2010-2015 and created a global map with the mean value per pixel.

What if we want to make multiple maps with some different projections? We can do that by creating our figure and supplying the axes to plot on.

# get land mass feature collection
land = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')

# get seasonal averages and clip to land features
djf = modis.filter(ee.Filter.calendarRange(12,3,'month')).mean().clip(land)
mam = modis.filter(ee.Filter.calendarRange(3,6,'month')).mean().clip(land)
jja = modis.filter(ee.Filter.calendarRange(6,9,'month')).mean().clip(land)
son = modis.filter(ee.Filter.calendarRange(9,12,'month')).mean().clip(land)

fig,ax = plt.subplots(ncols=2,nrows=2,subplot_kw={'projection': ccrs.Orthographic(-80,35)})

imgs = np.array([[djf,mam],[jja,son]])
titles = np.array([['DJF','MAM'],['JJA','SON']])

for i in range(len(imgs)):
  for j in range(len(imgs[i])):
      ax[i,j] = cee.plot(imgs[i,j],region=[-180,-90,180,90],
                         visParams={'min':-0.5 ,'max':0.85,'bands':'ndvi','palette':cb},
                         dims=500,axes=ax[i,j])
      ax[i,j].coastlines()
      ax[i,j].gridlines(linestyle='--')
      ax[i,j].set_title(titles[i,j])

alt-text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cartoee-0.0.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

cartoee-0.0.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file cartoee-0.0.1.tar.gz.

File metadata

  • Download URL: cartoee-0.0.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for cartoee-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ee12797d3dad3cf9ad1f7859a10ed8597d49e204c5fbe7420630714eff506cf2
MD5 274c301adae65d57cdc22869de34a972
BLAKE2b-256 72c1e016754c760c18afd967b7bb1d3bb63ba7c2efbd0cc8cbf493123012dd7c

See more details on using hashes here.

File details

Details for the file cartoee-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: cartoee-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for cartoee-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 971d31e4e36b3ca36980339e0d57e6284f2bd2d384fb2d77742da1b804103899
MD5 7570f9d3c9b2a2b21d3cbe1a0ee4499d
BLAKE2b-256 5e5c4ca060064de49ddcf4c77588c9277014d498ecccaf93acd4013c0ff18407

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page