Commit f3e4ec68 authored by abuddenberg's avatar abuddenberg

Added new category plot. Added descriptive comments

parent 226b3046
......@@ -6,9 +6,15 @@ Created on Nov 20, 2012
DATA_DIR = '/Users/abuddenberg/workspace/plot_precip_maps/data/'
NA_PRECIP_FILES = [
(DATA_DIR + 'pr_rcp85_2071-2099_percent_change.nc_hatched_north_america_ar5_white.nc', 'pr_rcp85_2071-2099_NA_percent_change_grads15.eps'),
(DATA_DIR + 'pr_rcp26_2071-2099_percent_change.nc_hatched_north_america_ar5_white.nc', 'pr_rcp26_2071-2099_NA_percent_change_grads15.eps'),
(DATA_DIR + 'pr_sresa2_2071-2099_percent_change.nc_hatched_north_america_ar5_white.nc', 'pr_sresa2_2071-2099_NA_percent_change_grads15.eps')
(DATA_DIR + 'pr_rcp85_2071-2099_percent_change.nc_hatched_north_america_ar5_white.nc', 'pr_rcp85_2071-2099_NA_percent_change.eps'),
(DATA_DIR + 'pr_rcp26_2071-2099_percent_change.nc_hatched_north_america_ar5_white.nc', 'pr_rcp26_2071-2099_NA_percent_change.eps'),
(DATA_DIR + 'pr_sresa2_2071-2099_percent_change.nc_hatched_north_america_ar5_white.nc', 'pr_sresa2_2071-2099_NA_percent_change.eps')
]
NA_CATEGORY_FILES = [
(DATA_DIR + 'pr_rcp85_2071-2099_percent_change.nc_hatched_north_america_ar5_white.nc', 'pr_rcp85_2071-2099_NA_percent_change_categories.eps'),
(DATA_DIR + 'pr_rcp26_2071-2099_percent_change.nc_hatched_north_america_ar5_white.nc', 'pr_rcp26_2071-2099_NA_percent_change_categories.eps'),
(DATA_DIR + 'pr_sresa2_2071-2099_percent_change.nc_hatched_north_america_ar5_white.nc', 'pr_sresa2_2071-2099_NA_percent_change_categories.eps')
]
GLOBAL_PRECIP_FILES = [
......
No preview for this file type
......@@ -2,6 +2,13 @@
Created on Nov 21, 2012
@author: abuddenberg
Creates a contour plot of projected precipitation change
globally for each emmissions scenario at the end of the
21st century vs the base period (presumably 1971-1999).
The hatched area denotes areas of higher statistical significance.
'''
from scipy.io.netcdf import netcdf_file
from mpl_toolkits.basemap import Basemap
......@@ -33,7 +40,6 @@ for infilename, outfilename in GLOBAL_PRECIP_FILES:
)
m.drawcoastlines()
# m.drawstates()
m.drawcountries()
lons, lats = meshgrid(lon_data, lat_data)
......
'''
Created on Nov 29, 2012
@author: abuddenberg
The purpose of this program is to plot the categories of statistical
significance for the various emissions scenarios in the North American
area. This plot is used in conjection with the accompanying contour plots
to spot-check anomalies caused by the smoothing in those plots (as well as to
verify the data itself).
The categories are as follows:
1.0 denotes areas little change
2.0 denotes areas of statistical uncertainty
3.0 denotes areas of statistical significance
Fun stuff
'''
from scipy.io.netcdf import netcdf_file
from mpl_toolkits.basemap import Basemap
from numpy import meshgrid
from numpy.ma import masked_equal
import numpy as np
import matplotlib.pyplot as plt
from config import NA_CATEGORY_FILES, SEASONS
for infilename, outfilename in NA_CATEGORY_FILES:
nc = netcdf_file(infilename)
lat_data = nc.variables['lat'].data
lon_data = nc.variables['lon'].data - 360.
fig = plt.figure(figsize=(25,16), dpi=100, tight_layout=True)
for i, season in enumerate(['Winter', 'Spring', 'Summer', 'Fall']):
data_var, signif_var = SEASONS[season]
data = nc.variables[data_var].data
signif = nc.variables[signif_var].data
ax = fig.add_subplot(221 + i)
plt.title(season)
m = Basemap(
projection='aea',
lon_0=-96,
lat_0=37.5,
lat_1=29.5,
lat_2=45.5,
# lat_ts=median(lats),
llcrnrlat=12,
urcrnrlat=80,
llcrnrlon=-135,
urcrnrlon=-25,
resolution='l',area_thresh=10000
)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
lons, lats = meshgrid(lon_data, lat_data)
x,y = m(lons, lats)
#Build boolean masks of the gridpoint for each category
stipples_mask = np.ma.getmask(np.ma.masked_equal(signif, 1.))
zeros_mask = np.ma.getmask(masked_equal(data, 0.0))
both_mask = np.ma.mask_or(stipples_mask, zeros_mask)
third_cat_mask = ~both_mask
#There's got to be a better way of doing this than copying the array
data = np.ma.masked_array(data)
data.mask = stipples_mask
data = np.ma.masked_array(data.filled(3.0)) #3.0 denotes areas of statistical significance
data.mask = zeros_mask
data = np.ma.masked_array(data.filled(1.0)) #1.0 denotes areas little change
data.mask = third_cat_mask
data = np.ma.masked_array(data.filled(2.0)) #2.0 denotes areas of statistical uncertainty
weird = m.pcolor(x,y, data)
m.colorbar(weird,location='right',pad="5%")
#Tests for overlap (There shouldn't be any)
# print np.any(np.logical_and(stipples_mask, zeros_mask))
# print np.any(np.logical_and(third_cat_mask, zeros_mask))
# print np.any(np.logical_and(third_cat_mask, stipples_mask))
plt.savefig('../dist/' + outfilename, format='eps', dpi=200)
# plt.show()
\ No newline at end of file
......@@ -2,6 +2,13 @@
Created on Nov 16, 2012
@author: abuddenberg
Creates a very lovely contour plot of projected precipitation change
over North American for each emmissions scenario at the end of the
21st century vs the base period (presumably 1971-1999).
The hatched area denotes areas of higher statistical significance.
'''
from scipy.io.netcdf import netcdf_file
from mpl_toolkits.basemap import Basemap
......@@ -51,7 +58,7 @@ for infilename, outfilename in NA_PRECIP_FILES:
levels_15 = [-45, -30, -15, 0, 15, 30, 45]
levels_10 = [-30, -20, -10, 0, 10, 20, 30]
prcp = m.contourf(x, y, data, cmap=plt.get_cmap('BrBG'), levels=levels_15, extend='both')
prcp = m.contourf(x, y, data, cmap=plt.get_cmap('BrBG'), levels=levels_10, extend='both')
m.colorbar(prcp, location='bottom',pad="5%")
hatching = m.contourf(x,y, signif, 1, colors='none',hatches=[None, '//'])
......
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