Commit 9b8ec8f6 authored by Carl Schreck's avatar Carl Schreck

New normalization for scatter plots and new test figures for imke.

parent d75b58c9
......@@ -17,7 +17,7 @@ import gzip
import cjs # '~carl/lib/python'
def draw_station_data(ax, path, lat_column=1, lon_column=2, data_column=5,
norm=None, cmap=None):
levels=None, cmap=None):
cjs.tstamp(f'Reading {path}')
asc_data = pd.read_csv(path, sep=' ', header=None, skipinitialspace=True)
......@@ -27,9 +27,9 @@ def draw_station_data(ax, path, lat_column=1, lon_column=2, data_column=5,
lon = asc_data[lon_column]
data = asc_data[data_column]
plot = ax.scatter(x=lon, y=lat, c=data, norm=norm, cmap=cmap, zorder=2,
transform=ccrs.PlateCarree(), marker='.',
edgecolors='black')
plot = ax.scatter(x=lon, y=lat, c=data, norm=cjs.norm_scatter(levels),
cmap=cmap, zorder=2, transform=ccrs.PlateCarree(),
marker='.', edgecolors='black', linewidth=0.5)
return plot
def draw_station_type(ax, path, lat_column=1, lon_column=2, time_column=6):
......
......@@ -29,8 +29,8 @@ 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)
# cmap = cm.get_cmap('bwr', lut=(len(levels) + 1))
cmap = 'RdBu_r'
cjs.tstamp('Here we go!')
......@@ -42,17 +42,16 @@ ax.set_title('a) Station type')
plt.savefig(f'figures/{var_name}_station_type.png')
ax.set_title('b) Station data')
plt.savefig(f'figures/{var_name}_scaled.png')
cjs.tstamp('Drawing unscaled data')
fig, ax = plt.subplots(nrows=1, ncols=1,
subplot_kw={'projection': cjs.conus_projection})
helpers.draw_station_data(ax, station_path, norm=norm, cmap=cmap)
helpers.draw_station_data(ax, station_path, levels=levels, cmap=cmap)
unscaled_data = helpers.read_unscaled(unscaled_path, var_name)
plot = unscaled_data.plot(ax=ax, transform=ccrs.PlateCarree(),
add_colorbar=True,
cmap=cmap, norm=norm, zorder=1)
cmap=cmap, levels=levels, zorder=1,
vmin = -np.inf, vmax = np.inf, extend = 'both',
)
ax.set_title('c) Unscaled data')
ax.set_extent([-100.0, -80.0, 30.0, 40.0])
plt.savefig(f'figures/{var_name}_unscaled.png')
......@@ -60,12 +59,14 @@ plt.savefig(f'figures/{var_name}_unscaled.png')
cjs.tstamp('Drawing scaled data')
fig, ax = plt.subplots(nrows=1, ncols=1,
subplot_kw={'projection': cjs.conus_projection})
helpers.draw_station_data(ax, station_path, norm=norm, cmap=cmap)
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')
plot = scaled_data.plot(ax=ax, transform=ccrs.PlateCarree(),
add_colorbar=True,
cmap=cmap, norm=norm, zorder=1)
cmap=cmap, levels=levels, zorder=1,
vmin=-np.inf, vmax=np.inf, extend='both'
)
ax.set_title('d) Scaled data')
ax.set_extent([-100.0, -80.0, 30.0, 40.0])
plt.savefig(f'figures/{var_name}_scaled.png')
......@@ -73,15 +74,15 @@ plt.savefig(f'figures/{var_name}_scaled.png')
cjs.tstamp('Drawing difference data')
levels = np.arange(-6, 7, 1)
cmap = cm.get_cmap('bwr', lut=(len(levels) + 1))
norm = mpl.colors.BoundaryNorm(levels, cmap.N, clip=False)
fig, ax = plt.subplots(nrows=1, ncols=1,
subplot_kw={'projection': cjs.conus_projection})
cjs.add_conus_map(ax=ax)
diff_data = scaled_data - unscaled_data
plot = diff_data.plot(ax=ax, transform=ccrs.PlateCarree(),
add_colorbar=True,
cmap=cmap, norm=norm, zorder=1)
cmap=cmap, levels=levels, zorder=1,
vmin = -np.inf, vmax = np.inf, extend = 'both',
)
ax.set_title('d) Scaled minus unscaled')
ax.set_extent([-100.0, -80.0, 30.0, 40.0])
plt.savefig(f'figures/{var_name}_diff_zoom.png')
......@@ -92,15 +93,16 @@ fig, ax = plt.subplots(nrows=1, ncols=1,
cjs.add_conus_map(ax=ax)
diff_data = scaled_data - unscaled_data
plot = diff_data.plot(ax=ax, transform=ccrs.PlateCarree(),
add_colorbar=True,
cmap=cmap, norm=norm, zorder=1)
add_colorbar=True,
cmap=cmap, levels=levels, zorder=1,
extend='both', vmin=-np.inf, vmax=np.inf)
ax.set_title('d) Scaled minus unscaled')
plt.savefig(f'figures/{var_name}_diff_wide.png')
# 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',
# fig.colorbar(cm.ScalarMappable(levels=levels, cmap=cmap), extend='both',
# cax=cbar_ax,
# orientation='horizontal')
#
......
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