def plotConvergence(ax, locName): locId = locations['locId'][locations['locName'] == locName][0] locLon = locations['locLon'][locations['locId'] == locId][0] locLat = locations['locLat'][locations['locId'] == locId][0] records = database.queries.locationRecords(db, str(locId)) recs = records['wspd'][records['wspd'] > 0] data = np.zeros(int(NumSimulations * 365.25)) data[-len(recs):] = recs sortedmax = np.sort(data) emprp = empReturnPeriod(data) dd, rr = bootstrap(data, n=100) ax.plot(emprp[-10000:], data[-10000:], color='k', label="Mean ARI") ax.fill_between(rr[0, :], dd[1, :], dd[0, :], alpha=0.5, label="95th percentile") ax.set_xscale('log') #xlabel = 'Average recurrence interval (years)' #ylabel = 'Wind speed (m/s)' title = "{0} (n={1:d})".format(locName, len(recs)) ax.set_title(title) addARIGrid(ax)
def plotConvergence(ax, locName): locId = locations['locId'][locations['locName'] == locName][0] locLon = locations['locLon'][locations['locId'] == locId][0] locLat = locations['locLat'][locations['locId'] == locId][0] records = database.locationRecords(db, locId) recs = records['wspd'][records['wspd'] > 0] data = np.zeros(int(NumSimulations * 365.25)) data[-len(recs):] = recs sortedmax = np.sort(data) emprp = empReturnPeriod(data) random.shuffle(data) d1 = data[:int(len(data) / 2)] d2 = data[int(len(data) / 2 + 1):] sortedmax1 = np.sort(d1) sortedmax2 = np.sort(d2) emprp1 = empReturnPeriod(d1) emprp2 = empReturnPeriod(d2) ep = 1. / emprp ep1 = 1. / emprp1 ep2 = 1. / emprp2 ax.semilogx(emprp[emprp > 1], sortedmax[emprp > 1], color='k', label="Mean ARI") ax.semilogx(emprp2[emprp2 > 1], sortedmax2[emprp2 > 1], color="#006983", label="Convergence check 1", ls='--') ax.semilogx(emprp1[emprp1 > 1], sortedmax1[emprp1 > 1], color="#A33F1F", label="Convergence check 2", ls='--') ax.set_xscale('log') xlabel = 'Average recurrence interval (years)' ylabel = 'Wind speed (m/s)' title = "{0} ({1:5.2f}E, {2:5.2f}S, n={3:d})".format( locName, locLon, locLat, len(recs)) #ax.set_xlabel(xlabel) #ax.set_ylabel(ylabel) ax.set_title(title) addARIGrid(ax)
def plotConvergenceTest(locName): locId = locations['locId'][locations['locName'] == locName][0] locLon = locations['locLon'][locations['locId'] == locId][0] locLat = locations['locLat'][locations['locId'] == locId][0] records = database.queries.locationRecords(db, str(locId)) recs = records['wspd'][records['wspd'] > 0] data = np.zeros(int(NumSimulations * 365.25)) data[-len(recs):] = recs sortedmax = np.sort(data) emprp = empReturnPeriod(data) dd, rr = bootstrap(data, n=100) ep = 1. / emprp ep1 = 1. / rr[0, :] ep2 = 1. / rr[1, :] mn = dd.mean(axis=0) delta = np.abs(np.diff(dd, axis=0)) fdelta = delta / mn fig, ax1 = plt.subplots(1, 1, figsize=figsize) ax1.fill_between(rr[0, :], dd[1, :], dd[0, :], alpha=0.5, label="95th percentile") ax1.plot(emprp[-10000:], data[-10000:], color='k', label="Mean ARI") ax1.set_xscale('log') xlabel = 'Average recurrence interval (years)' ylabel = 'Wind speed (m/s)' title = "ARI wind speeds at " + locName + \ " \n(%5.2f,%5.2f, n=%d)"%(locLon, locLat, len(recs)) ax1.set_xlabel(xlabel) ax1.set_ylabel(ylabel) ax1.set_title(title) ax1.legend(loc=2) addARIGrid(ax1) fig.tight_layout() plt.savefig(os.path.join(plotPath, "{0:05d}_ARI.png".format(locId)), bbox_inches='tight') plt.close() fig2, ax2 = plt.subplots(1, 1, figsize=figsize) ax2.semilogy(sortedmax[-10000:], ep[-10000:], color="k", label="Mean AEP") ax2.fill_betweenx(1. / rr[0, :], dd[0, :], dd[1, :], alpha=0.5, label="95th percentile") ax2.set_xlabel(ylabel) title = "AEP wind speeds at " + locName + \ " \n(%5.2f,%5.2f, n=%d)"%(locLon, locLat, len(recs)) ax2.set_ylabel("Exceedance probability (events/year)") ax2.set_title(title) ax2.legend(loc=1) addAEPGrid(ax2) fig.tight_layout() plt.savefig(os.path.join(plotPath, "{0:05d}_AEP.png".format(locId)), bbox_inches='tight') plt.close()
def calculateARI(data, years): emprp = empReturnPeriod(np.sort(data)) return np.sort(data)[-years:], emprp[-years:]
def plotConvergenceTest(locName): locId = locations['locId'][locations['locName'] == locName][0] locLon = locations['locLon'][locations['locId'] == locId][0] locLat = locations['locLat'][locations['locId'] == locId][0] records = database.locationRecords(db, locId) recs = records['wspd'][records['wspd'] > 0] data = np.zeros(int(NumSimulations * 365.25)) data[-len(recs):] = recs sortedmax = np.sort(data) emprp = empReturnPeriod(data) random.shuffle(data) d1 = data[:int(len(data) / 2)] d2 = data[int(len(data) / 2):] sortedmax1 = np.sort(d1) sortedmax2 = np.sort(d2) emprp1 = empReturnPeriod(d1) emprp2 = empReturnPeriod(d2) ep = 1. / emprp ep1 = 1. / emprp1 ep2 = 1. / emprp2 mn = (sortedmax1[emprp1 > 1] + sortedmax2[emprp2 > 1]) / 2. delta = np.abs(sortedmax1[emprp1 > 1] - sortedmax2[emprp2 > 1]) fdelta = delta / mn fig, ax1 = plt.subplots(1, 1) ax1.semilogx(emprp[emprp > 1], sortedmax[emprp > 1], color='k', label="Mean ARI") ax1.semilogx(emprp2[emprp2 > 1], sortedmax2[emprp2 > 1], color="#006983", label="Convergence check 1") ax1.semilogx(emprp1[emprp1 > 1], sortedmax1[emprp1 > 1], color="#A33F1F", label="Convergence check 2") ax1.set_xscale('log') xlabel = 'Average recurrence interval (years)' ylabel = 'Wind speed (m/s)' title = "ARI wind speeds at " + locName + \ " \n(%5.2f,%5.2f, n=%d)"%(locLon, locLat, len(recs)) ax1.set_xlabel(xlabel) ax1.set_ylabel(ylabel) ax1.set_title(title) ax1.legend(loc=2) addARIGrid(ax1) fig.tight_layout() plt.savefig(os.path.join(plotPath, "{0:05d}_ARI.png".format(locId)), bbox_inches='tight') plt.close() fig2, ax2 = plt.subplots(1, 1) ax2.semilogy(sortedmax[emprp > 1], ep[emprp > 1], color="k", label="Mean AEP") ax2.semilogy(sortedmax1[emprp1 > 1], ep1[emprp1 > 1], color="#006983", label="Convergence check 1") ax2.semilogy(sortedmax2[emprp2 > 1], ep2[emprp2 > 1], color="#A33F1F", label="Convergence check 2") ax2.set_xlabel(ylabel) title = "AEP wind speeds at " + locName + \ " \n(%5.2f,%5.2f, n=%d)"%(locLon, locLat, len(recs)) ax2.set_ylabel("Exceedance probability (events/year)") ax2.set_title(title) ax2.legend(loc=1) addAEPGrid(ax2) fig.tight_layout() plt.savefig(os.path.join(plotPath, "{0:05d}_AEP.png".format(locId)), bbox_inches='tight') plt.close() fig3, (ax3, ax4) = plt.subplots(2, 1, sharex=True) ax3.fill_between(emprp[emprp > 1][0:-1:2], fdelta, color="#006983", alpha=0.5) ax3.set_ylabel('Fractional difference') ax3.set_title("Difference in convergence test ARI wind speeds at " + \ locName + " \n(%5.2f,%5.2f, n=%d)"%(locLon, locLat, len(recs))) ax3.set_xscale('log') addARIGrid(ax3) ax4.fill_between(emprp[emprp > 1][0:-1:2], delta, color="#006983", alpha=0.5) ax4.set_ylabel("Difference (m/s)") ax4.set_xlabel(xlabel) ax4.set_xscale('log') addARIGrid(ax4) fig.tight_layout() plt.savefig(os.path.join(plotPath, "{0:05d}_ARI_delta.png".format(locId)), bbox_inches='tight') plt.close()