def cal_model_performance(obsl, siml):
    """Calculate model performance indexes."""
    nse = MathClass.nashcoef(obsl, siml)
    r2 = MathClass.rsquare(obsl, siml)
    rmse = MathClass.rmse(obsl, siml)
    pbias = MathClass.pbias(obsl, siml)
    rsr = MathClass.rsr(obsl, siml)
    print('NSE: %.2f, R$^2$: %.2f, PBIAS: %.2f%%, RMSE: %.2f, RSR: %.2f' %
          (nse, r2, pbias, rmse, rsr))
def cal_model_performance(obsl, siml):
    """Calculate model performance indexes."""
    nse = MathClass.nashcoef(obsl, siml)
    r2 = MathClass.rsquare(obsl, siml)
    rmse = MathClass.rmse(obsl, siml)
    pbias = MathClass.pbias(obsl, siml)
    rsr = MathClass.rsr(obsl, siml)
    print('NSE: %.2f, R-square: %.2f, PBIAS: %.2f%%, RMSE: %.2f, RSR: %.2f' %
          (nse, r2, pbias, rmse, rsr))
Example #3
0
def cal_model_performance(obsl, siml):
    nse = MathClass.nashcoef(obsl, siml)
    r2 = MathClass.rsquare(obsl, siml)
    rmse = MathClass.rmse(obsl, siml)
    pbias = MathClass.pbias(obsl, siml)
    rsr = MathClass.rsr(obsl, siml)
    plt.rcParams['xtick.direction'] = 'out'
    plt.rcParams['ytick.direction'] = 'out'
    plt.rcParams['font.family'] = 'Times New Roman'
    fig, ax = plt.subplots(figsize=(4, 4))
    plt.scatter(obsl, siml, marker='.', s=50, color='black')
    plt.xlabel('Observation', fontsize=20)
    plt.ylabel('Simulation', fontsize=20)
    plt.title('\nNSE: %.2f, R$^2$: %.2f, PBIAS: %.2f%%\nRMSE: %.2f, RSR: %.2f' %
              (nse, r2, pbias, rmse, rsr), color='red', loc='right')
    minv = math.floor(min(min(obsl), min(siml)))
    maxv = math.ceil(max(max(obsl), max(siml)))
    ax.set_xlim(left=minv, right=maxv)
    ax.set_ylim(bottom=minv, top=maxv)
    plt.tight_layout()
    plt.show()
Example #4
0
def calculate_statistics(
        sim_obs_dict,  # type: Optional[Dict[str, Dict[str, Union[List[datetime], List[float], float]]]]
        stime=None,  # type: Optional[datetime]
        etime=None  # type: Optional[datetime]
):
    # type: (...) -> Optional[List[str]]
    """Calculate NSE, R-square, RMSE, PBIAS, and RSR.
    Args:
        sim_obs_dict: {VarName: {'UTCDATETIME': [t1, t2, ..., tn],
                                 'Obs': [o1, o2, ..., on],
                                 'Sim': [s1, s2, ..., sn]
                                 },
                       ...
                       }
        stime: Start time for statistics calculation.
        etime: End time for statistics calculation.
    Returns:
        The dict with the format:
        {VarName: {'UTCDATETIME': [t1, t2, ..., tn],
                   'Obs': [o1, o2, ..., on],
                   'Sim': [s1, s2, ..., sn]},
                   'NSE': nse_value,
                   'R-square': r2_value,
                   'RMSE': rmse_value,
                   'PBIAS': pbias_value,
                   'lnNSE': lnnse_value,
                   'NSE1': nse1_value,
                   'NSE3': nse3_value
                   },
        ...
        }
        Return name list of the calculated statistics
    """
    if not sim_obs_dict:
        return None
    for param, values in sim_obs_dict.items():
        if stime is None and etime is None:
            sidx = 0
            eidx = len(values['UTCDATETIME'])
        else:
            sidx = bisect.bisect_left(values['UTCDATETIME'], stime)
            eidx = bisect.bisect_right(values['UTCDATETIME'], etime)
        obsl = values['Obs'][sidx:eidx]
        siml = values['Sim'][sidx:eidx]

        nse_value = MathClass.nashcoef(obsl, siml)
        r2_value = MathClass.rsquare(obsl, siml)
        rmse_value = MathClass.rmse(obsl, siml)
        pbias_value = MathClass.pbias(obsl, siml)
        rsr_value = MathClass.rsr(obsl, siml)
        lnnse_value = MathClass.nashcoef(obsl, siml, log=True)
        nse1_value = MathClass.nashcoef(obsl, siml, expon=1)
        nse3_value = MathClass.nashcoef(obsl, siml, expon=3)

        values['NSE'] = nse_value
        values['R-square'] = r2_value
        values['RMSE'] = rmse_value
        values['PBIAS'] = pbias_value
        values['RSR'] = rsr_value
        values['lnNSE'] = lnnse_value
        values['NSE1'] = nse1_value
        values['NSE3'] = nse3_value

        # print('Statistics for %s, NSE: %.3f, R2: %.3f, RMSE: %.3f, PBIAS: %.3f, RSR: %.3f,'
        #       ' lnNSE: %.3f, NSE1: %.3f, NSE3: %.3f' %
        #       (param, nse_value, r2_value, rmse_value, pbias_value, rsr_value,
        #        lnnse_value, nse1_value, nse3_value))
    return ['NSE', 'R-square', 'RMSE', 'PBIAS', 'RSR', 'lnNSE', 'NSE1', 'NSE3']