This page demonstrates Python tips and tricks that I use in my everyday programming as an atmospheric science graduate student.
-Brian Blaylock

Thursday, May 30, 2019

RAP and HRRR model domain boundaries

I made a neat map of the RAP (version 4) and HRRR model domain boundaries with Cartopy. I think it looks nice...


Tuesday, May 21, 2019

Cartopy: add NEXRAD mosaic image to figure

This Notebook shows how I add NEXRAD mosaic images from Iowa State University to my Cartopy maps...

https://github.com/blaylockbk/pyBKB_v3/blob/master/BB_maps/cartopy_NEXRAD-mosaic-from-Iowa.ipynb


Slowly, like a sloth, I'm using cartopy more and more.

Monday, May 20, 2019

Add an ArcGIS Map Service Image to a Cartopy axes.

I am a very slow Cartopy adopter. I learned Basemap years ago and am very comfortable with it and continue to hold tight to what I know. However, as I dabble more with Cartopy, I can see how it is superior.

For the last two years, one of my many reasons for sticking with Basemap despite almsot everyone telling me to stop, that the ease of adding arcGIS images as a map background. In Basemap, it is a simple m.arcgisimage(service='World_Shaded_Relief'). It took me a long time and many attempts to figure out how to do this in Cartopy. It does take a few extra steps, but it is possible, and even without the ease of use, I am now believe Cartopy does this better than Basemap.

In Basemap, you are limited to adding arcGIS images to cylindrical projection, but in Cartopy you can add these images to any projection. Incredible!

See the full notebook here, https://github.com/blaylockbk/pyBKB_v3/blob/master/BB_maps/cartopy_arcgisimage.ipynb.


Additional Resources:

NOTE: When you set the extent with ax.set_extent, the images are fine until you cross the prime meridian, then the images are distorted as if there aren't enough tiles. The only way I've been able to prevent this is to keep the image in the same projection as the tiles, a.k.a. the Mercator projection (see the second stack overflow answer linked above).

import cartopy.io.img_tiles as cimgt

fig=plt.figure(figsize=(10,5))
ax = fig.add_subplot(1,1,1, projection=ccrs.PlateCarree())
ax.coastlines()

url = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer/tile/{z}/{y}/{x}.jpg'

image = cimgt.GoogleTiles(url=url)

ax.add_image(image, 1)