Commit ed03b03f authored by Carl Schreck's avatar Carl Schreck

Starting to work on precip steps

parent 8f936c37
......@@ -75,11 +75,13 @@ def read_unscaled(path, var_name, lat_column=0, lon_column=1, data_column=4,):
'tmin': 'Minimum Temperature',
'tmax': 'Maximum Temperature',
'prcp': 'Precipitation',
'occr': 'Occurrence',
}
var_name_to_units = {
'tmin': 'degree_Celsius',
'tmax': 'degree_Celsius',
'prcp': 'Millimeters',
'occr': 'Probability'
}
with gzip.open(path, mode='rt') as f:
......
""" 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 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
time = '2018-09-14'
var_name = 'prcp'
base_path = f'{os.environ["DATA_DIR"]}/nclimgrid/imke_figures/04precip-steps' \
f'/option2-florence/'
station_path = f'{base_path}{var_name.upper()}-20180914-map.txt'
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])
levels = [0.5, 1, 5, 10, 25, 50, 75, 100, 150, 200, 250]
cmap = 'GnBu'
tif_name = 'MSR_50M'
cjs.tstamp('Here we go!')
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(6.4, 9.6),
subplot_kw={
'projection': ccrs.AlbersEqualArea(
central_longitude=central_longitude),
'anchor': 'N'
})
cjs.tstamp('Drawing anusplin precip')
ax = axes[0,0]
helpers.draw_station_data(ax, station_path, levels=levels, cmap=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=True,
cmap=cmap, levels=levels, zorder=1,
vmin=-np.inf, vmax=np.inf, extend='both',
cbar_kwargs={'label': 'mm',}
)
ax.set_title(f'(a) Anusplin Precipitation', loc='left')
ax.set_extent(extent)
ax.outline_patch.set_visible(True)
cjs.tstamp('Drawing scaled data')
ax = axes[1,1]
helpers.draw_station_data(ax, station_path, levels=levels, cmap=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=True,
cmap=cmap, levels=levels, zorder=1,
vmin=-np.inf, vmax=np.inf, extend='both',
cbar_kwargs={'label': 'mm',}
)
ax.set_title(f'(f) Scaled data', loc='left')
ax.set_extent(extent)
ax.outline_patch.set_visible(True)
cjs.tstamp('Drawing figure')
plt.tight_layout()
plt.savefig(f'figures/prcp_steps.png', dpi=200)
plt.show()
cjs.tstamp('Thank you, come again.')
......@@ -27,15 +27,18 @@ base_path = f'{os.environ["DATA_DIR"]}/nclimgrid/imke_figures/02temp-steps/'
extent = [-110.0, -101.0, 36.0, 42.0]
central_longitude = np.mean(extent[0:2])
levels = np.arange(-30, 10, 5)
levels = np.arange(-30, 15, 5)
cmap = 'BuPu_r'
tif_name = 'MSR_50M'
cjs.tstamp('Here we go!')
fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(6.4, 9.6),
subplot_kw={'projection': ccrs.AlbersEqualArea(
central_longitude=central_longitude)})
subplot_kw={
'projection': ccrs.AlbersEqualArea(
central_longitude=central_longitude),
'anchor': 'N'
})
i = 0
for ax, var_name in zip(axes[:2], var_names):
......@@ -57,7 +60,6 @@ for ax, var_name in zip(axes[:2], var_names):
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)
......@@ -77,7 +79,6 @@ helpers.draw_station_type(ax=ax, path=station_path, sep=' ',
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()
......
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