Beispiel #1
0
            # Now calibrate the forecast ensemble using the calibrate() method:

            X_t_cal_params, X_t_cal = taqminst.calibrate(
                X_ta_params, Y_ta_params, X_t_params, X_ta, Y_ta, X_t,
                trust_sharp_fcst)

            # Next, we’re going to compute the SIP quantity for the raw and calibrated forecast, plot all cumulative distributions, and calculate the continuous rank probability score (CRPS) for the raw and calibrated forecast.

            # First, evaluate the cdf for each of these using the cdf_eval() method in the beinf class. This method handles instances when a and b aren’t known (and given the value np.inf), in which case the cdf over (0,1) is computed using the ecdf() method. When a and b are known (as is the case in this example), cdf_eval() evaluates the cdf using the cdf() method. We can also use the cdf_eval() method to compute SIP.

            x = np.linspace(0, 1, 1000)
            x_c = 0.15

            # Evaluate cdf for the TAMH distribution at x
            cdf_x_ta = beinf.cdf_eval(x, X_ta_params, X_ta)

            # Evaluate cdf for the TAOH distribution at x
            cdf_y_ta = beinf.cdf_eval(x, Y_ta_params, Y_ta)

            # Evaluate cdf for the forecast distribution at x and calculate SIP
            cdf_x_t = beinf.cdf_eval(x, X_t_params, X_t)
            sip_x_t = 1.0 - beinf.cdf_eval(x_c, X_t_params, X_t)

            p_x_t = X_t_params[2]  # raw forecast
            p_x_ta = X_ta_params[2]  # TAMH climatology
            p_y_ta = Y_ta_params[2]  # TAOH climatology

            # Evaluate cdf for the calibrated forecast distribution at x and calculate SIP
            if trust_sharp_fcst == True and p_x_t == 1.0:
                # go with the original forecast data/distribution when any of the p parameters are one
a_x_t, b_x_t, p_x_t, q_x_t = X_t_params[0], X_t_params[1], X_t_params[
    2], X_t_params[3]
a_x_t_cal, b_x_t_cal, p_x_t_cal, q_x_t_cal = X_t_cal_params[0], X_t_cal_params[
    1], X_t_cal_params[2], X_t_cal_params[3]

# freeze distribution objects
rv_x_ta = beinf(a_x_ta, b_x_ta, p_x_ta, q_x_ta)  #TAMH
rv_y_ta = beinf(a_y_ta, b_y_ta, p_y_ta, q_y_ta)  #TAOH
rv_x_t = beinf(a_x_t, b_x_t, p_x_t, q_x_t)  #Raw forecast ensemble
rv_x_t_cal = beinf(a_x_t_cal, b_x_t_cal, p_x_t_cal,
                   q_x_t_cal)  #Calibrated forecast ensemble

x = np.linspace(0, 1, 1000)

# Evaluate cdf for the TAMH distribution at x
cdf_x_ta = beinf.cdf_eval(x, X_ta_params, X_ta)

# Evaluate cdf for the TAOH distribution at x
cdf_y_ta = beinf.cdf_eval(x, Y_ta_params, Y_ta)

# Evaluate cdf for the forecast distribution at x
cdf_x_t = beinf.cdf_eval(x, X_t_params, X_t)

# Evaluate cdf for the calibrated forecast distribution at x
if trust_sharp_fcst == True and p_x_t == 1:
    cdf_x_t_cal = beinf.cdf_eval(x, X_t_params, X_t)
else:
    if p_x_t == 1.0:
        cdf_x_t_cal = beinf.cdf_eval(x, Y_ta_params, Y_ta)
    else:
        cdf_x_t_cal = beinf.cdf_eval(x, X_t_cal_params, X_t_cal)