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

Added the categories to the precip_step

parent 59795b18
......@@ -7,6 +7,9 @@ __license__ = "BSD-3.0"
import xarray as xr
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from matplotlib import cm
import matplotlib.patches as mpatches
import os
import numpy as np
import cartopy.crs as ccrs
......@@ -24,117 +27,108 @@ scaled_path = f'{base_path}{var_name}-201809-grd-scaled.nc'
extent = [-85.0, -75.0, 32.0, 38.0]
central_longitude = np.mean(extent[0:2])
precip_levels = [0.5, 1, 5, 10, 25, 50, 75, 100, 150, 200]
precip_levels = [0.1, 0.5, 1, 5, 10, 25, 50, 75, 100, 150, 200]
occur_levels = np.arange(0.1, 1.0, 0.1)
cmap = 'GnBu'
tif_name = 'MSR_50M'
cmap = cm.get_cmap('GnBu')
newcolors= cmap(np.linspace(0, 1, 256))
newcolors[0] = [1, 1, 1, 1]
precip_cmap = mcolors.ListedColormap(newcolors)
cat_cmap = mcolors.ListedColormap(cjs.tab_2016[:4])
cjs.tstamp('Here we go!')
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(6.4, 8.0),
fig, axs = plt.subplots(nrows=3, ncols=1, figsize=(6.4, 8.0),
subplot_kw={
'projection': ccrs.AlbersEqualArea(
central_longitude=central_longitude),
'anchor': 'N'
'anchor': 'W'
})
cjs.tstamp('Drawing anusplin occurrence')
ax = axs[0,0]
helpers.draw_station_data(ax, station_path, levels=0.1, cmap=cmap,
cjs.tstamp('Drawing anusplin categories')
ax = axs[0]
helpers.draw_station_data(ax, station_path, levels=0.1, cmap=precip_cmap,
data_column=6)
anu_occur_path = f'{base_path}BPRC_20180914_D6_A2.pnt.gz'
anu_occur_data = helpers.read_unscaled(anu_occur_path, var_name, data_column=5)
sph_occur_path = f'{base_path}BPRC_20180914_D6_S1.pnt.gz'
sph_occur_data = helpers.read_unscaled(sph_occur_path, var_name, data_column=2)
plot = anu_occur_data.plot(ax=ax, transform=ccrs.PlateCarree(),
add_colorbar=False,
cmap=cmap, levels=occur_levels, zorder=1,
vmin=-np.inf, vmax=np.inf, extend='both',
)
sph_occur_data.plot.contour(ax=ax, transform=ccrs.PlateCarree(),
levels=[0.9], zorder=2,
colors='magenta')
anu_occur_data.plot.contour(ax=ax, transform=ccrs.PlateCarree(),
levels=[0.4], zorder=2,
colors='darkorange')
ax.set_title(f'(a) Anusplin occurrence', loc='left')
ax.set_extent(extent)
ax.outline_patch.set_visible(True)
categories = anu_occur_data * 0
categories += np.where(anu_occur_data > 0.4, 0, 1)
categories += np.where(sph_occur_data > 0.9, 0, 2)
cjs.tstamp('Drawing spheremap occurrence')
ax = axs[0,1]
helpers.draw_station_data(ax, station_path, levels=0.1, cmap=cmap,
data_column=6)
plot = sph_occur_data.plot(ax=ax, transform=ccrs.PlateCarree(),
add_colorbar=False,
cmap=cmap, levels=occur_levels, zorder=1,
vmin=-np.inf, vmax=np.inf, extend='both',
)
sph_occur_data.plot.contour(ax=ax, transform=ccrs.PlateCarree(),
levels=[0.9], zorder=2,
colors='magenta')
anu_occur_data.plot.contour(ax=ax, transform=ccrs.PlateCarree(),
levels=[0.4], zorder=2,
colors='darkorange')
ax.set_title(f'(b) Spheremap occurrence', loc='left')
plot = categories.plot(ax=ax, transform=ccrs.PlateCarree(),
add_colorbar=False, levels=[0.5, 1.5, 2.5],
cmap=cat_cmap)
ax.set_title(f'(a) Occurrence', loc='left')
ax.set_extent(extent)
ax.outline_patch.set_visible(True)
fig.colorbar(plot, ax=axs[0, :], shrink=0.6, orientation='horizontal',
anchor=(0.5, 1.0),
label='Probability of precipitation')
labels = ['ANUSPLIN < 0.4, Spheremap < 0.9',
'ANUSPLIN < 0.4, Spheremap > 0.9',
'ANUSPLIN > 0.4, Spheremap < 0.9',
'ANUSPLIN > 0.4, Spheremap > 0.9',
]
# proxy = [plt.Rectangle((0,0), 1, 1, fc=cat_color)
# for cat_color in cat_cmap.colors]
patches = [mpatches.Patch(color=color) for color in cat_cmap.colors]
ax.legend(patches, labels,
bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)
cjs.tstamp('Drawing anusplin precip')
ax = axs[1,0]
helpers.draw_station_data(ax, station_path, levels=precip_levels, cmap=cmap,
data_column=6)
ax = axs[1]
helpers.draw_station_data(ax, station_path, levels=precip_levels,
cmap=precip_cmap, data_column=6)
anusplin_path = f'{base_path}{var_name.upper()}_20180914_D6_A2.pnt.gz'
anusplin_data = helpers.read_unscaled(anusplin_path, var_name, data_column=5)
plot = anusplin_data.plot(ax=ax, transform=ccrs.PlateCarree(),
add_colorbar=False,
cmap=cmap, levels=precip_levels, zorder=1,
cmap=precip_cmap, levels=precip_levels, zorder=1,
vmin=-np.inf, vmax=np.inf, extend='both',
)
# anusplin_data.plot.contour(ax=ax, transform=ccrs.PlateCarree(),
# levels=[0.1], zorder=2,
# colors='black')
sph_occur_data.plot.contour(ax=ax, transform=ccrs.PlateCarree(),
levels=[0.9], zorder=2,
colors='magenta')
anu_occur_data.plot.contour(ax=ax, transform=ccrs.PlateCarree(),
levels=[0.4], zorder=2,
colors='darkorange')
ax.set_title(f'(c) Anusplin Precipitation', loc='left')
# sph_occur_data.plot.contour(ax=ax, transform=ccrs.PlateCarree(),
# levels=[0.9], zorder=2,
# colors='magenta')
# anu_occur_data.plot.contour(ax=ax, transform=ccrs.PlateCarree(),
# levels=[0.4], zorder=2,
# colors='darkorange')
ax.set_title(f'(b) Anusplin Precipitation', loc='left')
ax.set_extent(extent)
ax.outline_patch.set_visible(True)
cjs.tstamp('Drawing scaled data')
ax = axs[1,1]
helpers.draw_station_data(ax, station_path, levels=precip_levels, cmap=cmap,
data_column=6)
ax = axs[2]
helpers.draw_station_data(ax, station_path, levels=precip_levels,
cmap=precip_cmap, data_column=6)
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=False,
cmap=cmap, levels=precip_levels, zorder=1,
cmap=precip_cmap, levels=precip_levels, zorder=1,
vmin=-np.inf, vmax=np.inf, extend='both',
)
scaled_data.plot.contour(ax=ax, transform=ccrs.PlateCarree(),
levels=[0.1], zorder=2,
colors='black')
ax.set_title(f'(d) Scaled data', loc='left')
# scaled_data.plot.contour(ax=ax, transform=ccrs.PlateCarree(),
# levels=[0.1], zorder=2,
# colors='black')
ax.set_title(f'(c) Scaled data', loc='left')
ax.set_extent(extent)
ax.outline_patch.set_visible(True)
str_levels = [str(lev) for lev in precip_levels]
cb = fig.colorbar(plot, ax=axs[1, :], shrink=0.6, orientation='horizontal',
cb = fig.colorbar(plot, ax=axs[1:], shrink=0.6, orientation='vertical',
anchor=(0.5, 1.0),
label='Precipitation (mm)')
cb.ax.set_xticklabels(str_levels)
cb.set_ticks(precip_levels)
cb.set_ticklabels(str_levels)
cjs.tstamp('Drawing figure')
......
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