Commit bfc50912 authored by Jared Rennie's avatar Jared Rennie
Browse files

initial commit

parents
#!/usr/bin/python
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import numpy as np
import numpy.ma as ma
import sys
import time
import datetime
import os
import xarray as xr
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.io.shapereader import Reader
import warnings
warnings.filterwarnings("ignore")
from metpy.cbook import get_test_data
from metpy.io import Level2File
from metpy.plots import colortables
from metpy.plots import ctables
from metpy.plots import USCOUNTIES
# Define Directories
main_directory='/store/sfcnet/datasets/mrms'
in_directory=main_directory+'/source'
shapefile_directory=main_directory+'/input_shapefiles'
out_directory=main_directory+'/results_plots'
# Set Up for Plotting
dpi=300
plt.style.use('dark_background')
center_lat=35.6362
center_lon=-82.6302
# Set Bounds
minLat = 31
maxLat = 39
minLon = -88 + 360.
maxLon = -78 + 360.
#################################################
# BEGIN PROGRAM
start=time.time()
# Read in Arguments
if len(sys.argv) < 2:
sys.exit("USAGE: <INFILE>")
file = sys.argv[1]
print(file)
# Get Time
current_time=file[40:55]
if time.localtime().tm_isdst == 1: # DST in Affect (EDT)
utcAdjust=4
timeZone='EDT'
else:
utcAdjust=5 # DST NOT in Affect (EST)
timeZone='EST'
current_date=datetime.datetime(int(current_time[0:4]),int(current_time[4:6]),int(current_time[6:8]),int(current_time[9:11]),int(current_time[11:13])) - datetime.timedelta(hours=utcAdjust)
current_day= "%04i%02i%02i" % (current_date.year,current_date.month,current_date.day)
current_hour= "%02i:%02i" % (current_date.hour,current_date.minute)
# Read in Data
inData=xr.load_dataset(in_directory+'/'+file,engine='cfgrib')
# Mask Data outside of bounds
mask_lon = (inData.longitude >= minLon-1) & (inData.longitude <= maxLon+1)
mask_lat = (inData.latitude >= minLat-1) & (inData.latitude <= maxLat+1)
dataSubset = inData.where(mask_lon & mask_lat, drop=True)
lats=dataSubset.latitude.values
lons=dataSubset.longitude.values-360
vals=dataSubset.unknown.values
vals_nonmiss=ma.masked_where(vals <= 0, vals)
# Set Up Figure
print("PLOT")
fig= plt.figure(num=1, figsize=(8,5), dpi=dpi, facecolor='w', edgecolor='k')
#proj=ccrs.LambertConformal(central_longitude=center_lon, central_latitude=center_lat)
proj=ccrs.Mercator()
ax = fig.add_axes([0, 0, 1, 1], projection=proj)
ax.set_extent([minLon, maxLon, minLat, maxLat], crs=ccrs.Geodetic())
ax.set_facecolor('black')
ref_norm, ref_cmap = ctables.registry.get_with_steps('NWSReflectivity', 5, 5)
# Add Boundaries
ax.add_feature(cfeature.COASTLINE,linewidth=0.5,edgecolor='white',facecolor='black',zorder=5)
ax.add_feature(cfeature.OCEAN,linewidth=0.5,edgecolor='white',facecolor='black',zorder=5)
ax.add_feature(USCOUNTIES.with_scale('500k'),linewidth=0.10,edgecolor='white',facecolor='#4a4a4a',zorder=6)
state_borders = cartopy.feature.NaturalEarthFeature(category='cultural', name='admin_1_states_provinces_lines',scale='10m', facecolor='none')
ax.add_feature(state_borders, edgecolor='white', linewidth=1, zorder=7)
interstates = cfeature.ShapelyFeature(Reader(shapefile_directory+'/tl_2016_us_primaryroads.shp').geometries(),ccrs.PlateCarree(), facecolor='none')
ax.add_feature(interstates, edgecolor='#000073', linewidth=0.5, zorder=9)
# Plot Data
ax.pcolormesh(lons, lats,vals_nonmiss,transform=ccrs.PlateCarree(),cmap=ref_cmap,norm=ref_norm,zorder=8)
#plt.scatter(center_lat, center_lat, transform=proj, marker='*',c='orange',s=50,zorder=8)
# Add Titles
plt.annotate('Time='+str(current_day)+' '+str(current_hour)+' '+str(timeZone)+'\nMade By Jared Rennie (@jjrennie)',xy=(0.02, 0.02), xycoords='axes fraction', fontsize=5,backgroundcolor='black',color='white',horizontalalignment='left', verticalalignment='bottom',zorder=10)
plt.suptitle('MRMS Composite Radar',size=17,color='white',y=1.05)
# Save Figure
plt.savefig(out_directory+"/MRMS_AVL_"+str(current_day)+"-"+str(current_hour.replace(':',''))+".png",bbox_inches='tight')
plt.clf()
plt.close()
####################
# DONE
####################
print("DONE!")
end=time.time()
print ("Runtime: %8.1f seconds." % (end-start))
sys.exit()
\ No newline at end of file
#!/usr/bin/python
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import numpy as np
import numpy.ma as ma
import sys
import time
import datetime
import os
import xarray as xr
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import warnings
warnings.filterwarnings("ignore")
from metpy.cbook import get_test_data
from metpy.io import Level2File
from metpy.plots import colortables
from metpy.plots import ctables
from metpy.plots import USCOUNTIES
# Define Directories
main_directory='/store/sfcnet/datasets/mrms'
in_directory=main_directory+'/source'
out_directory=main_directory+'/results_plots'
# Set Up for Plotting
dpi=300
plt.style.use('dark_background')
# Set Bounds
minLat = 22.5
maxLat = 50.5
minLon = -120
maxLon = -73
#################################################
# BEGIN PROGRAM
start=time.time()
# Read in Arguments
if len(sys.argv) < 2:
sys.exit("USAGE: <INFILE>")
file = sys.argv[1]
print(file)
# Get Time
current_time=file[40:55]
if time.localtime().tm_isdst == 1: # DST in Affect (EDT)
utcAdjust=4
timeZone='EDT'
else:
utcAdjust=5 # DST NOT in Affect (EST)
timeZone='EST'
current_date=datetime.datetime(int(current_time[0:4]),int(current_time[4:6]),int(current_time[6:8]),int(current_time[9:11]),int(current_time[11:13])) - datetime.timedelta(hours=utcAdjust)
current_day= "%04i%02i%02i" % (current_date.year,current_date.month,current_date.day)
current_hour= "%02i:%02i" % (current_date.hour,current_date.minute)
# Read in Data
inData=xr.load_dataset(in_directory+'/'+file,engine='cfgrib')
sys.exit()
lats=inData.latitude.values
lons=inData.longitude.values-360
vals=inData.unknown.values
vals_nonmiss=ma.masked_where(vals <= 0, vals)
print("PLOT")
unit='dBz'
color_map='Greens'
bounds=np.arange(-10,120,10)
ref_norm, ref_cmap = ctables.registry.get_with_steps('NWSReflectivity', 5, 5)
# Set Up Figure
#vmin=np.min(bounds)
#vmax=np.max(bounds)
extend='max'
#orm = mcolors.BoundaryNorm(boundaries=bounds, ncolors=256)
cm = plt.cm.ScalarMappable(cmap=ref_cmap)
#cm.set_array(np.array(vals_nonmiss))
#cm.set_clim(vmin, vmax)
fig= plt.figure(num=1, figsize=(8,5), dpi=dpi, facecolor='w', edgecolor='k')
ax = fig.add_axes([0, 0, 1, 1], projection=ccrs.LambertConformal())
ax.set_extent([minLon, maxLon, minLat, maxLat], crs=ccrs.Geodetic())
ax.set_facecolor('black')
ax.add_feature(cfeature.COASTLINE,linewidth=0.5,edgecolor='white',facecolor='black')
ax.add_feature(cfeature.OCEAN,linewidth=0.5,edgecolor='white',facecolor='black')
ax.add_feature(cfeature.BORDERS,linewidth=0.5,edgecolor='white',facecolor='black')
ax.add_feature(cfeature.STATES,linewidth=0.5,edgecolor='white',facecolor='#4a4a4a')
# Plot Data
ax.pcolormesh(lons, lats,vals_nonmiss,transform=ccrs.PlateCarree(),cmap=ref_cmap,norm=ref_norm,zorder=10)
value_max="%5.2f" % np.nanmax(vals_nonmiss)
value_min="%5.2f" % np.nanmin(vals_nonmiss)
# Add Colormap
#cax = fig.add_axes([0.1, -0.035, 0.8, 0.03])
#cbar=plt.colorbar(cm, cax=cax,boundaries=bounds,orientation='horizontal',extend=extend,spacing='uniform')
#cbar=plt.colorbar(cm, cax=cax,orientation='horizontal',extend=extend,spacing='uniform')
#cbar.ax.tick_params(labelsize=15)
#cbar.set_label(unit,size=15)
# Add Titles
plt.annotate('Time='+str(current_day)+' '+str(current_hour)+' '+str(timeZone)+'\nMade By Jared Rennie (@jjrennie)',xy=(0.02, 0.02), xycoords='axes fraction', fontsize=5,backgroundcolor='black',color='white',horizontalalignment='left', verticalalignment='bottom',zorder=4)
plt.suptitle('MRMS Composite Radar',size=17,color='white',y=1.05)
# Save Figure
plt.savefig(out_directory+"/MRMS_CONUS_"+str(current_day)+"-"+str(current_hour.replace(':',''))+".png",bbox_inches='tight')
plt.clf()
plt.close()
####################
# DONE
####################
print("DONE!")
end=time.time()
print ("Runtime: %8.1f seconds." % (end-start))
sys.exit()
\ No newline at end of file
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