How to use the climpred.prediction.compute_perfect_model function in climpred

To help you get started, we’ve selected a few climpred examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bradyrx / climpred / climpred / test_prediction.py View on Github external
def test_compute_perfect_model_ds_not_nan(PM_ds_ds, PM_ds_control, metric, comparison):
    actual = compute_perfect_model(
        PM_ds_ds, PM_ds_control, metric=metric, comparison=comparison).isnull().any()
    assert actual == False
github bradyrx / climpred / climpred / test_prediction.py View on Github external
def test_compute_perfect_model_da_not_nan(PM_da_ds, PM_da_control, metric, comparison):
    actual = compute_perfect_model(
        PM_da_ds, PM_da_control, metric=metric, comparison=comparison).isnull().any()
    assert actual == False
github bradyrx / climpred / asv_bench / benchmarks / benchmarks_perfect_model.py View on Github external
def time_compute_perfect_model(self, metric, comparison):
        """Take time for `compute_perfect_model`."""
        dim = 'member' if metric in PROBABILISTIC_METRICS else None
        ensure_loaded(
            compute_perfect_model(
                self.ds, self.control, metric=metric, comparison=comparison, dim=dim
            )
github bradyrx / climpred / climpred / toy.py View on Github external
pers_sig=None,
):
    """bootstrap_compute for large ensembles."""
    if dim is None:
        dim = ['init', 'member']
    return bootstrap_compute(
        ds,
        control,
        hist=None,
        metric=metric,
        comparison=comparison,
        dim=dim,
        sig=sig,
        bootstrap=bootstrap,
        pers_sig=pers_sig,
        compute=compute_perfect_model,
        resample_uninit=uninit_ensemble_ori,
    )
github bradyrx / climpred / climpred / toy.py View on Github external
def run_skill_for_ensemble(
    lead=lead,
    nmember=5,
    ninit=5,
    signal_P=signal_P,
    signal_amplitude=signal_amplitude,
    noise_amplitude=noise_amplitude,
    ramp=ramp,
    bootstrap=10,
    plot=True,
    ax=None,
    label=None,
    color='k',
    compute=compute_perfect_model,
    **metric_kwargs,
):
    """Short summary.

    Args:
        lead (xr.DataArray): lead times to create synthetic data for.
        ninit (type): number of initialzations. Defaults to 3.
        nmember (type): number of members. Defaults to 3.
        noise_amplitude (type): amplitude of the gaussian noise.
        ramp (np.array): Ramping up function.
        signal_amplitude (float): amplitude of the signal.
        signal_P (float): period of the signal.
        bootstrap (int): bootstrap iterations to calc synthetic skill. Defaults to 10.
        plot (bool): plot as boxplot. Defaults to True.
        ax (plt.axes): using existing ax. Defaults to None.
        label (str): label in legend. Defaults to None.
github bradyrx / climpred / asv_bench / benchmarks / benchmarks_perfect_model.py View on Github external
def peakmem_compute_perfect_model(self, metric, comparison):
        """Take memory peak for `compute_perfect_model`."""
        dim = 'member' if metric in PROBABILISTIC_METRICS else None
        ensure_loaded(
            compute_perfect_model(
                self.ds, self.control, metric=metric, comparison=comparison, dim=dim
            )
github bradyrx / climpred / climpred / toy.py View on Github external
Returns:
        whisker_line: to use in legend, if plot.
        xr.DataArray: skill, else.

    """
    s = []
    # for i in tqdm(range(bootstrap),desc='bootstrap'):
    for i in range(bootstrap):
        ds = create_initialized(
            nmember=nmember,
            ninit=ninit,
            signal_P=signal_P,
            signal_amplitude=signal_amplitude,
            noise_amplitude=noise_amplitude,
        )
        s.append(compute_perfect_model(ds, ds, **metric_kwargs))
    s = xr.concat(s, 'bootstrap')
    s['lead'] = lead.values
    if plot:
        if ax is None:
            _, ax = plt.subplots()
        ss = s.to_dataframe('skill').unstack()['skill']
        bp = ss.plot.box(
            ax=ax,
            color=color,
            return_type='dict',
            label=label,
            flierprops={'markeredgecolor': color},
        )
        metric = metric_kwargs['metric'] if 'metric' in metric_kwargs else ''
        ax.set_title(f'metric: {metric}, nmember: {nmember} ninit:{ninit}')
        return bp['whiskers'][0]