Commit 8f936c37 authored by Carl Schreck's avatar Carl Schreck

Changed station_type from plot to scatter and added elevation panel to temp_steps.py

parent a95ad306
......@@ -32,10 +32,13 @@ def draw_station_data(ax, path, lat_column=1, lon_column=2, data_column=5,
marker='.', edgecolors='black', linewidth=0.5)
return plot
def draw_station_type(ax, path, lat_column=2, lon_column=3, time_column=7):
def draw_station_type(ax, path, sep=',', lat_column=2, lon_column=3,
time_column=7, markersize=[16, 4, 16, 4], edgecolor=None):
if np.isscalar(markersize):
markersize = np.full(4, markersize)
cjs.tstamp('Reading')
print(path)
asc_data = pd.read_csv(path, sep=',', header=None, skipinitialspace=True)
asc_data = pd.read_csv(path, sep=sep, header=None, skipinitialspace=True)
cjs.add_conus_map(ax)
......@@ -47,7 +50,7 @@ def draw_station_type(ax, path, lat_column=2, lon_column=3, time_column=7):
labels = ['RAWS', 'SNOTEL', 'NWS Midnight', 'NWS Morning']
zorders = np.array([4, 5, 6, 2]) + 5
colors = cjs.tab[[3, 2, 0, 1]]
markersize = [2, 1, 2, 1]
station_type = np.full(lat.shape, fill_value=3)
station_type = np.where(network == 'R', 0, station_type)
station_type = np.where(network == 'S', 1, station_type)
......@@ -57,10 +60,11 @@ def draw_station_type(ax, path, lat_column=2, lon_column=3, time_column=7):
df = pd.DataFrame(dict(lon=lon, lat=lat, station_type=station_type))
groups = df.groupby('station_type')
for type_ind, group in groups:
ax.plot(group.lon, group.lat, transform=ccrs.PlateCarree(),
marker='.', markersize=markersize[type_ind],
linestyle='', label=labels[type_ind],
zorder=zorders[type_ind], c=colors[type_ind])
ax.scatter(group.lon, group.lat, transform=ccrs.PlateCarree(),
marker='.', s=markersize[type_ind],
label=labels[type_ind],
zorder=zorders[type_ind], c=colors[type_ind],
edgecolor=edgecolor, linewidth=0.5)
# ax.legend(labels=labels, loc='upper center', bbox_to_anchor=[0.5, 0],
# ncol=2)
return None
......
......@@ -48,7 +48,7 @@ for ax, date in zip(axes[:,0], dates):
handles, labels = axes[2,0].axes.get_legend_handles_labels()
fig.legend(handles, labels, loc='lower center', ncol=4,
markerscale=10)
markerscale=5)
cjs.tstamp('Drawing figure')
plt.tight_layout()
......
......@@ -15,30 +15,34 @@ 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'
var_names = ['tmax', 'tmin']
var_name_to_long_name = {
'tmax': 'Maximum Temperature',
'tmin': 'Minimum Temperature',
}
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(-35, 15, 5)
# cmap = cm.get_cmap('bwr', lut=(len(levels) + 1))
extent = [-110.0, -101.0, 36.0, 42.0]
central_longitude = np.mean(extent[0:2])
levels = np.arange(-30, 10, 5)
cmap = 'BuPu_r'
tif_name = 'MSR_50M'
cjs.tstamp('Here we go!')
# for tif_name in ['SR_50M', 'MSR_50M', 'PRISMA_SR_50M', 'US_MSR']:
for tif_name in ['US_MSR']:
fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(6.4, 6.4),
subplot_kw={'projection': cjs.conus_projection, })
fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(6.4, 9.6),
subplot_kw={'projection': ccrs.AlbersEqualArea(
central_longitude=central_longitude)})
i = 0
for ax, var_name in zip(axes[:2], var_names):
cjs.tstamp('Drawing scaled data')
ax = axes
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'
helpers.draw_station_data(ax, station_path, levels=levels, cmap=cmap)
scaled_ds = xr.open_dataset(scaled_path)
scaled_data = scaled_ds[var_name].sel(time=time).drop('time')
......@@ -46,22 +50,42 @@ for tif_name in ['US_MSR']:
add_colorbar=True,
cmap=cmap, levels=levels, zorder=1,
vmin=-np.inf, vmax=np.inf, extend='both',
cbar_kwargs={'orientation': 'horizontal',
'label': '°C',
'pad': 0.05,
}
cbar_kwargs={'label': '°C',}
)
# ax.set_title('c) Scaled data', loc='left')
ax.set_extent([-120.0, -100.0, 35.0, 45.0])
ax.set_title(f'{cjs.number_to_letter(i)} '
f'{var_name_to_long_name[var_name]}',
loc='left')
ax.set_extent(extent)
ax.outline_patch.set_visible(True)
ax.set_anchor('N')
i += 1
# cjs.add_shaded_relief(ax, tif_name=tif_name)
trans_gray = cjs.add_shaded_relief(ax, tif_name=tif_name)
cjs.tstamp('Adding elevation plot')
ax = axes[2]
elev_path = f'{os.environ["DATA_DIR"]}/geography/elev.americas.5-min.nc'
elev_ds = xr.open_dataset(elev_path)
levels = np.arange(800, 3800, 100)
plot = elev_ds['data'][0].plot(ax=ax, transform=ccrs.PlateCarree(),
cmap='OrRd', add_colorbar=True, zorder=1,
levels=levels,
cbar_kwargs = {'label': 'm', }
)
helpers.draw_station_type(ax=ax, path=station_path, sep=' ',
lat_column=1, lon_column=2, time_column=6,
markersize=36, edgecolor='black')
ax.set_extent(extent)
ax.outline_patch.set_visible(True)
ax.set_anchor('N')
ax.set_title('c) Elevation and station type', loc='left')
ax.set_title('')
# ax.legend()
cjs.tstamp('Drawing figure')
plt.tight_layout()
plt.savefig(f'figures/{var_name}_steps.png', dpi=200)
plt.show()
cjs.tstamp('Drawing figure')
plt.tight_layout()
plt.savefig(f'figures/temp_steps.png', dpi=200)
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