コード例 #1
0
ファイル: cox18nature.py プロジェクト: lijunde/ESMValTool
def plot_cdf(cfg, psi_cube, ecs_cube, obs_cube):
    """Plot cumulative distribution function of ECS."""
    confidence_level = cfg.get('confidence_level', 0.66)
    (ecs_lin, ecs_pdf) = ec.gaussian_pdf(psi_cube.data, ecs_cube.data,
                                         np.mean(obs_cube.data),
                                         np.std(obs_cube.data))
    ecs_cdf = ec.cdf(ecs_lin, ecs_pdf)

    # Provenance
    filename = 'cdf_{}'.format(obs_cube.attributes['dataset'])
    netcdf_path = get_diagnostic_filename(filename, cfg)
    cube = iris.cube.Cube(ecs_cdf,
                          var_name='cdf',
                          long_name='Cumulative distribution function',
                          units='1')
    cube.add_aux_coord(
        iris.coords.AuxCoord(ecs_lin, **ih.convert_to_iris(ECS_ATTRS)), 0)
    io.iris_save(cube, netcdf_path)
    project = _get_project(cfg)
    provenance_record = get_provenance_record(
        "The CDF for ECS. The horizontal dot-dashed lines show the {}% "
        "confidence limits. The orange histograms show the prior "
        "distributions that arise from equal weighting of the {} models in "
        "0.5 K bins.".format(int(confidence_level * 100), project), ['mean'],
        ['other'], _get_ancestor_files(cfg, obs_cube.attributes['dataset']))

    # Plot
    if cfg['write_plots']:
        AXES.plot(ecs_lin,
                  ecs_cdf,
                  color='black',
                  linewidth=2.0,
                  label='Emergent constraint')
        AXES.hist(ecs_cube.data,
                  bins=6,
                  range=(2.0, 5.0),
                  cumulative=True,
                  density=True,
                  color='orange',
                  label='{} models'.format(project))
        AXES.axhline((1.0 - confidence_level) / 2.0,
                     color='black',
                     linestyle='dashdot')
        AXES.axhline((1.0 + confidence_level) / 2.0,
                     color='black',
                     linestyle='dashdot')

        # Plot appearance
        AXES.set_title('CDF of emergent constraint')
        AXES.set_xlabel('ECS / K')
        AXES.set_ylabel('CDF')
        legend = AXES.legend(loc='upper left')

        # Save plot
        provenance_record['plot_file'] = _save_fig(cfg, filename, legend)

    # Write provenance
    with ProvenanceLogger(cfg) as provenance_logger:
        provenance_logger.log(netcdf_path, provenance_record)
コード例 #2
0
def get_ecs_range(cfg, ecs_lin, ecs_pdf):
    """Get constrained ecs range."""
    confidence_level = cfg.get('confidence_level', 0.66)
    conf_low = (1.0 - confidence_level) / 2.0
    conf_high = (1.0 + confidence_level) / 2.0

    # Calculate CDF
    ecs_cdf = ec.cdf(ecs_lin, ecs_pdf)

    # Calculate constrained ECS range
    ecs_mean = ecs_lin[np.argmax(ecs_pdf)]
    ecs_index_range = np.where((ecs_cdf >= conf_low)
                               & (ecs_cdf <= conf_high))[0]
    ecs_range = ecs_lin[ecs_index_range]
    ecs_low = min(ecs_range)
    ecs_high = max(ecs_range)
    return (ecs_mean, ecs_low, ecs_high)
コード例 #3
0
ファイル: cox18nature.py プロジェクト: lijunde/ESMValTool
def get_ecs_range(cfg, psi_cube, ecs_cube, obs_cube):
    """Get constrained ecs range."""
    confidence_level = cfg.get('confidence_level', 0.66)
    conf_low = (1.0 - confidence_level) / 2.0
    conf_high = (1.0 + confidence_level) / 2.0

    # Calculate PDF and CDF
    (ecs_lin, ecs_pdf) = ec.gaussian_pdf(psi_cube.data, ecs_cube.data,
                                         np.mean(obs_cube.data),
                                         np.std(obs_cube.data))
    ecs_cdf = ec.cdf(ecs_lin, ecs_pdf)

    # Calculate constrained ECS range
    ecs_mean = ecs_lin[np.argmax(ecs_pdf)]
    ecs_index_range = np.where((ecs_cdf >= conf_low)
                               & (ecs_cdf <= conf_high))[0]
    ecs_range = ecs_lin[ecs_index_range]
    ecs_low = min(ecs_range)
    ecs_high = max(ecs_range)
    return (ecs_mean, ecs_low, ecs_high)