How to use the xgcm.grid.Axis function in xgcm

To help you get started, we’ve selected a few xgcm 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 xgcm / xgcm / xgcm / autogenerate.py View on Github external
# are a) one dimensional (dimensions) or 2) multidimensional. These are
    # separated by the keyword attrs_from_scratch.
    # These two cases are treated differently because for each dataset we need
    # to recreate all a) cases before we can proceed to 2), hence this is
    # really the 'raw' data processing step. If we have working one dimensional
    # coordinates (e.g. after we looped over the axes_dims_dict, we can use the
    # regular xgcm.Axis to interpolate multidimensional coordinates.
    # This assures that any changes to the Axis.interp method can directly
    # propagate to this module.

    if attrs_from_scratch:
        # Input coordinate has to be declared as center,
        # or xgcm.Axis throws error. Will be rewrapped below.
        ds[name] = _fill_attrs(ds[name], "center", axis)

        ax = Axis(ds, axis, periodic=periodic)
        args = ds[name], raw_interp_function, relative_pos_to
        ds.coords[new_name] = ax._neighbor_binary_func_raw(*args, **kwargs)

        # Place the correct attributes
        ds[name] = _fill_attrs(ds[name], pos_from, axis)
        ds[new_name] = _fill_attrs(ds[new_name], pos_to, axis)
    else:
        kwargs.pop("position_check", None)
        ax = Axis(ds, axis, periodic=periodic)
        args = ds[name], pos_to
        ds.coords[new_name] = ax.interp(*args, **kwargs)
    return ds
github xgcm / xgcm / xgcm / autogenerate.py View on Github external
if attrs_from_scratch:
        # Input coordinate has to be declared as center,
        # or xgcm.Axis throws error. Will be rewrapped below.
        ds[name] = _fill_attrs(ds[name], "center", axis)

        ax = Axis(ds, axis, periodic=periodic)
        args = ds[name], raw_interp_function, relative_pos_to
        ds.coords[new_name] = ax._neighbor_binary_func_raw(*args, **kwargs)

        # Place the correct attributes
        ds[name] = _fill_attrs(ds[name], pos_from, axis)
        ds[new_name] = _fill_attrs(ds[new_name], pos_to, axis)
    else:
        kwargs.pop("position_check", None)
        ax = Axis(ds, axis, periodic=periodic)
        args = ds[name], pos_to
        ds.coords[new_name] = ax.interp(*args, **kwargs)
    return ds
github xgcm / xgcm / xgcm / grid.py View on Github external
all_axes = coords.keys()
        else:
            all_axes = comodo.get_all_axes(ds)
            coords = {}

        self.axes = OrderedDict()
        for axis_name in all_axes:
            try:
                is_periodic = axis_name in periodic
            except TypeError:
                is_periodic = periodic
            if axis_name in default_shifts:
                axis_default_shifts = default_shifts[axis_name]
            else:
                axis_default_shifts = {}
            self.axes[axis_name] = Axis(
                ds,
                axis_name,
                is_periodic,
                default_shifts=axis_default_shifts,
                coords=coords.get(axis_name),
            )

        if face_connections is not None:
            self._assign_face_connections(face_connections)

        if metrics is not None:
            self._assign_metrics(metrics)