Mapping#

Map data onto a geographic map!

geographic keywords#

For geographic annotations, there are these keywords:

ahlive keyword

type

scope

description

crs

str

subplot

the data’s projection coordinate reference system (crs)

projection

str

subplot

the desired output crs

central_lon

float

subplot

the desired longitude in degrees to center on

borders

bool

subplot

whether to show country borders

coastline

bool

subplot

whether to show coastlines

tiles

bool

subplot

whether to show tiles

zoom

int

subplot

zoom level of tiles

land

bool

subplot

whether to show land

ocean

bool

subplot

whether to show ocean

lakes

bool

subplot

whether to show lakes

rivers

bool

subplot

whether to show rivers

states

bool

subplot

whether to show US states’ borders

worldwide

bool

subplot

whether to set to global extents

reference crs#

To utilize any geographic annotations, pass crs OR projection as an instantiated cartopy.crs object the class name.

crs specifies the data’s coordinate reference system; it’s often set to ccrs.PlateCarree(), or conveniently 'platecarree', if the data is in degrees.

[1]:
import xarray as xr
import ahlive as ah
ds = xr.tutorial.open_dataset('air_temperature').isel(time=slice(0, 3))
ah_ds = ah.Dataset(ds, 'lon', 'lat', 'air', crs='platecarree')
ah_ds.render()

Hi!
I am the author of pygifsicle , which you use in this Notebook.
I hope my work has saved you some time!
I love to code, but I also need coffee. Please sponsor me on GitHub ❤️
Good luck in your coding 🍀!
- Luca

[1]:

projection crs#

projection on the other hand specifies the desired output crs. If crs is not specified, but projection is set, crs defaults to ccrs.PlateCarree().

[2]:
import xarray as xr
import ahlive as ah
ds = xr.tutorial.open_dataset('air_temperature').isel(time=slice(0, 3))
ah_ds = ah.Dataset(ds, 'lon', 'lat', 'air', projection='lambertconformal')
ah_ds.render()
[2]:
[3]:
import xarray as xr
import ahlive as ah
import cartopy.crs as ccrs
import cartopy.feature as cfeature

ds = xr.tutorial.open_dataset("air_temperature").isel(time=slice(0, 3))
ah_ds = ah.Dataset(
    ds,
    "lon",
    "lat",
    "air",
    projection=ccrs.Orthographic(central_latitude=25, central_longitude=-88),
    coastline=cfeature.COASTLINE.with_scale("50m"),
)
ah_ds.render()
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/50m_physical/ne_50m_coastline.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/50m_physical/ne_50m_coastline.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
[3]:

geographic features#

After setting either crs or projection, geographic features can be toggled.

[4]:
import xarray as xr
import ahlive as ah
ds = xr.tutorial.open_dataset('air_temperature').isel(time=slice(0, 3))
ah_ds = ah.Dataset(
    ds, 'lon', 'lat', 'air', projection='lambertconformal',
    land=True, ocean=True, borders=True, states=True)
ah_ds.render()
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_physical/ne_110m_land.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_physical/ne_110m_land.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_physical/ne_110m_ocean.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_physical/ne_110m_ocean.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_admin_0_boundary_lines_land.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_admin_0_boundary_lines_land.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/ahlive-1.0.4.post1+dirty-py3.11.egg/ahlive/animation.py:1759: UserWarning: Failed to render state=2 due to unpack requires a buffer of 8 bytes!
  warnings.warn(error_msg)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_admin_1_states_provinces_lakes.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/cartopy/io/__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/110m_cultural/ne_110m_admin_1_states_provinces_lakes.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
[4]:

worldwide view#

worldwide can be set to view the data on a global extent.

[5]:
import xarray as xr
import ahlive as ah
ds = xr.tutorial.open_dataset('air_temperature').isel(time=slice(0, 3))
ah_ds = ah.Dataset(
    ds, 'lon', 'lat', 'air', projection='robinson', worldwide=True)
ah_ds.render()
[5]:

central longitude#

The central_lon is automatically set to the median longitude of the data, but can be set manually.

[6]:
import xarray as xr
import ahlive as ah
ds = xr.tutorial.open_dataset('air_temperature').isel(time=slice(0, 3))
ah_ds = ah.Dataset(
    ds, 'lon', 'lat', 'air',
    projection='robinson', worldwide=True, central_lon=0)
ah_ds.render()
[6]:

tiles and zoom#

Web tiles can also be retrieved; click here for a listing of available tiles.

[7]:
import ahlive as ah
arr = ah.Array(
    [-88, -88.2, -88.5], [40, 40.5, 40.05], tiles="OSM", zoom=9
).config("tiles", style="toner")
arr.render()
/home/docs/checkouts/readthedocs.org/user_builds/ahlive/conda/latest/lib/python3.11/site-packages/cartopy/io/img_tiles.py:116: UserWarning: Cartopy created the following directory to cache GoogleWTS tiles: /tmp/cartopy_cache_dir/OSM
  warnings.warn(
gifsicle: warning: trivial adaptive palette (only 215 colors in source)
[7]: