Commit a6034384 authored by Carl Schreck's avatar Carl Schreck

Working version of station_type.py

parent d3ec975c
......@@ -32,10 +32,10 @@ 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=1, lon_column=2, time_column=6):
def draw_station_type(ax, path, lat_column=2, lon_column=3, time_column=7):
cjs.tstamp('Reading')
print(path)
asc_data = pd.read_csv(path, sep=' ', header=None, skipinitialspace=True)
asc_data = pd.read_csv(path, sep=',', header=None, skipinitialspace=True)
cjs.add_conus_map(ax)
......@@ -45,8 +45,9 @@ def draw_station_type(ax, path, lat_column=1, lon_column=2, time_column=6):
obs_time = asc_data[time_column]
network = asc_data[0].str[2]
labels = ['RAWS', 'SNOTEL', 'NWS Midnight', 'NWS Morning']
zorders = [4, 5, 3, 2] + 5
zorders = np.array([4, 5, 3, 2]) + 5
colors = cjs.tab[[0, 3, 2, 1]]
markersize = [1, 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)
......@@ -56,12 +57,13 @@ def draw_station_type(ax, path, lat_column=1, lon_column=2, time_column=6):
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=1, linestyle='', label=labels[type_ind],
zorder=zorders[type_ind], c=colors[type_ind])
ax.legend(labels=labels, loc='upper center', bbox_to_anchor=[0.5, 0],
ncol=2)
return asc_data
plot = 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.legend(labels=labels, loc='upper center', bbox_to_anchor=[0.5, 0],
# ncol=2)
return None
def read_unscaled(path, var_name, lat_column=0, lon_column=1, data_column=4,):
......
""" Draw maps of station type for precip and temp, and compare by time."""
__author__ = "Carl Schreck"
__email__ = "cjschrec@ncsu.edu"
__copyright__ = "Copyright 2020, North Carolina State University"
__license__ = "BSD-3.0"
import matplotlib.pyplot as plt
import numpy as np
import os
import cjs # '~carl/lib/python'
import helpers
# These are some parameters that could be useful to have up top
base_path = f'{os.environ["DATA_DIR"]}/nclimgrid/imke_figures/stn-maps/'
var_names = np.array(['PRCP', 'TMAX'])
dates = np.array(['19510101', '20091106', '20191231'])
var_name_to_long_name = {
'TMAX': 'Maximum Temperature',
'PRCP': 'Precipitation',
}
cjs.tstamp('Here we go!')
fig, axes = plt.subplots(nrows=3, ncols=2, figsize=(6.4, 8.0),
subplot_kw={'projection': cjs.conus_projection, })
i = 0
for var_name in var_names:
for date in dates:
ax = axes[date==dates, var_name==var_names][0]
station_path = f'{base_path}/{var_name}_{date}_D6_A2_time.txt'
plot = helpers.draw_station_type(ax, station_path)
ax.set_anchor('N')
ax.set_title(f'{cjs.number_to_letter(i)}'
f'{var_name_to_long_name[var_name]}: '
f'{date[:4]}',
loc='left')
i += 1
handles, labels = ax.axes.get_legend_handles_labels()
fig.legend(handles, labels, loc='lower center', ncol=4,
markerscale=10)
cjs.tstamp('Drawing figure')
plt.tight_layout()
plt.savefig(f'figures/station_type.png', dpi=200, bbox_inches="tight")
plt.show()
cjs.tstamp('Thank you, come again.')
......@@ -16,7 +16,7 @@ import helpers
# These are some parameters that could be useful to have up top
parser = argparse.ArgumentParser()
parser.add_argument('--var_name', default='tmin')
parser.add_argument('--var_name', default='tavg')
args = parser.parse_args()
var_name = args.var_name
time = '1989-02-03'
......@@ -60,7 +60,7 @@ for tif_name in ['US_MSR']:
cjs.tstamp('Drawing figure')
plt.tight_layout()
plt.savefig(f'figures/{var_name}_steps.png', dpi=300)
plt.savefig(f'figures/{var_name}_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