Commit a9914d30 authored by Carl Schreck's avatar Carl Schreck

Tweaked the default map plotting in cjs. Also working version of temp_steps.py for imke.

parent ec005fec
......@@ -16,20 +16,12 @@ import numpy as np
import gzip
import cjs # '~carl/lib/python'
def draw_station_data(path, lat_column=1, lon_column=2, data_column=5,
def draw_station_data(ax, path, lat_column=1, lon_column=2, data_column=5,
norm=None, cmap=None):
cjs.tstamp(f'Reading {path}')
asc_data = pd.read_csv(path, sep=' ', header=None, skipinitialspace=True)
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)
cjs.add_conus_map(ax=ax)
lat = asc_data[lat_column]
lon = asc_data[lon_column]
......@@ -39,21 +31,12 @@ def draw_station_data(path, lat_column=1, lon_column=2, data_column=5,
transform=ccrs.PlateCarree(), marker='.')
return plot
def draw_station_type(path, lat_column=1, lon_column=2, time_column=6,
norm=None, cmap=None):
def draw_station_type(ax, path, lat_column=1, lon_column=2, time_column=6):
cjs.tstamp('Reading')
print(path)
asc_data = pd.read_csv(path, sep=' ', header=None, skipinitialspace=True)
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=30, usa_only=True)
cjs.add_conus_map(ax)
lat = asc_data[lat_column]
lon = asc_data[lon_column]
......@@ -75,7 +58,7 @@ def draw_station_type(path, lat_column=1, lon_column=2, time_column=6,
ax.plot(group.lon, group.lat, transform=ccrs.PlateCarree(),
marker='.', linestyle='', label=labels[type_ind],
zorder=zorders[type_ind], c=colors[type_ind])
ax.legend(labels=labels)
ax.legend(labels=labels, loc='lower right')
return asc_data
......
""" Draw the steps for one temperature variable. """
__author__ = "Carl Schreck"
__email__ = "cjschrec@ncsu.edu"
__copyright__ = "Copyright 2020, North Carolina State University"
__license__ = "BSD-3.0"
import xarray as xr
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.cm as cm
import os
import argparse
import numpy as np
import cartopy.crs as ccrs
import cjs # '~carl/lib/python'
import helpers
# These are some parameters that could be useful to have up top
parser = argparse.ArgumentParser()
parser.add_argument('--var_name', default='tmin')
args = parser.parse_args()
var_name = args.var_name
time = '1989-02-03'
base_path = f'{os.environ["DATA_DIR"]}/nclimgrid/imke_figures/02temp-steps/'
station_path = f'{base_path}{var_name.upper()}19890203map.txt'
unscaled_path = f'{base_path}{var_name.upper()}_19890203_D6_A2.pnt.gz'
scaled_path = f'{base_path}{var_name.upper()}-198902-grd-scaled.nc'
levels = np.arange(-30, 35, 5)
cmap = cm.get_cmap('bwr', lut=(len(levels) + 1))
norm = mpl.colors.BoundaryNorm(levels, cmap.N, clip=False)
cjs.tstamp('Here we go!')
fig, ax = plt.subplots(nrows=2, ncols=2,
subplot_kw={'projection': cjs.conus_projection})
cjs.tstamp('Drawing station type')
helpers.draw_station_type(ax[0, 0], station_path)
ax[0, 0].set_title('a) Station type')
cjs.tstamp('Drawing station data')
helpers.draw_station_data(ax[0, 1], station_path, norm=norm, cmap=cmap)
ax[0, 1].set_title('b) Station data')
cjs.tstamp('Drawing unscaled data')
plt.gca().outline_patch.set_visible(False)
unscaled_data = helpers.read_unscaled(unscaled_path, var_name)
cjs.add_conus_map(ax=ax[1, 0])
plot = unscaled_data.plot(ax=ax[1, 0], transform=ccrs.PlateCarree(),
add_colorbar=False,
cmap=cmap, norm=norm, zorder=2)
ax[1, 0].set_title('c) Unscaled data')
cjs.tstamp('Drawing scaled data')
scaled_ds = xr.open_dataset(scaled_path)
scaled_data = scaled_ds[var_name].sel(time=time).drop('time')
cjs.add_conus_map(ax=ax[1, 1])
plot = scaled_data.plot(ax=ax[1, 1], transform=ccrs.PlateCarree(),
add_colorbar=False,
cmap=cmap, norm=norm, zorder=2)
ax[1, 1].set_title('d) Scaled data')
cjs.tstamp('Add colorbar')
fig.subplots_adjust(bottom=0.2)
cbar_ax = fig.add_axes([0.15, 0.05, 0.80, 0.03])
fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), extend='both',
cax=cbar_ax,
orientation='horizontal')
cjs.tstamp('Drawing')
plt.savefig(f'figures/{var_name}_steps.png')
plt.show()
cjs.tstamp('Thank you, come again.')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment