scipp.transform_coords

scipp.transform_coords(x, targets, graph, *, rename_dims=True, keep_aliases=True, keep_intermediate=True, keep_inputs=True)

Compute new coords based on transformations of input coords.

Parameters
  • x (Union[scipp._scipp.core.DataArray, scipp._scipp.core.Dataset]) – Input object with coords.

  • targets (Union[str, Iterable[str]]) – Name or list of names of desired output coords.

  • graph (Dict[Union[str, Tuple[str, ...]], Union[str, Callable]]) –

    A graph defining how new coords can be computed from existing coords. This may be done in multiple steps. The graph is given by a dict where:

    • Dict keys are str or tuple of str, defining the names of outputs generated by a dict value.

    • Dict values are str or a callable (function). If str, this is a synonym for renaming a coord. If a callable, it must either return a single variable or a dict of variables. The argument names of callables must be coords in x or be computable by other nodes in graph.

  • rename_dims (bool) –

    Rename dimensions if the corresponding dimension coords are used as inputs. Dimension a is renamed to b if and only if

    • coord a is used as input in exactly 1 node

    • coord a is the only dimension coord in that node’s inputs

    • coord b is the only output of that node.

    Default is True.

  • keep_aliases (bool) – If True, aliases for coords defined in graph are included in the output. Default is True.

  • keep_intermediate (bool) – Keep attributes created as intermediate results. Default is True.

  • keep_inputs (bool) – Keep consumed input coordinates or attributes. Default is True.

Returns

New object with desired coords. Existing data and meta-data is shallow-copied.

Seealso

The section in the user guide on Coordinate transformations

Return type

Union[scipp._scipp.core.DataArray, scipp._scipp.core.Dataset]