quick_map.py 1.12 KB
Newer Older
Carl Schreck's avatar
Carl Schreck committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
""" Draw a quick map of data in a file."""

__author__ = "Carl Schreck"
__email__ = "cjschrec@ncsu.edu"
__copyright__ = "Copyright 2020, North Carolina State University"
__license__ = "BSD-3.0"

import xarray as xr
import os
from matplotlib import pyplot as plt
import cartopy.crs as ccrs
import cjs # '~carl/lib/python'

cjs.tstamp('Here we go!')
# These are some parameters that could be useful to have up top
16
17
path = f'{os.environ["DATA_DIR"]}/prism/netcdf/PRISM_tmax_198101.nc'
var_name = 'tmax'
Carl Schreck's avatar
Carl Schreck committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

ds = xr.open_dataset(path)

ax = plt.axes(projection=ccrs.AlbersEqualArea(central_longitude=360-95,
                                              standard_parallels=(40,60)))
plt.gca().outline_patch.set_visible(False)
ax.set_extent([-118, -75, 23.5, 50.5])

shp_name = 'ne_10m_admin_1_states_provinces_lakes'
cjs.add_map(ax, shp_name, edgecolor='none', facecolor='silver', zorder=1,
            usa_only=True)
cjs.add_map(ax, shp_name, edgecolor=(0.2, 0.2, 0.2), facecolor='none', zorder=3,
            usa_only=True)

ds[var_name].isel(time=0).plot(ax=ax, zorder=2, transform=ccrs.PlateCarree())
plt.show()

cjs.tstamp('Thank you, come again.')