How to use the climpred.utils.assign_attrs 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 / reference.py View on Github external
for i in hind['lead'].values:
        # Ensure that the uninitialized reference has all of the
        # dates for alignment.
        dates = list(set(forecast['time'].values) & set(verif_dates[i]))
        a = forecast.sel(time=dates)
        b = verif.sel(time=dates)
        a['time'] = b['time']
        plag.append(
            metric.function(a, b, dim='time', comparison=comparison, **metric_kwargs)
        )
    uninit_skill = xr.concat(plag, 'lead')
    uninit_skill['lead'] = hind.lead.values

    # Attach climpred compute information to skill
    if add_attrs:
        uninit_skill = assign_attrs(
            uninit_skill,
            uninit,
            function_name=inspect.stack()[0][3],
            metric=metric,
            comparison=comparison,
            metadata_dict=metric_kwargs,
        )
    return uninit_skill
github bradyrx / climpred / climpred / prediction.py View on Github external
)
        for lead in forecast['lead'].data
    ]
    result = xr.concat(metric_over_leads, dim='lead', **CONCAT_KWARGS)
    result['lead'] = forecast['lead']
    # rename back to 'init'
    if 'time' in result.dims:  # If dim is 'member'
        result = result.rename({'time': 'init'})
    # These computations sometimes drop coordinates along the way. This appends them
    # back onto the results of the metric.
    drop_dims = [d for d in hind.coords if d in CLIMPRED_DIMS]
    result = copy_coords_from_to(hind.drop_vars(drop_dims), result)

    # Attach climpred compute information to result
    if add_attrs:
        result = assign_attrs(
            result,
            hind,
            function_name=inspect.stack()[0][3],
            alignment=alignment,
            metric=metric,
            comparison=comparison,
            dim=dim,
            metadata_dict=metric_kwargs,
        )
    return result
github bradyrx / climpred / climpred / reference.py View on Github external
for i in hind.lead.values:
        a = verif.sel(time=inits[i])
        b = verif.sel(time=verif_dates[i])
        a['time'] = b['time']
        plag.append(
            metric.function(a, b, dim='time', comparison=__e2c, **metric_kwargs)
        )
    pers = xr.concat(plag, 'lead')
    pers['lead'] = hind.lead.values
    # keep coords from hind
    drop_dims = [d for d in hind.coords if d in CLIMPRED_DIMS]
    if 'iteration' in hind.dims:
        drop_dims += ['iteration']
    pers = copy_coords_from_to(hind.drop_vars(drop_dims), pers)
    if add_attrs:
        pers = assign_attrs(
            pers,
            hind,
            function_name=inspect.stack()[0][3],
            alignment=alignment,
            metric=metric,
            metadata_dict=metric_kwargs,
        )
    return pers
github bradyrx / climpred / climpred / prediction.py View on Github external
)

    forecast, verif = comparison.function(init_pm, metric=metric)

    # in case you want to compute deterministic skill over member dim
    if (forecast.dims != verif.dims) and not metric.probabilistic:
        forecast, verif = xr.broadcast(forecast, verif)

    skill = metric.function(
        forecast, verif, dim=dim, comparison=comparison, **metric_kwargs
    )
    if comparison.name == 'm2m':
        skill = skill.mean(M2M_MEMBER_DIM)
    # Attach climpred compute information to skill
    if add_attrs:
        skill = assign_attrs(
            skill,
            init_pm,
            function_name=inspect.stack()[0][3],
            metric=metric,
            comparison=comparison,
            dim=dim,
            metadata_dict=metric_kwargs,
        )
    return skill