Commit 436c47f6 authored by abuddenberg's avatar abuddenberg

Merging

parent a8c6eebc
......@@ -6,3 +6,5 @@ src/Blah.pyc
dist/*/*.sum
dist/*/*.csv
data/*/*.nc
*.pyc
.idea/*
......@@ -6,15 +6,29 @@ Created on Nov 20, 2012
DATA_DIR = '/Users/abuddenberg/workspace/plot_precip_maps/data/'
NA_PRECIP_FILES = [
(DATA_DIR + 'pr_rcp85_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc', 'pr_rcp85_2071-2099_NA_{}.eps'),
(DATA_DIR + 'pr_rcp26_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc', 'pr_rcp26_2071-2099_NA_{}.eps'),
(DATA_DIR + 'pr_sresa2_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc', 'pr_sresa2_2071-2099_NA_{}.eps')
(DATA_DIR + 'pr_rcp85_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc', 'pr_rcp85_2071-2099_north_american_{}.eps'),
(DATA_DIR + 'pr_rcp26_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc', 'pr_rcp26_2071-2099_north_american_{}.eps'),
(DATA_DIR + 'pr_sresa2_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc', 'pr_sresa2_2071-2099_north_american_{}.eps'),
(DATA_DIR + 'pr_rcp45_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc', 'pr_rcp45_2071-2099_north_american_{}.eps'),
(DATA_DIR + 'pr_rcp60_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc', 'pr_rcp60_2071-2099_north_american_{}.eps'),
(DATA_DIR + 'pr_sresa1b_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc', 'pr_sresa1b_2071-2099_north_american_{}.eps'),
(DATA_DIR + 'pr_sresb1_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc', 'pr_sresb1_2071-2099_north_american_{}.eps'),
]
NA_SCENARIOS_FILES = {
'RCP8.5': (DATA_DIR + 'pr_rcp85_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc'),
'RCP2.6': (DATA_DIR + 'pr_rcp26_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc'),
'SRES A2': (DATA_DIR + 'pr_sresa2_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc'),
'RCP4.5': (DATA_DIR + 'pr_rcp45_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc'),
'RCP6.0': (DATA_DIR + 'pr_rcp60_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc'),
'SRES A1B': (DATA_DIR + 'pr_sresa1b_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc'),
'SRES B1': (DATA_DIR + 'pr_sresb1_1970-1999_2071-2099_percent_change.nc_hatched_North_America_AR5_white.nc'),
}
GLOBAL_PRECIP_FILES = [
(DATA_DIR + 'pr_rcp26_2071-2099_percent_change-1.nc_hatched_global_ar5_white.nc', 'pr_rcp26_2071-2099_global_{}.eps'),
(DATA_DIR + 'pr_rcp85_2071-2099_percent_change-1.nc_hatched_global_ar5_white.nc', 'pr_rcp85_2071-2099_global_{}.eps')
(DATA_DIR + 'pr_rcp26_1970-1999_2071-2099_percent_change.nc_hatched_Global_AR5_white.nc', 'pr_rcp26_2071-2099_global_{}.eps'),
(DATA_DIR + 'pr_rcp85_1970-1999_2071-2099_percent_change.nc_hatched_Global_AR5_white.nc', 'pr_rcp85_2071-2099_global_{}.eps')
]
......
......@@ -36,7 +36,18 @@ for infilename, outfilename in GLOBAL_PRECIP_FILES:
m.drawcountries()
lons, lats = meshgrid(lon_data, lat_data)
x,y = m(lons, lats)
#pcolor coordinates should refer to the lower left corner of the grid box;
# the data refers to the center of the grid box. Shift the lon and lat south and west by half the height and
# width of the grid box to obtain the correct representation.
grid_width = lons[0][1] - lons[0][0]
grid_height = lats[1][0] - lats[0][0]
lons_shifted = (lons - 0.5 * grid_width)
lats_shifted = (lats - 0.5 * grid_height)
x, y = m(lons, lats)
x_shifted, y_shifted = m(lons_shifted, lats_shifted)
#Build boolean masks of the gridpoint for each category
stipples_mask = np.ma.getmask(np.ma.masked_equal(signif, 1.))
......@@ -57,8 +68,10 @@ for infilename, outfilename in GLOBAL_PRECIP_FILES:
data = np.ma.masked_array(data.filled(2.0)) #2.0 denotes areas of statistical uncertainty
weird = m.pcolor(x,y, data)
weird = m.pcolor(x_shifted, y_shifted, data)
m.colorbar(weird,location='right',pad="5%")
m.scatter(x, y, 3, marker='o')
#Tests for overlap (There shouldn't be any)
# print np.any(np.logical_and(stipples_mask, zeros_mask))
......@@ -66,5 +79,5 @@ for infilename, outfilename in GLOBAL_PRECIP_FILES:
# print np.any(np.logical_and(third_cat_mask, stipples_mask))
# plt.savefig('../dist/' + outfilename.format('categories'), format='eps', dpi=200)
plt.show()
\ No newline at end of file
plt.savefig('../dist/' + outfilename.format('categories'), format='eps', dpi=200)
# plt.show()
\ No newline at end of file
......@@ -44,16 +44,14 @@ for infilename, outfilename in GLOBAL_PRECIP_FILES:
lons, lats = meshgrid(lon_data, lat_data)
x,y = m(lons, lats)
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, '//'])
# m.colorbar(hatching,location='right',pad="5%")
# plt.savefig('../dist/' + outfilename.format('percent_change'), format='eps', dpi=200)
plt.show()
\ No newline at end of file
plt.savefig('../dist/' + outfilename.format('percent_change'), format='eps', dpi=200)
# plt.show()
\ No newline at end of file
......@@ -5,56 +5,137 @@ Created on Nov 27, 2012
"""
from scipy.io.netcdf import netcdf_file
from mpl_toolkits.basemap import Basemap
from numpy import meshgrid
import numpy as np
import matplotlib.pyplot as plt
from config import NA_PRECIP_FILES, SEASONS
for infilename, outfilename in NA_PRECIP_FILES:
nc = netcdf_file(infilename)
lat_data = nc.variables['lat'].data
lon_data = nc.variables['lon'].data
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=10,
urcrnrlat=40,
llcrnrlon=-160,
urcrnrlon=-158,
resolution='l',area_thresh=1
)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
lons, lats = meshgrid(lon_data, lat_data)
x,y = m(lons, lats)
levels_10 = [-30, -20, -10, 0, 10, 20, 30]
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, '//'])
# m.colorbar(hatching,location='right',pad="5%")
plt.savefig('../dist/' + outfilename.format('HI_percent_change'), format='eps', dpi=200)
# plt.show()
\ No newline at end of file
map_proj = {
'projection': 'aea',
'lon_0': -96,
'lat_0': 37.5,
'lat_1': 29.5,
'lat_2': 45.5,
'llcrnrlat': 10,
'urcrnrlat': 40,
'llcrnrlon': -160,
'urcrnrlon': -158,
'resolution': 'l',
'area_thresh': 1
}
def main():
plot_precip_map()
plot_category_map()
def plot_precip_map():
for infilename, outfilename in NA_PRECIP_FILES:
nc = netcdf_file(infilename)
lat_data = nc.variables['lat'].data
lon_data = nc.variables['lon'].data
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(**map_proj)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
lons, lats = np.meshgrid(lon_data, lat_data)
x,y = m(lons, lats)
levels_10 = [-30, -20, -10, 0, 10, 20, 30]
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, '//'])
# m.colorbar(hatching,location='right',pad="5%")
plt.savefig('../dist/' + outfilename.format('HI_percent_change'), format='eps', dpi=200)
# plt.show()
def plot_category_map():
for infilename, outfilename in NA_PRECIP_FILES:
nc = netcdf_file(infilename)
lat_data = nc.variables['lat'].data
lon_data = nc.variables['lon'].data
fig = plt.figure(figsize=(25, 16), dpi=100, tight_layout=True)
for i, season in enumerate(['Winter', 'Spring', 'Summer', 'Fall']): #['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(**map_proj)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
lons, lats = np.meshgrid(lon_data, lat_data)
#pcolor coordinates should refer to the lower left corner of the grid box;
# the data refers to the center of the grid box. Shift the lon and lat south and west by half the height and
# width of the grid box to obtain the correct representation.
grid_width = lons[0][1] - lons[0][0]
grid_height = lats[1][0] - lats[0][0]
lons_shifted = (lons - 0.5 * grid_width)
lats_shifted = (lats - 0.5 * grid_height)
x, y = m(lons, lats)
x_shifted, y_shifted = m(lons_shifted, lats_shifted)
#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(np.ma.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; red
data.mask = zeros_mask
data = np.ma.masked_array(data.filled(1.0)) #1.0 denotes areas little change; blue
data.mask = third_cat_mask
data = np.ma.masked_array(data.filled(2.0)) #2.0 denotes areas of statistical uncertainty; green
weird = m.pcolor(x_shifted, y_shifted, data)
m.colorbar(weird, location='right', pad="5%")
m.scatter(x, y, 3, marker='o')
#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('HI_categories'), format='eps', dpi=200)
# plt.show()
main()
\ No newline at end of file
......@@ -31,15 +31,15 @@ for infilename, outfilename in NA_PRECIP_FILES:
lat_data = nc.variables['lat'].data
lon_data = nc.variables['lon'].data
fig = plt.figure(figsize=(25,16), dpi=100, tight_layout=True)
for i, season in enumerate(['Winter', 'Spring', 'Summer', 'Fall']):
for i, season in enumerate(['Winter', 'Spring', 'Summer', 'Fall']): #['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(231 + i)
plt.title(season)
m = Basemap(
......@@ -59,9 +59,20 @@ for infilename, outfilename in NA_PRECIP_FILES:
m.drawcoastlines()
m.drawstates()
m.drawcountries()
lons, lats = meshgrid(lon_data, lat_data)
x,y = m(lons, lats)
#pcolor coordinates should refer to the lower left corner of the grid box;
# the data refers to the center of the grid box. Shift the lon and lat south and west by half the height and
# width of the grid box to obtain the correct representation.
grid_width = lons[0][1] - lons[0][0]
grid_height = lats[1][0] - lats[0][0]
lons_shifted = (lons - 0.5 * grid_width)
lats_shifted = (lats - 0.5 * grid_height)
x, y = m(lons, lats)
x_shifted, y_shifted = m(lons_shifted, lats_shifted)
#Build boolean masks of the gridpoint for each category
stipples_mask = np.ma.getmask(np.ma.masked_equal(signif, 1.))
......@@ -77,20 +88,21 @@ for infilename, outfilename in NA_PRECIP_FILES:
data.mask = zeros_mask
data = np.ma.masked_array(data.filled(1.0)) #1.0 denotes areas little change; blue
data.mask = third_cat_mask
data = np.ma.masked_array(data.filled(2.0)) #2.0 denotes areas of statistical uncertainty; green
weird = m.pcolor(x,y, data)
m.colorbar(weird,location='right',pad="5%")
weird = m.pcolor(x_shifted, y_shifted, data)
m.colorbar(weird, location='right', pad="5%")
m.scatter(x, y, 3, marker='o')
#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('north_american_categories'), format='eps', dpi=200)
# plt.savefig('../dist/' + outfilename.format('categories'), format='eps', dpi=200)
plt.show()
......@@ -25,7 +25,7 @@ for infilename, outfilename in NA_PRECIP_FILES:
fig = plt.figure(figsize=(25,16), dpi=100, tight_layout=True)
for i, season in enumerate(['Winter', 'Spring', 'Summer', 'Fall']):
for i, season in enumerate(['Winter', 'Spring', 'Summer', 'Fall']): #['Winter', 'Spring', 'Summer', 'Fall']
data_var, signif_var = SEASONS[season]
data = nc.variables[data_var].data
......@@ -53,13 +53,13 @@ for infilename, outfilename in NA_PRECIP_FILES:
lons, lats = meshgrid(lon_data, lat_data)
x,y = m(lons, lats)
levels_10 = [-30, -20, -10, 0, 10, 20, 30]
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, '//'])
hatching = m.contourf(x, y, signif, 1, colors='none', hatches=[None, '//'])
# m.colorbar(hatching,location='right',pad="5%")
......
__author__ = 'abuddenberg'
"""
The purpose of this program is to create a contour plot of seasonal precipitation change across various model scenarios
for summer and winter (for now)
"""
from mpl_toolkits.basemap import Basemap
from scipy.io.netcdf import netcdf_file
import numpy as np
import matplotlib.pyplot as plt
from config import SEASONS, NA_SCENARIOS_FILES
map_proj = {
'projection': 'aea',
'lon_0': -96,
'lat_0': 37.5,
'lat_1': 29.5,
'lat_2': 45.5,
'llcrnrlat': 12,
'urcrnrlat': 80,
'llcrnrlon': -135,
'urcrnrlon': -25,
'resolution': 'l',
'area_thresh': 10000
}
def main():
plot_precip_map()
plot_category_map()
def plot_precip_map():
for season in ['Winter', 'Summer']:
fig, axes = plt.subplots(figsize=(25, 64), tight_layout=True)
for i, scenario in enumerate(['SRES A2', 'RCP8.5', 'SRES A1B', 'RCP6.0', 'SRES B1', 'RCP4.5', 'RCP2.6']):
precip_var, signif_var = SEASONS[season]
nc = netcdf_file(NA_SCENARIOS_FILES[scenario])
lat_data = nc.variables['lat'].data
lon_data = nc.variables['lon'].data
precip_data = nc.variables[precip_var].data
signif_data = nc.variables[signif_var].data
#Juke RCP2.6 plot over to the right column
if scenario == 'RCP2.6':
i += 1
ax = plt.subplot(421 + i)
ax.autoscale_view('tight')
plt.title(scenario)
m = Basemap(**map_proj)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
lons, lats = np.meshgrid(lon_data, lat_data)
levels_10 = [-30, -20, -10, 0, 10, 20, 30]
prcp = m.contourf(lons, lats, precip_data, latlon=True, cmap=plt.get_cmap('BrBG'), levels=levels_10, extend='both')
hatching = m.contourf(lons, lats, signif_data, 1, latlon=True, colors='none', hatches=[None, '//'])
# m.colorbar(hatching, location='right', pad="5%")
#Let's make a shared colorbar!
cax = fig.add_axes([0.05, 0.01, 0.9, 0.01])
plt.colorbar(prcp, cax=cax, orientation='horizontal')
plt.suptitle('Projected {}time Precipitation Changes'.format(season), size='42')
plt.savefig('../dist/{}time_precip.eps'.format(season), format='eps', dpi=200)
# plt.show()
def plot_category_map():
for season in ['Winter', 'Summer']:
fig, axes = plt.subplots(figsize=(25, 64), tight_layout=True)
for i, scenario in enumerate(['SRES A2', 'RCP8.5', 'SRES A1B', 'RCP6.0', 'SRES B1', 'RCP4.5', 'RCP2.6']):
precip_var, signif_var = SEASONS[season]
nc = netcdf_file(NA_SCENARIOS_FILES[scenario])
lat_data = nc.variables['lat'].data
lon_data = nc.variables['lon'].data
signif_data = nc.variables[signif_var].data
#Juke RCP2.6 plot over to the right column
if scenario == 'RCP2.6':
i += 1
ax = plt.subplot(421 + i)
ax.autoscale_view('tight')
plt.title(scenario)
m = Basemap(**map_proj)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
lons, lats = np.meshgrid(lon_data, lat_data)
#pcolor coordinates should refer to the lower left corner of the grid box;
# the data refers to the center of the grid box. Shift the lon and lat south and west by half the height and
# width of the grid box to obtain the correct representation.
grid_width = lons[0][1] - lons[0][0]
grid_height = lats[1][0] - lats[0][0]
lons_shifted = (lons - 0.5 * grid_width)
lats_shifted = (lats - 0.5 * grid_height)
x, y = m(lons, lats)
x_shifted, y_shifted = m(lons_shifted, lats_shifted)
categories = m.pcolor(x_shifted, y_shifted, signif_data)
m.scatter(x, y, 3, marker='o')
cax = fig.add_axes([0.05, 0.01, 0.9, 0.01])
plt.colorbar(categories, cax=cax, orientation='horizontal')
plt.suptitle('Projected {}time Precipitation Changes'.format(season))
plt.savefig('../dist/{}time_categories.eps'.format(season), format='eps', dpi=200)
# plt.show()
main()
\ 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