-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_plot_v0.1.py
More file actions
86 lines (66 loc) · 2.54 KB
/
simple_plot_v0.1.py
File metadata and controls
86 lines (66 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'''
This script makes a simple plot of surface temperature and 10m winds from a wrfout.nc file
Written 3/15/21 by Jack Sillin for EAS 5555
Updated 3/21/21
This is version 0.1 of this script.
'''
########## SETUP ##########
#Import Necessary Packages
import matplotlib.pyplot as plt
import xarray as xr
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import numpy as np
import matplotlib.lines as lines
# Read data with xarray
data_path = 'data/'
filename = 'matthew_wrfout.nc'
path = data_path + filename
print(path)
ds = xr.open_dataset(path)
########## PROCESSING DATA ##########
# Select/extract time of interest
ds = ds.isel(Time=1)
time = ds.XTIME
dtfs = str(time.dt.strftime('%Y-%m-%d_%H%MZ').item())
# Get coordinates
lat = ds['XLAT']
lon = ds['XLONG']
# Extract 10m wind data and convert m/s to kts
u_10m = ds['U10']*1.94384449
v_10m = ds['V10']*1.94384449
# Extract 2m temp data and convert to F
t2m = ds['TH2']
t2m = ((t2m - 273.15)*(9./5.))+32.
# Thin the wind arrays a bit for plotting nicely
wind_slice = slice(3,-3,3)
sliced_lats = lat[wind_slice,wind_slice]
sliced_lons = lon[wind_slice,wind_slice]
sliced_u10m = u_10m[wind_slice,wind_slice]
sliced_v10m = v_10m[wind_slice,wind_slice]
########## PLOTTING ##########
# Define legend entries
blue_line = lines.Line2D([], [], color='b',label='32F Isotherm')
# Create the figure and axes
fig = plt.figure(figsize=(15,15))
ax1 = fig.add_subplot(111, projection = ccrs.PlateCarree())
# Add various geographical information to the plot
ax1.coastlines(resolution='10m')
ax1.add_feature(cfeature.BORDERS.with_scale('10m'), linewidth=1.5)
ax1.add_feature(cfeature.STATES.with_scale('10m'), linewidth=2.0)
# Plot 2m temps and 32F isotherm
tmp_2m = ax1.contourf(lon,lat,t2m,cmap='RdYlBu_r', alpha = 0.8, levels = range(-20,100,5),transform=ccrs.PlateCarree())
tmp_2m32 = ax1.contour(lon,lat,t2m,colors='b', alpha = 0.8, levels = [32])
cbr = fig.colorbar(tmp_2m, orientation = 'horizontal', aspect = 80, ax = ax1, pad = 0.01,
extendrect=False, ticks = range(-20,100,5), shrink=0.7)
cbr.set_label('2m Temperature (F)', fontsize = 14)
# Plot 10m winds thinned out for better presentation
ax1.barbs(sliced_lons,sliced_lats,sliced_u10m,sliced_v10m, length=6,color='gray')
# Set titles
ax1.set_title('2m Temperatures (F) and 10m Winds (kts)')
ax1.set_title('WRF Basic Case Study',fontsize=11,loc='right')
ax1.set_title('Valid: '+dtfs,fontsize=11,loc='right')
# Add legend
leg = ax1.legend(handles=[blue_line],loc=3,framealpha=1)
# Save output graphic
plt.savefig('sfc_tempsandwinds_v1'+dtfs+'.png')