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

initial commit

parents
UTF-8
\ No newline at end of file
PROJCS["WGS_1984_World_Mercator",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Mercator"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",0.0],PARAMETER["Standard_Parallel_1",0.0],UNIT["Meter",1.0]]
\ No newline at end of file
<?xml version="1.0"?>
<!--<!DOCTYPE metadata SYSTEM "http://www.esri.com/metadata/esriprof80.dtd">-->
<metadata xml:lang="en"><Esri><CreaDate>20210105</CreaDate><CreaTime>15221000</CreaTime><SyncOnce>TRUE</SyncOnce><DataProperties><lineage><Process Name="Create Feature Class" ToolSource="C:\ESRI\ARCGIS\ArcToolbox\Toolboxes\Data Management Tools.tbx\CreateFeatureclass" Date="20061101" Time="202813">CreateFeatureclass C:\ESRI\AEJEE_XTRA\AEJEE23data\usa states # states_Layer SAME_AS_TEMPLATE SAME_AS_TEMPLATE "GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-178.217598362366 18.921786345087 999999.999068677;0 100000;0 100000" # 0 0 0 C:\ESRI\AEJEE_XTRA\AEJEE23data\usa\states.shp</Process><Process Name="Append" ToolSource="C:\ESRI\ARCGIS\ArcToolbox\Toolboxes\Data Management Tools.tbx\Append" Date="20061101" Time="202813">Append states_Layer C:\ESRI\AEJEE_XTRA\AEJEE23data\usa\states.shp TEST C:\ESRI\AEJEE_XTRA\AEJEE23data\usa\states.shp</Process><Process Name="FeatureClassToFeatureClass_3" ToolSource="C:\ESRI\ARCGIS\ArcToolbox\Toolboxes\Conversion Tools.tbx\FeatureClassToFeatureClass" Date="20061101" Time="202814">FeatureClassToFeatureClass D:\usa\census\states.sdc\states C:\ESRI\AEJEE_XTRA\AEJEE23data\usa states # "STATE_NAME STATE_NAME VISIBLE;STATE_FIPS STATE_FIPS VISIBLE;SUB_REGION SUB_REGION VISIBLE;STATE_ABBR STATE_ABBR VISIBLE;POP2000 POP2000 VISIBLE;POP2005 POP2005 VISIBLE;POP00_SQMI POP00_SQMI VISIBLE;POP05_SQMI POP05_SQMI VISIBLE;WHITE WHITE VISIBLE;BLACK BLACK VISIBLE;AMERI_ES AMERI_ES VISIBLE;ASIAN ASIAN VISIBLE;HAWN_PI HAWN_PI VISIBLE;OTHER OTHER VISIBLE;MULT_RACE MULT_RACE VISIBLE;HISPANIC HISPANIC VISIBLE;MALES MALES VISIBLE;FEMALES FEMALES VISIBLE;AGE_UNDER5 AGE_UNDER5 VISIBLE;AGE_5_17 AGE_5_17 VISIBLE;AGE_18_21 AGE_18_21 VISIBLE;AGE_22_29 AGE_22_29 VISIBLE;AGE_30_39 AGE_30_39 VISIBLE;AGE_40_49 AGE_40_49 VISIBLE;AGE_50_64 AGE_50_64 VISIBLE;AGE_65_UP AGE_65_UP VISIBLE;MED_AGE MED_AGE VISIBLE;MED_AGE_M MED_AGE_M VISIBLE;MED_AGE_F MED_AGE_F VISIBLE;HOUSEHOLDS HOUSEHOLDS VISIBLE;AVE_HH_SZ AVE_HH_SZ VISIBLE;HSEHLD_1_M HSEHLD_1_M VISIBLE;HSEHLD_1_F HSEHLD_1_F VISIBLE;MARHH_CHD MARHH_CHD VISIBLE;MARHH_NO_C MARHH_NO_C VISIBLE;MHH_CHILD MHH_CHILD VISIBLE;FHH_CHILD FHH_CHILD VISIBLE;FAMILIES FAMILIES VISIBLE;AVE_FAM_SZ AVE_FAM_SZ VISIBLE;HSE_UNITS HSE_UNITS VISIBLE;VACANT VACANT VISIBLE;OWNER_OCC OWNER_OCC VISIBLE;RENTER_OCC RENTER_OCC VISIBLE;NO_FARMS97 NO_FARMS97 VISIBLE;AVG_SIZE97 AVG_SIZE97 VISIBLE;CROP_ACR97 CROP_ACR97 VISIBLE;AVG_SALE97 AVG_SALE97 VISIBLE;SQMI SQMI VISIBLE" SAME_AS_TEMPLATE SAME_AS_TEMPLATE # 0 C:\ESRI\AEJEE_XTRA\AEJEE23data\usa\states.shp</Process><Process ToolSource="c:\program files (x86)\arcgis\desktop10.6\ArcToolbox\Toolboxes\Data Management Tools.tbx\Project" Date="20210105" Time="152213">Project Carolinas_LCC E:\jared\Shapefiles\Carolinas_Merc.shp PROJCS['WGS_1984_World_Mercator',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],UNIT['Meter',1.0]] WGS_1984_(ITRF00)_To_NAD_1983 PROJCS['USA_Contiguous_Lambert_Conformal_Conic',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-96.0],PARAMETER['Standard_Parallel_1',33.0],PARAMETER['Standard_Parallel_2',45.0],PARAMETER['Latitude_Of_Origin',39.0],UNIT['Meter',1.0]] NO_PRESERVE_SHAPE # NO_VERTICAL</Process></lineage></DataProperties><ArcGISFormat>1.0</ArcGISFormat></Esri></metadata>
#!/usr/bin/python
#####################################################################
# plot_nclimgrid_daily.py
#
# *AUTHOR*
# Written By: Jared Rennie (@jjrennie)
#
# *DESCRIPTION*
# Takes nClimGrid daily data and plots for a given day. 2 plots
# are generated. 1 for CONUS, one for the Carolinas (NC and SC).
#
# *INPUT DATA LOCATION*
# I have provided some data in the source/ directory, however the
# latest data is below:
#
# WWW: https://www.ncei.noaa.gov/pub/data/daily-grids/beta/by-month/
# AWS S3: s3://noaa-nclimgrid-daily-pds/beta/by-month/
#
# *HOW TO RUN*
# python plot_nclimgrid_daily.py 2021 07 24 tmax
#####################################################################
# Import Modules
import numpy as np
import numpy.ma as ma
import sys, time, datetime, math, calendar
import xarray as xr
import geopandas as gpd
import rioxarray
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.io.shapereader as shpreader
from cartopy.feature import ShapelyFeature
from shapely.geometry import mapping
from metpy.plots import USCOUNTIES
# Declare User Directories
main_directory="."
dataset_directory=main_directory+'/input_nclimgrid'
shapefile_directory=main_directory+'/input_shapefile'
out_directory=main_directory+"/results_plots"
#################################################
# BEGIN PROGRAM
start=time.time()
# Read in Arguments
if len(sys.argv) < 5:
sys.exit("USAGE: <YYYY> <MM> <DD> <ELEMENT>")
year= sys.argv[1]
month= sys.argv[2]
day= sys.argv[3]
element= sys.argv[4]
# Get some Info Based on Date
day_counter=int(day)
current_date="%04i%02i%02i" % (int(year),int(month),int(day))
current_month="%04i%02i" % (int(year),int(month))
day_pos=datetime.datetime(int(year),int(month),int(day)).timetuple().tm_yday
if not calendar.isleap(int(year)) and int(month) >=3:
day_pos+=1
# Set info based on Element
if element == "tmax" or element == "tmin" or element == "tavg":
unit='°F'
if element=='tmax':
element_name='Maximum Temperature'
if element=='tmin':
element_name='Minimum Temperature'
if element=='tavg':
element_name='Average Temperature'
# Set Up Color Map
cmap='RdYlBu_r'
bounds=np.array([0,10,20,30,40,50,60,70,80,90,100,110])
if element == "prcp":
unit='inches'
element_name='Precipitation'
# Set Up Color Map
cmap='YlGnBu'
bounds=np.array([0.01,0.10,0.25,0.50,0.75,1.00,2.00,3.00,4.00], dtype='f')
# Set up some other Plotting info
dpi=300
plt.style.use('dark_background')
#################################################
# READ IN DATA
# Grab Daily nClimGrid Data (1 File Per Month)
infile_monthly=dataset_directory+'/'+str(element)+'-'+str(current_month)+'-grd.nc'
print('READING IN nClimGrid DATA: ',infile_monthly)
data_monthly = xr.open_dataset(infile_monthly)
# Get Lat/Lons
nclimgrid_lats=data_monthly.lat.values
nclimgrid_lons=data_monthly.lon.values
# Set Up Spatial Configurations of nClimGrid Data (For Clipping Purposes)
data_monthly=data_monthly.rio.set_spatial_dims(x_dim="lon", y_dim="lat", inplace=True)
data_monthly=data_monthly.rio.write_crs('epsg:4326', inplace=True)
# Read in Carolinas Shapefile For Clipping Purposes
input_shapefile=shapefile_directory+'/Carolinas_Merc.shp'
geo_shapefile = gpd.read_file(input_shapefile)
projection=geo_shapefile.crs
# Clip CONUS Data By Carolinas
data_monthly_clip=data_monthly.rio.clip(geo_shapefile.geometry.apply(mapping), geo_shapefile.crs, drop=False)
# Get Data, Convert from metric
if element == 'prcp':
conus_value=(data_monthly[element].values[day_counter-1,:,:] * 0.0393701)
carolinas_value=(data_monthly_clip[element].values[day_counter-1,:,:] * 0.0393701)
else:
conus_value=(data_monthly[element].values[day_counter-1,:,:] * 1.8) + 32.
carolinas_value=(data_monthly_clip[element].values[day_counter-1,:,:] * 1.8) + 32.
#################################################
# PLOTTING CONUS
print("PLOTTING CONUS")
# Set Up Colorbar info
vmin=np.min(bounds)
vmax=np.max(bounds)
extend='both'
norm = mcolors.BoundaryNorm(boundaries=bounds, ncolors=256)
cm = plt.cm.ScalarMappable(cmap=cmap)
cm.set_array(np.array(conus_value))
cm.set_clim(vmin, vmax)
# Set CONUS Bounds
minLat = 22
maxLat = 50
minLon = -120
maxLon = -73
# Set Up Figure
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')
# Add Boundaries
ax.add_feature(cfeature.COASTLINE,linewidth=0.5)
ax.add_feature(cfeature.BORDERS,linewidth=0.5)
ax.add_feature(cfeature.STATES,linewidth=0.5)
# Plot Data
ax.pcolormesh(nclimgrid_lons, nclimgrid_lats, conus_value,transform=ccrs.PlateCarree(),cmap=cmap,norm=norm,vmin=vmin,vmax=vmax)
# Add Colorbar
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.ax.tick_params(labelsize=15)
cbar.set_label(unit,size=15)
# Annotate Info On Graphic
nclimgrid_max="%6.1f" % np.nanmax(conus_value)
nclimgrid_min="%6.1f" % np.nanmin(conus_value)
plt.annotate('Source: nClimGrid Daily\nMade By: @jjrennie',xy=(1.045, -3.51), xycoords='axes fraction', fontsize=7,color='white',horizontalalignment='right', verticalalignment='bottom')
if element == "prcp":
plt.annotate('MAX: '+str(nclimgrid_max)+'"\nMIN: '+str(nclimgrid_min)+'"',xy=(0.045, -3.51), xycoords='axes fraction', fontsize=7,color='white',horizontalalignment='right', verticalalignment='bottom')
else:
plt.annotate('MAX: '+str(nclimgrid_max)+'°F\nMIN: '+str(nclimgrid_min)+'°F',xy=(0.045, -3.51), xycoords='axes fraction', fontsize=7,color='white',horizontalalignment='right', verticalalignment='bottom')
# Add Title and Save to File
plt.suptitle('Daily '+element_name+' for '+current_date,size=17,color='white',y=1.05)
plt.savefig(out_directory+'/nclimgrid-conus_'+element+'_'+current_date+'.png', format='png', dpi=dpi,bbox_inches='tight')
plt.clf()
plt.close()
#################################################
# PLOTTING CAROLINAS
print("PLOTTING CAROLINAS")
# Set Up Colorbar info
vmin=np.min(bounds)
vmax=np.max(bounds)
extend='both'
norm = mcolors.BoundaryNorm(boundaries=bounds, ncolors=256)
cm = plt.cm.ScalarMappable(cmap=cmap)
cm.set_array(np.array(carolinas_value))
cm.set_clim(vmin, vmax)
# Set Carolinas Bounds
minLat = 31.75
maxLat = 36.75
minLon = -85
maxLon = -75
# Set Up Figure
fig= plt.figure(num=1, figsize=(8,5), dpi=dpi, facecolor='w', edgecolor='k')
ax = fig.add_axes([0, 0, 1, 1], projection=ccrs.Mercator())
ax.set_extent([minLon, maxLon, minLat, maxLat], crs=ccrs.Geodetic())
ax.set_facecolor('#4a4a4a')
# Add Boundaries
ax.add_feature(USCOUNTIES.with_scale('500k'),linewidth=0.25,edgecolor='#4a4a4a')
car_bnds = ShapelyFeature(shpreader.Reader(input_shapefile).geometries(),ccrs.Mercator(), facecolor='none',edgecolor='black',linewidth=2)
ax.add_feature(car_bnds,zorder=9)
# Plot Data
ax.pcolormesh(nclimgrid_lons, nclimgrid_lats, carolinas_value,transform=ccrs.PlateCarree(),cmap=cmap,norm=norm,vmin=vmin,vmax=vmax)
# Add Colorbar
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.ax.tick_params(labelsize=15)
cbar.set_label(unit,size=15)
# Annotate Info On Graphic
nclimgrid_max="%6.1f" % np.nanmax(carolinas_value)
nclimgrid_min="%6.1f" % np.nanmin(carolinas_value)
plt.annotate('Source: nClimGrid Daily\nMade By: @jjrennie',xy=(1.045, -3.51), xycoords='axes fraction', fontsize=7,color='white',horizontalalignment='right', verticalalignment='bottom')
if element == "prcp":
plt.annotate('MAX: '+str(nclimgrid_max)+'"\nMIN: '+str(nclimgrid_min)+'"',xy=(0.045, -3.51), xycoords='axes fraction', fontsize=7,color='white',horizontalalignment='right', verticalalignment='bottom')
else:
plt.annotate('MAX: '+str(nclimgrid_max)+'°F\nMIN: '+str(nclimgrid_min)+'°F',xy=(0.045, -3.51), xycoords='axes fraction', fontsize=7,color='white',horizontalalignment='right', verticalalignment='bottom')
# Add Title and Save to File
plt.suptitle('Daily '+element_name+' for '+current_date,size=17,color='white',y=1.05)
plt.savefig(out_directory+'/nclimgrid-carolinas_'+element+'_'+current_date+'.png', format='png', dpi=dpi,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