Mapping#
Map data onto a geographic map!
geographic keywords#
For geographic annotations, there are these keywords:
ahlive keyword |
type |
scope |
description |
---|---|---|---|
|
|
subplot |
the data’s projection coordinate reference system (crs) |
|
|
subplot |
the desired output crs |
|
|
subplot |
the desired longitude in degrees to center on |
|
|
subplot |
whether to show country borders |
|
|
subplot |
whether to show coastlines |
|
|
subplot |
whether to show tiles |
|
|
subplot |
zoom level of tiles |
|
|
subplot |
whether to show land |
|
|
subplot |
whether to show ocean |
|
|
subplot |
whether to show lakes |
|
|
subplot |
whether to show rivers |
|
|
subplot |
whether to show US states’ borders |
|
|
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()
[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/main/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/main/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/main/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/main/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/main/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/main/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/main/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/main/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/main/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/main/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/main/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]: