## Analysis points anal_dates = np.array([]) for i in range(0,len(f00[station])): D = datetime.strptime(f00[station][i],'%Y-%m-%d %H:%M') anal_dates = np.append(anal_dates,D) anal_temp = f00['temp'] anal_dwpt = f00['dwpt'] anal_speed = f00['speed'] date_start_index = 24+24+6 file_start_date = datetime.strptime(f00[station][date_start_index],'%Y-%m-%d %H:%M') # First grab the MesoWest Data. MW_start = file_start_date-timedelta(hours=1) MW_end = file_start_date+timedelta(days=1) a = get_mesowest_ts(station,MW_start,MW_end) # plot on a graph fig = plt.figure(1) ax = fig.add_subplot(111) plt.plot(a['datetimes'],a['temperature'],color='k',linewidth=3,label='MesoWest') anal_color=[.2,.2,.2] anal_hours = range(0,13,3) color = ['red','blue','green','darkorange','cornflowerblue','gold','yellowgreen'] lw = np.linspace(2,1.5,len(anal_hours)) for i in range(0,len(anal_hours)): file_start_date = datetime.strptime(f00[station][date_start_index+anal_hours[i]],'%Y-%m-%d %H:%M') print file_start_date Aug5_00UTC_line = np.array([]) Aug5_00UTC_line = np.append(Aug5_00UTC_line,f00['temp'][date_start_index+anal_hours[i]]) Aug5_00UTC_line = np.append(Aug5_00UTC_line,f01['temp'][date_start_index+1+anal_hours[i]])
figs[locName][4].xaxis.set_major_locator( mdates.HourLocator(range(0, 24, 6))) figs[locName][4].xaxis.set_minor_locator( mdates.HourLocator(range(0, 24, 1))) figs[locName][4].xaxis.set_major_formatter( mdates.DateFormatter('%b-%d\n%H:%M')) leg4 = figs[locName][4].legend() leg4.get_frame().set_linewidth(0) figs[locName][4].grid() figs[locName][4].set_ylabel('Height (m)') # # Finally, add MesoWest data if it is available if l['is MesoWest'] is True: a = get_mesowest_ts( locName, TS_dates[0], TS_dates[-1], variables='air_temp,dew_point_temperature,wind_direction,wind_speed' ) if a != 'ERROR': figs[locName][2].plot(a['DATETIME'], a['air_temp'], c='k', ls='--') figs[locName][2].plot(a['DATETIME'], a['dew_point_temperature'], c='k', ls='--') figs[locName][3].plot(a['DATETIME'], a['wind_speed'], c='k', ls='--') # Now add the element that changes, save the figure, and remove elements from plot. # Only download the HRRR grid once per forecast hour.
figs[locName][4].xaxis.set_major_locator( mdates.HourLocator(range(0, 24, 6))) figs[locName][4].xaxis.set_minor_locator( mdates.HourLocator(range(0, 24, 1))) figs[locName][4].xaxis.set_major_formatter( mdates.DateFormatter('%b-%d\n%H:%M')) leg4 = figs[locName][4].legend() leg4.get_frame().set_linewidth(0) figs[locName][4].grid() figs[locName][4].set_ylabel('Height (m)') # # Finally, add MesoWest data if it is available if l['is MesoWest'] is True: a = get_mesowest_ts( locName, sDATE, eDATE, variables='air_temp,wind_speed,dew_point_temperature') if a != 'ERROR': figs[locName][2].plot(a['DATETIME'], a['air_temp'], c='k', ls='--') figs[locName][2].plot(a['DATETIME'], a['dew_point_temperature'], c='k', ls='--') figs[locName][3].plot(a['DATETIME'], a['wind_speed'], c='k', ls='--') # Now add the element that changes, save the figure, and remove elements from plot. # Only download the HRRR grid once per forecast hour.
HRRR_var = 'DPT:2 m' MW_var = 'dew_point_temperature' title_var = "Dew Point Temperature" #============================================================================== # Set colormap if MW_var == 'wind_speed': cmap = 'magma_r' elif MW_var == 'dew_point_temperature': cmap = 'BrBG' elif MW_var == 'air_temp': cmap = 'Spectral_r' else: cmap = 'viridis' # Get data from the MesoWest Station a = get_mesowest_ts(stn, sDATE, eDATE, variables=MW_var) # Make a time series of HRRR forecasts for each forecast hour. loc = {stn:{'latitude':a['LAT'],'longitude':a['LON']}} data = {} for f in range(19): sOffset = sDATE - timedelta(hours=f) eOffset = eDATE - timedelta(hours=f) data[f] = point_hrrr_time_series_multi(sOffset, eOffset, loc, variable=HRRR_var, fxx=f) # combine the data arrays into a hovmoller array if MW_var == 'air_temp' or MW_var == 'dew_point_temperature': hovmoller = np.array([data[i][stn]-273.15 for i in range(19)]) else:
dwptF = TS_dwpt[loc] ax2.plot(TS_temp['DATETIME'], tempF, c='r', lw='1.5', label='Temperature') ax2.scatter(TS_temp['DATETIME'][hh], tempF[hh], c='r', s=60) ax2.plot(TS_dwpt['DATETIME'], dwptF, c='g', lw='1.5', label='Dew Point') ax2.scatter(TS_dwpt['DATETIME'][hh], dwptF[hh], c='g', s=60) if l['is MesoWest'] is True: a = get_mesowest_ts(loc, sDATE, eDATE, variables='air_temp,wind_speed') b = get_mesowest_radius(TS_dates[hh], 15, extra='&radius=%s,30' % (loc), variables='wind_speed,wind_direction') MW_u, MW_v = wind_spddir_to_uv(b['wind_speed'], b['wind_direction']) MW_u = mps_to_MPH(MW_u) MW_v = mps_to_MPH(MW_v) ax2.plot(a['DATETIME'], CtoF(a['air_temp']), c='k', ls='--') MWx, MWy = maps[loc](b['LON'], b['LAT']) ax1.barbs(MWx, MWy, MW_u, MW_v, color='r') ax2.legend() ax2.grid()
def plot_pollywog(p, SAVEDIR, custom_end_date=False): """ Plots the pollywogs for all the variables in the pollywog dictionary. Plots the pollywog with the MesoWest observation inputs: p - p is a pollywog dictionary SAVEDIR - a string name for the save directory output: none global: station analysis vectors (i.e. Adates, Atemp, Au, ...) width - the figure width (barb figure height is higher) """ Acolor = [.2, .2, .2] #color of the analysis points barbs_colors = [] hours = mpl.dates.HourLocator([0, 3, 6, 9, 12, 15, 18, 21]) hours_each = mpl.dates.HourLocator() # find the first time in the p dictionary fv = p.keys()[0] # first variable key num_v = len(p.keys()) # number of variables num_h = len(p[fv]) # number of hours # p[variable][hour][dates array][position] first_date = p[fv][0][1][0] last_date = p[fv][len(p[fv]) - 1][1][-1] # First grab the MesoWest Data. MW_start = first_date - timedelta(hours=1) if custom_end_date != False: MW_end = custom_end_date else: MW_end = last_date a = get_mesowest_ts(station, MW_start, MW_end) print "got MesoWest" for i in range(0, num_v): # for each variable #%% if p.keys()[i] == 'temp': print 'working on temp' fig = plt.figure(i + 1) ax = fig.add_subplot(111) # Add a grid plt.grid() # Plot MesoWest plt.plot(a['datetimes'], a['temperature'], color='k', linewidth=3) # Plot each pollywog for h in range(0, num_h): lw = np.linspace(2, 1.5, num_h) z = plt.plot(p['temp'][h][1], p['temp'][h][0], linewidth=lw[h]) # store the line color and plot head with same color color = z[0]._get_rgba_ln_color() barbs_colors = barbs_colors + [color] # Plot the Pollywog head, the analysis time, with same color plt.scatter(p['temp'][h][1][0], p['temp'][h][0][0], color=color, s=80) # Plot the analysis hours plt.scatter(Adates, Atemp, color=Acolor, s=30, zorder=10) plt.title(station) plt.ylabel(r'2-m Temperature (C)') #plt.ylim([0,15]) plt.xlim(MW_start, MW_end) ax.xaxis.set_major_locator(hours) ax.xaxis.set_minor_locator(hours_each) ax.xaxis.set_major_formatter( mpl.dates.DateFormatter('%m/%d\n%H:%M')) plt.savefig(SAVEDIR + station + '_temp_2m.png') #%% elif p.keys()[i] == 'dwpt': print 'working on dwpt' fig = plt.figure(i + 1) ax = fig.add_subplot(111) # Add a grid plt.grid() # Plot MesoWest plt.plot(a['datetimes'], a['dew point'], color='k', linewidth=3) # Plot each pollywog for h in range(0, num_h): lw = np.linspace(2, 1.5, num_h) z = plt.plot(p['dwpt'][h][1], p['dwpt'][h][0], linewidth=lw[h]) # store the line color and plot head with same color color = z[0]._get_rgba_ln_color() # store the line color and plot head with same color barbs_colors = barbs_colors + [color] # Plot the Pollywog head, the analysis time, with same color plt.scatter(p['dwpt'][h][1][0], p['dwpt'][h][0][0], color=color, s=80) # Plot the analysis hours plt.scatter(Adates, Adwpt, color=Acolor, s=30, zorder=10) plt.title(station) plt.ylabel(r'2-m Dew Point (C)') #plt.ylim([0,15]) plt.xlim(MW_start, MW_end) ax.xaxis.set_major_locator(hours) ax.xaxis.set_minor_locator(hours_each) ax.xaxis.set_major_formatter( mpl.dates.DateFormatter('%m/%d\n%H:%M')) plt.savefig(SAVEDIR + station + '_dwpt_2m.png') #%% elif p.keys()[i] == 'speed': print 'working on speed' fig = plt.figure(i + 1) ax = fig.add_subplot(111) # Add a grid plt.grid() # Plot MesoWest plt.plot(a['datetimes'], a['wind speed'], color='k', linewidth=3, zorder=1) # Plot each pollywog for h in range(0, num_h): lw = np.linspace(2, 1.5, num_h) z = plt.plot(p['speed'][h][1], p['speed'][h][0], linewidth=lw[h], zorder=2) # store the line color and plot head with same color color = z[0]._get_rgba_ln_color() # store the line color and plot head with same color barbs_colors = barbs_colors + [color] # Plot the Pollywog head, the analysis time, with same color plt.scatter(p['speed'][h][1][0], p['speed'][h][0][0], color=color, s=80, zorder=2) # Plot the analysis hours plt.scatter(Adates, Aspeed, color=Acolor, s=30, zorder=10) plt.title(station) plt.ylabel(r'10-m Wind Speed (ms$\mathregular{^{-1}}$)') plt.ylim([0, 15]) plt.xlim(MW_start, MW_end) ax.xaxis.set_major_locator(hours) ax.xaxis.set_minor_locator(hours_each) ax.xaxis.set_major_formatter( mpl.dates.DateFormatter('%m/%d\n%H:%M')) plt.savefig(SAVEDIR + station + '_speed_10m.png') #%% ## for u and v variables, plot the wind barbs elif p.keys()[i] == 'u': print 'working on u' fig = plt.figure(i + 1, [width, 6]) ax = fig.add_subplot(111) # Add a grid plt.grid() # Plot MesoWest MW_u, MW_v = wind_spddir_to_uv(a['wind speed'], a['wind direction']) # If u or v is nan, then set to zero. We got a nan origianlly # becuase no direction was reported. Speed is zero in these instances. MW_u[np.isnan(MW_u)] = 0 MW_v[np.isnan(MW_v)] = 0 idx = mpl.dates.date2num(a['datetimes']) y = np.ones_like(MW_u) * -.5 # ONLY PLOT EVERY THIRD MESOWEST OBSERVATION!!!! plt.barbs(idx[::3], y[::3], MW_u[::3], MW_v[::3], barb_increments=dict(half=1, full=2, flag=10), length=5.25) #print barbs_colors yticks = [-0.5] ylabels = ['MesoWest'] for h in range(0, num_h): idx = mpl.dates.date2num(p['u'][h][1]) plt.barbs(idx, np.ones_like(idx) * h + 1, p['u'][h][0], p['v'][h][0], color=barbs_colors[h], barb_increments=dict(half=1, full=2, flag=10), length=5.25) yticks.append(h + 1) ylabels.append('%02d UTC' % (p['u'][h][1][0].hour)) plt.yticks(yticks, ylabels) plt.title(station) plt.ylabel(r'10-m Wind Speed (ms$\mathregular{^{-1}}$)') #plt.ylim([0,15]) plt.xlim(MW_start, MW_end) ax.xaxis.set_major_locator(hours) ax.xaxis.set_minor_locator(hours_each) ax.xaxis.set_major_formatter( mpl.dates.DateFormatter('%m/%d\n%H:%M')) plt.savefig(SAVEDIR + station + '_barbs_10m_full2_half1.png') #%% return { 'fv': fv, 'num_v': num_v, 'first_date': first_date, 'last_date': last_date, 'mesowest': a, 'plots': z, 'barbs_colors': barbs_colors }
ax1.set_title(' UTC: %s\nLocal Time: %s' % (DATE + timedelta(hours=fxx), DATE + timedelta(hours=fxx) - timedelta(hours=tz))) # 3.2) Temperature/Dew Point ax2 = plt.subplot(3, 2, 2) tempF = P_temp[loc] dwptF = P_dwpt[loc] ax2.plot(P_temp['DATETIME'], tempF, c='r', label='Temperature') ax2.scatter(P_temp['DATETIME'][fxx], tempF[fxx], c='r', s=60) ax2.plot(P_dwpt['DATETIME'], dwptF, c='g', label='Dew Point') ax2.scatter(P_dwpt['DATETIME'][fxx], dwptF[fxx], c='g', s=60) if l['is MesoWest'] is True: a = get_mesowest_ts( loc, DATE, datetime.utcnow(), variables='air_temp,wind_speed,dew_point_temperature') if a != 'ERROR': ax2.plot(a['DATETIME'], CtoF(a['air_temp']), c='k', ls='--') ax2.plot(a['DATETIME'], CtoF(a['dew_point_temperature']), c='k', ls='--') leg2 = ax2.legend() leg2.get_frame().set_linewidth(0) ax2.grid() ax2.set_ylabel('Degrees (F)') ax2.set_xlim([P_temp['DATETIME'][0], P_temp['DATETIME'][-1]]) if l['is MesoWest'] is True and a != 'ERROR':
forecasts = [0, 6, 12, 16, 18] # ============================================================================= # ============================================================================= # Create the hourly date list base = DATE hours = (eDATE - DATE).days * 24 date_list = [base + timedelta(hours=x) for x in range(0, hours)] # Create time series plot overlaying HRRR and MesoWest data for each station # and each forecast hour. for stn in stations: for fxx in forecasts: # Get MesoWest data a = get_mesowest_ts(stn, DATE, eDATE) # Get HRRR data Hvar = 'MSLMA:mean sea level' validDate, value = point_hrrr_time_series(DATE, eDATE, variable=Hvar, lat=a['LAT'], lon=a['LON'], fxx=fxx, model='hrrr', field='sfc', reduce_CPUs=0) # Create the plot fig, ax = plt.subplots(1)
# first_mw_attempt = S['MW var'] for stn in locations.keys(): print "\nWorking on %s %s" % (stn, s) SAVE = SAVE_dir + '%s/' % stn if not os.path.exists(SAVE): # make the SAVE directory if it doesn't already exist os.makedirs(SAVE) print "created:", SAVE # then link the photo viewer photo_viewer = '/uufs/chpc.utah.edu/common/home/u0553130/public_html/Brian_Blaylock/photo_viewer/photo_viewer.php' os.link(photo_viewer, SAVE+'photo_viewer.php') # # Get data from the MesoWest Station # a = get_mesowest_ts(stn, sDATE, eDATE, variables=S['MW var']) # Aak, so many different precipitatin variables. Try each one until we # find one that works... if a == 'ERROR': # the variable probably isn't available (i.e. CAPE), so fill with nans dates_1d = hovmoller['valid_1d+'][:-1] a = {'DATETIME':dates_1d, S['MW var']:[np.nan for i in range(len(dates_1d))]} # # Apply offset to data if necessary if s == 'Air Temperature' or s == 'Dew Point Temperature': hovmoller[stn]['max'] = hovmoller[stn]['max']-273.15 hovmoller[stn]['min'] = hovmoller[stn]['min']-273.15 hovmoller[stn]['box center'] = hovmoller[stn]['box center']-273.15 # #
first_mw_attempt = S['MW var'] for stn in locations.keys(): print "\nWorking on %s %s" % (stn, s) SAVE = SAVE_dir + '%s/' % stn if not os.path.exists(SAVE): # make the SAVE directory if it doesn't already exist os.makedirs(SAVE) print "created:", SAVE # then link the photo viewer photo_viewer = '/uufs/chpc.utah.edu/common/home/u0553130/public_html/Brian_Blaylock/photo_viewer/photo_viewer.php' os.link(photo_viewer, SAVE + 'photo_viewer.php') # # Get data from the MesoWest Station # S['MW var'] = first_mw_attempt a = get_mesowest_ts(stn, sDATE, eDATE, variables=first_mw_attempt) # Aak, so many different precipitatin variables. Try each one until we # find one that works... if a == 'ERROR': a = get_mesowest_ts(stn, sDATE, eDATE, variables='precip_accum_one_hour') S['MW var'] = 'precip_accum_one_hour' if a == 'ERROR': a = get_mesowest_ts(stn, sDATE, eDATE, variables='precip_accum') S['MW var'] = 'precip_accum' if a == 'ERROR':
import sys sys.path.append('B:/pyBKB_v2') sys.path.append('/uufs/chpc.utah.edu/common/home/u0553130/pyBKB_v2') from BB_MesoWest.MesoWest_timeseries import get_mesowest_ts DATE_START = datetime(2017, 1, 4) DATE_END = datetime.now() save_date = DATE_START.strftime('%Y%m%d') + '-' + DATE_END.strftime('%Y%m%d') stations = ['PSINK', 'KLGU', 'UFD09', 'WBB'] data = OrderedDict() for s in stations: data[s] = get_mesowest_ts(s, DATE_START, DATE_END) """ Plot """ fig, ax1 = plt.subplots(1, 1) for s in data.keys(): ax1.plot(data[s]['DATETIME'], data[s]['air_temp'], label=s) plt.grid() ax1.legend() ax1.set_title('MesoWest Air Temperature') ax1.set_ylabel('Temperature (C)') ax1.xaxis.set_major_locator(HourLocator(byhour=[0, 12]))
style_path + 'dpi_medium.mplstyle' ]) from matplotlib.dates import DateFormatter, HourLocator from datetime import datetime import sys sys.path.append('B:/pyBKB_v2') sys.path.append('/uufs/chpc.utah.edu/common/home/u0553130/pyBKB_v2') from BB_MesoWest.MesoWest_timeseries import get_mesowest_ts DATE_START = datetime(2017, 1, 4) DATE_END = datetime.now() save_date = DATE_START.strftime('%Y%m%d') + '-' + DATE_END.strftime('%Y%m%d') valley = get_mesowest_ts('PSINK', DATE_START, DATE_END) rim = get_mesowest_ts('PSRIM', DATE_START, DATE_END) """ Plot """ fig, ax1 = plt.subplots(1, 1) ax1.plot(rim['DATETIME'], rim['air_temp'], color='r', label='rim') ax1.plot(valley['DATETIME'], valley['air_temp'], color='b', label='valley') plt.grid() ax1.legend() ax1.set_title('Peter Sinks') ax1.set_ylabel('Temperature (C)')
# the nearest neighbor which isn't water. bflat_temps = temps[:, 3] # Air temperatures where also returned buoy_2m = temps[:, 4] ufd09_2m = temps[:, 5] ufd09_2m2 = temps[:, 6] # Remember, these are the 1 grid point west of # the nearest neighbor which isn't water. bflat_2m = temps[:, 7] # Get MesoWest observations. try: a = get_buoy_ts(date_list[-1], date_list[0]) except: print "no buoy observations" MW_bflat = get_mesowest_ts('BFLAT', date_list[-1], date_list[0]) MW_ufd09 = get_mesowest_ts('UFD09', date_list[-1], date_list[0], variables='air_temp,surface_temp') plt.plot(a['Datetimes'], a['T_water1']) plt.plto(date_list, buoy_temps) """ Plot time series: - HRRR surface temperature and - Buoy observed -0.4 meter water temperature. - UFD09 surface temperature """ """