def slope_fdc(da: DataArray, lower_quantile: float = 0.33, upper_quantile: float = 0.66) -> float: # sort discharge by descending order fdc = da.sortby(da, ascending=False) # get idx of lower and upper quantile idx_lower = np.round(lower_quantile * len(fdc)).astype(int) idx_upper = np.round(upper_quantile * len(fdc)).astype(int) value = (np.log(fdc[idx_lower].values + 1e-8)) - np.log(fdc[idx_upper].values + 1e-8) / (upper_quantile - lower_quantile) return value
def slope_fdc(da: DataArray, lower_quantile: float = 0.33, upper_quantile: float = 0.66) -> float: """Calculates flow duration curve slope. Slope of the flow duration curve (between the log-transformed `lower_quantile` and `upper_quantile`) [#]_ (Eq. 3). Parameters ---------- da : DataArray Array of flow values. lower_quantile : float, optional Lower quantile to use in slope calculation. upper_quantile : float, optional Upper quantile to use in slope calculation. Returns ------- float Slope of the flow duration curve. References ---------- .. [#] Sawicz, K., Wagener, T., Sivapalan, M., Troch, P. A., and Carrillo, G.: Catchment classification: empirical analysis of hydrologic similarity based on catchment function in the eastern USA. Hydrology and Earth System Sciences, 2011, 15, 2895--2911, doi:10.5194/hess-15-2895-2011 """ # sort discharge by descending order fdc = da.sortby(da, ascending=False) # get idx of lower and upper quantile idx_lower = np.round(lower_quantile * len(fdc)).astype(int) idx_upper = np.round(upper_quantile * len(fdc)).astype(int) value = (np.log(fdc[idx_lower].values + 1e-8)) - np.log(fdc[idx_upper].values + 1e-8) / (upper_quantile - lower_quantile) return value
def _get_fdc(da: DataArray) -> np.ndarray: return da.sortby(da, ascending=False).values