def bin_stats(x, y, stat='median', nbins=360):
import scipy.stats
#bin_range = (x.min(), x.max())
bin_range = (0., 360.)
bin_width = (bin_range[1] - bin_range[0]) / nbins
print("Computing 1-degree bin statistics: %s" % stat)
bin_stat, bin_edges, bin_number = scipy.stats.binned_statistic(x, y, \
statistic=stat, bins=nbins, range=bin_range)
bin_centers = bin_edges[:-1] + bin_width/2.
bin_stat = np.ma.masked_invalid(bin_stat)
"""
#Mask bins in grid directions, can potentially contain biased stats
badbins = [0, 45, 90, 180, 225, 270, 315]
bin_stat = np.ma.masked_where(np.around(bin_edges[:-1]) % 45 == 0, bin_stat)
bin_edges = np.ma.masked_where(np.around(bin_edges[:-1]) % 45 == 0, bin_edges)
"""
#Generate plots
if False:
plt.figure()
#Need to pull out original values for each bin
#Loop through unique bin numbers, pull out original values into list of lists
#plt.boxplot(bin_stat, sym='')
plt.xlim(*bin_range)
plt.xticks(np.arange(bin_range[0],bin_range[1],30))
plt.ylabel('dh/tan(slope) (m)')
plt.xlabel('Aspect (1-deg bins)')
plt.figure()
plt.bar(bin_centers, bin_count)
plt.xlim(*bin_range)
plt.xticks(np.arange(bin_range[0],bin_range[1],30))
plt.ylabel('Count')
plt.xlabel('Aspect (1-deg bins)')
plt.show()
return bin_stat, bin_edges, bin_centers
#Function for fitting Nuth and Kaab (2011)
评论列表
文章目录