def calculateCI(Vr, years, nodata, minRecords, yrsPerSim=1, sample_size=50, prange=90): """ Fit a GEV to the wind speed records for a 2-D extent of wind speed values, providing a confidence range by resampling at random from the input values. :param Vr: `numpy.ndarray` of wind speeds (3-D - event, lat, lon) :param years: `numpy.ndarray` of years for which to evaluate return period values. :param float nodata: missing data value. :param int minRecords: minimum number of valid wind speed values required to fit distribution. :param int yrsPerSim: Values represent block maxima - this value indicates the time span of the block (default 1). :param int sample_size: number of records to randomly sample for calculating confidence interval of the fit. :param float prange: percentile range. :return: `numpy.ndarray` of return period wind speed values """ lower = (100 - prange) / 2. upper = 100. - lower nrecords = Vr.shape[0] nsamples = nrecords / sample_size RpUpper = nodata*np.ones((len(years), Vr.shape[1], Vr.shape[2]), dtype='f') RpLower = nodata*np.ones((len(years), Vr.shape[1], Vr.shape[2]), dtype='f') w = np.zeros((len(years), nsamples), dtype='f') wUpper = np.zeros((len(years)), dtype='f') wLower = np.zeros((len(years)), dtype='f') for i in xrange(Vr.shape[1]): for j in xrange(Vr.shape[2]): if Vr[:, i, j].max() > 0.0: random.shuffle(Vr[:, i, j]) for n in xrange(nsamples): nstart = n*sample_size nend = (n + 1)*sample_size - 1 vsub = Vr[nstart:nend, i, j] vsub.sort() if vsub.max( ) > 0.: w[:, n], loc, scale, shp = evd.estimateEVD(vsub, years, nodata, minRecords/10, yrsPerSim) for n in range(len(years)): wUpper[n] = percentile(w[n,:], upper) wLower[n] = percentile(w[n,:], lower) RpUpper[:, i, j] = wUpper RpLower[:, i, j] = wLower return RpUpper, RpLower
def calculate(Vr, years, nodata, minRecords, yrsPerSim): """ Fit a GEV to the wind speed records for a 2-D extent of wind speed values Parameters: ----------- :param Vr: `numpy.ndarray` of wind speeds (3-D - event, lat, lon) :param years: `numpy.ndarray` of years for which to evaluate return period values Returns: -------- :param Rp: `numpy.ndarray` of return period wind speed values :param loc: `numpy.ndarray` of location parameters in the domain of `Vr` :param scale: `numpy.ndarray` of scale parameters in the domain of `Vr` :param shp: `numpy.ndarray` of shape parameters in the domain of `Vr` """ Vr.sort(axis=0) Rp = np.zeros((len(years),) + Vr.shape[1:], dtype='f') loc = np.zeros(Vr.shape[1:], dtype='f') scale = np.zeros(Vr.shape[1:], dtype='f') shp = np.zeros(Vr.shape[1:], dtype='f') for i in xrange(Vr.shape[1]): for j in xrange(Vr.shape[2]): if Vr[:,i,j].max() > 0.0: w, l, sc, sh = evd.estimateEVD(Vr[:,i,j], years, nodata, minRecords, yrsPerSim) Rp[:, i, j] = w loc[i, j] = l scale[i, j] = sc shp[i, j] = sh return Rp, loc, scale, shp
def calculate(Vr, years, nodata, minRecords, yrsPerSim): """ Fit a GEV to the wind speed records for a 2-D extent of wind speed values :param Vr: `numpy.ndarray` of wind speeds (3-D - event, lat, lon) :param years: `numpy.ndarray` of years for which to evaluate return period values Returns: -------- :param Rp: `numpy.ndarray` of return period wind speed values :param loc: `numpy.ndarray` of location parameters in the domain of `Vr` :param scale: `numpy.ndarray` of scale parameters in the domain of `Vr` :param shp: `numpy.ndarray` of shape parameters in the domain of `Vr` """ Vr.sort(axis=0) Rp = np.zeros((len(years), ) + Vr.shape[1:], dtype='f') loc = np.zeros(Vr.shape[1:], dtype='f') scale = np.zeros(Vr.shape[1:], dtype='f') shp = np.zeros(Vr.shape[1:], dtype='f') for i in xrange(Vr.shape[1]): for j in xrange(Vr.shape[2]): if Vr[:, i, j].max() > 0.0: w, l, sc, sh = evd.estimateEVD(Vr[:, i, j], years, nodata, minRecords, yrsPerSim) Rp[:, i, j] = w loc[i, j] = l scale[i, j] = sc shp[i, j] = sh return Rp, loc, scale, shp
def calculateCI(Vr, years, nodata, minRecords, yrsPerSim=1, sample_size=50, prange=90): """ Fit a GEV to the wind speed records for a 2-D extent of wind speed values, providing a confidence range by resampling at random from the input values. :param Vr: `numpy.ndarray` of wind speeds (3-D - event, lat, lon) :param years: `numpy.ndarray` of years for which to evaluate return period values. :param float nodata: missing data value. :param int minRecords: minimum number of valid wind speed values required to fit distribution. :param int yrsPerSim: Values represent block maxima - this value indicates the time span of the block (default 1). :param int sample_size: number of records to randomly sample for calculating confidence interval of the fit. :param float prange: percentile range. :return: `numpy.ndarray` of return period wind speed values """ lower = (100 - prange) / 2. upper = 100. - lower nrecords = Vr.shape[0] nsamples = nrecords / sample_size RpUpper = nodata * np.ones( (len(years), Vr.shape[1], Vr.shape[2]), dtype='f') RpLower = nodata * np.ones( (len(years), Vr.shape[1], Vr.shape[2]), dtype='f') w = np.zeros((len(years), nsamples), dtype='f') wUpper = np.zeros((len(years)), dtype='f') wLower = np.zeros((len(years)), dtype='f') for i in xrange(Vr.shape[1]): for j in xrange(Vr.shape[2]): if Vr[:, i, j].max() > 0.0: random.shuffle(Vr[:, i, j]) for n in xrange(nsamples): nstart = n * sample_size nend = (n + 1) * sample_size - 1 vsub = Vr[nstart:nend, i, j] vsub.sort() if vsub.max() > 0.: w[:, n], loc, scale, shp = evd.estimateEVD( vsub, years, nodata, minRecords / 10, yrsPerSim) for n in range(len(years)): wUpper[n] = percentile(w[n, :], upper) wLower[n] = percentile(w[n, :], lower) RpUpper[:, i, j] = wUpper RpLower[:, i, j] = wLower return RpUpper, RpLower