Exemple #1
0
def Portrait_diagram_subregion(obs_subregion_mean,
                               obs_name,
                               model_subregion_mean,
                               model_names,
                               seasonal_cycle,
                               file_name,
                               normalize=True):

    nmodel, nt, nregion = model_subregion_mean.shape

    if seasonal_cycle:
        obs_data = ma.mean(
            obs_subregion_mean.reshape([1, nt / 12, 12, nregion]), axis=1)
        model_data = ma.mean(
            model_subregion_mean.reshape([nmodel, nt / 12, 12, nregion]),
            axis=1)
        nt = 12
    else:
        obs_data = obs_subregion_mean
        model_data = model_subregion_mean

    subregion_metrics = ma.zeros([4, nregion, nmodel])

    for imodel in np.arange(nmodel):
        for iregion in np.arange(nregion):
            # First metric: bias
            subregion_metrics[0, iregion, imodel] = metrics.calc_bias(
                model_data[imodel, :, iregion],
                obs_data[0, :, iregion],
                average_over_time=True)
            # Second metric: standard deviation
            subregion_metrics[1, iregion, imodel] = metrics.calc_stddev_ratio(
                model_data[imodel, :, iregion], obs_data[0, :, iregion])
            # Third metric: RMSE
            subregion_metrics[2, iregion, imodel] = metrics.calc_rmse(
                model_data[imodel, :, iregion], obs_data[0, :, iregion])
            # Fourth metric: correlation
            subregion_metrics[3, iregion, imodel] = metrics.calc_correlation(
                model_data[imodel, :, iregion], obs_data[0, :, iregion])

    if normalize:
        for iregion in np.arange(nregion):
            subregion_metrics[0, iregion, :] = subregion_metrics[
                0, iregion, :] / ma.std(obs_data[0, :, iregion]) * 100.
            subregion_metrics[
                1, iregion, :] = subregion_metrics[1, iregion, :] * 100.
            subregion_metrics[2, iregion, :] = subregion_metrics[
                2, iregion, :] / ma.std(obs_data[0, :, iregion]) * 100.

    region_names = ['R%02d' % i for i in np.arange(nregion) + 1]

    for imetric, metric in enumerate(['bias', 'std', 'RMSE', 'corr']):
        plotter.draw_portrait_diagram(
            subregion_metrics[imetric, :, :],
            region_names,
            model_names,
            file_name + '_' + metric,
            xlabel='model',
            ylabel='region')
def Portrait_diagram_subregion(obs_subregion_mean,
                               obs_name,
                               model_subregion_mean,
                               model_names,
                               seasonal_cycle,
                               file_name,
                               normalize=True):

    nmodel, nt, nregion = model_subregion_mean.shape

    if seasonal_cycle:
        obs_data = ma.mean(obs_subregion_mean.reshape(
            [1, nt / 12, 12, nregion]),
                           axis=1)
        model_data = ma.mean(model_subregion_mean.reshape(
            [nmodel, nt / 12, 12, nregion]),
                             axis=1)
        nt = 12
    else:
        obs_data = obs_subregion_mean
        model_data = model_subregion_mean

    subregion_metrics = ma.zeros([4, nregion, nmodel])

    for imodel in np.arange(nmodel):
        for iregion in np.arange(nregion):
            # First metric: bias
            subregion_metrics[0, iregion, imodel] = metrics.calc_bias(
                model_data[imodel, :, iregion],
                obs_data[0, :, iregion],
                average_over_time=True)
            # Second metric: standard deviation
            subregion_metrics[1, iregion, imodel] = metrics.calc_stddev_ratio(
                model_data[imodel, :, iregion], obs_data[0, :, iregion])
            # Third metric: RMSE
            subregion_metrics[2, iregion, imodel] = metrics.calc_rmse(
                model_data[imodel, :, iregion], obs_data[0, :, iregion])
            # Fourth metric: correlation
            subregion_metrics[3, iregion, imodel] = metrics.calc_correlation(
                model_data[imodel, :, iregion], obs_data[0, :, iregion])

    if normalize:
        for iregion in np.arange(nregion):
            subregion_metrics[0, iregion, :] = subregion_metrics[
                0, iregion, :] / ma.std(obs_data[0, :, iregion]) * 100.
            subregion_metrics[
                1, iregion, :] = subregion_metrics[1, iregion, :] * 100.
            subregion_metrics[2, iregion, :] = subregion_metrics[
                2, iregion, :] / ma.std(obs_data[0, :, iregion]) * 100.

    region_names = ['R%02d' % i for i in np.arange(nregion) + 1]

    for imetric, metric in enumerate(['bias', 'std', 'RMSE', 'corr']):
        plotter.draw_portrait_diagram(subregion_metrics[imetric, :, :],
                                      region_names,
                                      model_names,
                                      file_name + '_' + metric,
                                      xlabel='model',
                                      ylabel='region')