Commit 7c06b250 authored by Carl Schreck's avatar Carl Schreck

Fixed standardize teleconnections and updates multi-maps

parent 938ec554
......@@ -18,7 +18,7 @@ cjs.tstamp('Here we go!')
# These are some parameters that could be useful to have up top
# mpl.use('Agg')
year = 2020
month = 1
month = datetime.today().month - 1
days_in_month = calendar.monthrange(year, month)[1]
start_day = 1
delta_days = 5
......@@ -110,7 +110,7 @@ for first_day, last_day in zip(first_days, last_days):
os.makedirs(f'figures/prcp-pon/', exist_ok=True)
plt.savefig(f'figures/prcp-pon/prcp-pon-{year}-{month:02}{first_day:02}'
f'-{month:02}{last_day:02}.png', dpi=200)
f'-{month:02}{last_day:02}.png', dpi=100)
# plt.show()
plt.close()
......
......@@ -42,7 +42,7 @@ for telecon_name in telecon_names:
data = cjs.download_year_month_day_data(remote_path, local_path,
clobber=clobber,
standarize=True,
standarize='daily',
clim_range=clim_range)
ds = ds.assign({telecon_name: data})
......@@ -65,7 +65,7 @@ plt.xlim(sub_ds.time[0], sub_ds.time[-1])
plt.title(f'Standardized teleconnection amplitudes\n'
f' {calendar.month_name[month]} {year}')
plt.ylabel('Standard Deviations')
plt.ylim(-4, 4)
# plt.ylim(-4, 4)
plt.legend(labels=[f'{x.upper()}: '
f'{monthly_std_data[x].sel(time=time_range.stop).values:.1f}'
......
......@@ -18,13 +18,9 @@ cjs.tstamp('Here we go!')
# These are some parameters that could be useful to have up top
# mpl.use('Agg')
year = 2020
month = 1
month = datetime.today().month - 1
days_in_month = calendar.monthrange(year, month)[1]
start_day = 1
delta_days = 1
first_days = np.arange(start_day, days_in_month - delta_days + 2, 1)
last_days = np.arange(start_day + delta_days - 1, days_in_month + 1, 1)
cjs.tstamp('Downloading')
file_type = 'scaled'
......@@ -42,73 +38,78 @@ if download_err:
f'{year}/{month:02}/{file_name}')
download_err = cjs.download_file(ftp_path, in_path, clobber=True)
for first_day, last_day in zip(first_days, last_days):
time_range = slice(f'{year}-{month:02}-{first_day:02}',
f'{year}-{month:02}-{last_day:02}')
cjs.tstamp(f'{first_day} -- {last_day}')
cjs.tstamp('Read and average totals')
total_ds = xr.open_dataset(in_path)
dayofyear = total_ds.time.sel(time=time_range).dt.dayofyear
total_data = total_ds['tavg'].sel(time=time_range).mean(dim='time')
cjs.tstamp('Read and average climatology')
clim_path = f'{os.environ["DATA_DIR"]}/nclimgrid/beta/tavg.clim.1981.2010.nc'
clim_ds = xr.open_dataset(clim_path)
clim_data = clim_ds['tavg'].sel(dayofyear=dayofyear.values).mean(
dim='dayofyear')
cjs.tstamp('Anomalize')
anom_data = (total_data - clim_data) * 9 / 5
cjs.tstamp('Draw map')
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.tstamp('Draw data')
levels = list(np.arange(-5,6)*3)
plot = anom_data.plot(ax=ax, transform=ccrs.PlateCarree(),
cmap='RdBu_r', levels=levels, zorder=2, extend='both',
vmin=-np.inf, vmax=np.inf,
cbar_kwargs={'orientation': 'horizontal',
'label': 'Degrees Fahrenheit',
'pad': 0.0})
plot.colorbar.set_ticklabels(levels)
plot.colorbar.set_ticks(levels)
cjs.tstamp('Add labels')
date_string = f'{calendar.month_name[month]} {first_day}-{last_day} {year}'
plt.text(0.5, 1.11, 'Mean Temperature Departures from Average',
fontsize=14, ha='center', transform=ax.transAxes)
plt.text(0.5, 1.05, date_string,
fontsize=11, ha='center', transform=ax.transAxes)
plt.text(0.5, 1.00, 'Average Period: 1981-2010',
fontsize=9, ha='center', transform=ax.transAxes)
plt.text(1.1, -0.25, 'Data Source: 5km Gridded\n'
'(nClimGrid-Daily) Beta',
fontsize=7, ha='right', transform=ax.transAxes)
today_string = (f'{datetime.now().strftime("Created: %a %b %d %Y")}\n'
f'{file_type.capitalize()} data')
plt.text(-0.1, -0.25, today_string,
fontsize=7, ha='left', transform=ax.transAxes)
cjs.tstamp('Save figure')
plt.tight_layout()
os.makedirs(f'figures/tave-anom/', exist_ok=True)
plt.savefig(f'figures/tave-anom/tave-anom-{year}-{month:02}{first_day:02}'
f'-{month:02}{last_day:02}.png', dpi=200)
# plt.show()
plt.close()
for delta_days in [1, 5]:
first_days = np.arange(start_day, days_in_month - delta_days + 2, 1)
last_days = np.arange(start_day + delta_days - 1, days_in_month + 1, 1)
for first_day, last_day in zip(first_days, last_days):
time_range = slice(f'{year}-{month:02}-{first_day:02}',
f'{year}-{month:02}-{last_day:02}')
cjs.tstamp(f'{first_day} -- {last_day}')
cjs.tstamp('Read and average totals')
total_ds = xr.open_dataset(in_path)
dayofyear = total_ds.time.sel(time=time_range).dt.dayofyear
total_data = total_ds['tavg'].sel(time=time_range).mean(dim='time')
cjs.tstamp('Read and average climatology')
clim_path = f'{os.environ["DATA_DIR"]}/nclimgrid/beta/tavg.clim.1981.2010.nc'
clim_ds = xr.open_dataset(clim_path)
clim_data = clim_ds['tavg'].sel(dayofyear=dayofyear.values).mean(
dim='dayofyear')
cjs.tstamp('Anomalize')
anom_data = (total_data - clim_data) * 9 / 5
cjs.tstamp('Draw map')
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.tstamp('Draw data')
levels = list(np.arange(-5,6)*3)
plot = anom_data.plot(ax=ax, transform=ccrs.PlateCarree(),
cmap='RdBu_r', levels=levels, zorder=2, extend='both',
vmin=-np.inf, vmax=np.inf,
cbar_kwargs={'orientation': 'horizontal',
'label': 'Degrees Fahrenheit',
'pad': 0.0})
plot.colorbar.set_ticklabels(levels)
plot.colorbar.set_ticks(levels)
cjs.tstamp('Add labels')
date_string = f'{calendar.month_name[month]} {first_day}-{last_day} {year}'
plt.text(0.5, 1.11, 'Mean Temperature Departures from Average',
fontsize=14, ha='center', transform=ax.transAxes)
plt.text(0.5, 1.05, date_string,
fontsize=11, ha='center', transform=ax.transAxes)
plt.text(0.5, 1.00, 'Average Period: 1981-2010',
fontsize=9, ha='center', transform=ax.transAxes)
plt.text(1.1, -0.25, 'Data Source: 5km Gridded\n'
'(nClimGrid-Daily) Beta',
fontsize=7, ha='right', transform=ax.transAxes)
today_string = (f'{datetime.now().strftime("Created: %a %b %d %Y")}\n'
f'{file_type.capitalize()} data')
plt.text(-0.1, -0.25, today_string,
fontsize=7, ha='left', transform=ax.transAxes)
cjs.tstamp('Save figure')
plt.tight_layout()
os.makedirs(f'figures/tave-anom/', exist_ok=True)
plt.savefig(f'figures/tave-anom/tave-anom_{delta_days}-{year}'
f'-{month:02}{first_day:02}'
f'-{month:02}{last_day:02}.png', dpi=100)
# plt.show()
plt.close()
cjs.tstamp('Thank you, come again.')
This diff is collapsed.
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