Created
June 20, 2014 21:40
-
-
Save henryroe/3f34c604d74d7e46403c to your computer and use it in GitHub Desktop.
Plot NSF AST funding data for per-year funding of grants
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
max_award_per_year = 3e5 # above this amount just bin in to top bin | |
years_per_bin = 1.0 | |
award_bin_size = 10000 | |
start_year = np.array([a.year + (a.month - 1)/12. for a in awards['StartDate']]) | |
year_bins = np.arange(np.floor(start_year.min()), np.ceil(start_year.max())+1, years_per_bin) | |
awarded_per_year = np.array(awards['AwardedAmountToDate']/awards['DurationYears']) | |
awarded_per_year_mean_per_bin = np.zeros(year_bins.size - 1) | |
awarded_per_year_median_per_bin = np.zeros(year_bins.size - 1) | |
year_per_bin = np.zeros(year_bins.size - 1) | |
for i in np.arange(year_bins.size - 1): | |
year_per_bin[i] = (year_bins[i+1] + year_bins[i])/2.0 | |
curmask = (start_year >= year_bins[i]) & (start_year < year_bins[i+1]) | |
awarded_per_year_mean_per_bin[i] = awarded_per_year[curmask].mean() | |
awarded_per_year_median_per_bin[i] = np.median(awarded_per_year[curmask]) | |
awarded_per_year[awarded_per_year > (max_award_per_year - 1.0)] = max_award_per_year - 1.0 | |
award_bins = np.arange(0., max_award_per_year + 1., award_bin_size) | |
H, xedges, yedges = np.histogram2d(start_year, awarded_per_year, bins=[year_bins, award_bins]) | |
# H needs to be rotated and flipped | |
H = np.rot90(H) | |
H = np.flipud(H) | |
# Mask zeros | |
Hmasked = np.ma.masked_where(H==0,H) # Mask pixels with a value of zero | |
# Plot 2D histogram using pcolor | |
fig2 = plt.figure(figsize=(12,5)) | |
plt.pcolormesh(xedges,yedges,Hmasked) | |
plt.plot(year_per_bin, awarded_per_year_mean_per_bin, 'r', label='mean', linewidth=2) | |
plt.plot(year_per_bin, awarded_per_year_median_per_bin, 'm', label='median',linewidth=3) | |
plt.xlabel('Start Year for each grant') | |
plt.ylabel('$/year awarded to date') | |
plt.xlim(1970, 2015) | |
plt.ylim(0, max_award_per_year) | |
plt.legend(loc='upper left') | |
cbar = plt.colorbar() | |
cbar.ax.set_ylabel('# of grants') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment