coordinates

class zfit.core.coordinates.Coordinates(obs=None, axes=None)[source]

Bases: zfit.core.interfaces.ZfitOrderableDimensional

axes

Return the axes, integer based identifier(indices) for the coordinate system.

get_reorder_indices(obs: Union[str, Iterable[str], zfit.Space] = None, axes: Union[int, Iterable[int]] = None) → Tuple[int][source]

Indices that would order the instances obs as obs respectively the instances axes as axes.

Parameters:
  • obs – Observables that the instances obs should be ordered to. Does not reorder, but just return the indices that could be used to reorder.
  • axes – Axes that the instances obs should be ordered to. Does not reorder, but just return the indices that could be used to reorder.
Returns:

New indices that would reorder the instances obs to be obs respectively axes.

Return type:

tuple(int)

Raises:

CoordinatesUnderdefinedError – If neither obs nor axes is given

n_obs

Return the number of observables, the dimensionality. Corresponds to the last dimension.

obs

Return the observables, string identifier for the coordinate system.

reorder_x(x: Union[tensorflow.python.framework.ops.Tensor, numpy.ndarray], *, x_obs: Union[str, Iterable[str], zfit.Space] = None, x_axes: Union[int, Iterable[int]] = None, func_obs: Union[str, Iterable[str], zfit.Space] = None, func_axes: Union[int, Iterable[int]] = None) → Union[numpy.ndarray, tensorflow.python.framework.ops.Tensor][source]

Reorder x in the last dimension either according to its own obs or assuming a function ordered with func_obs.

There are two obs or axes around: the one associated with this Coordinate object and the one associated with x. If x_obs or x_axes is given, then this is assumed to be the obs resp. the axes of x and x will be reordered according to self.obs resp. self.axes.

If func_obs resp. func_axes is given, then x is assumed to have self.obs resp. self.axes and will be reordered to align with a function ordered with func_obs resp. func_axes.

Switching func_obs for x_obs resp. func_axes for x_axes inverts the reordering of x.

Parameters:
  • x (tensor-like) – Tensor to be reordered, last dimension should be n_obs resp. n_axes
  • x_obs – Observables associated with x. If both, x_obs and x_axes are given, this has precedency over the latter.
  • x_axes – Axes associated with x.
  • func_obs – Observables associated with a function that x will be given to. Reorders x accordingly and assumes self.obs to be the obs of x. If both, func_obs and func_axes are given, this has precedency over the latter.
  • func_axes – Axe associated with a function that x will be given to. Reorders x accordingly and assumes self.axes to be the axes of x.
Returns:

the reordered array-like object

Return type:

tensor-like

with_autofill_axes(overwrite: bool = False) → zfit.core.interfaces.ZfitOrderableDimensional[source]

Overwrite the axes of the current object with axes corresponding to range(len(n_obs)).

This effectively fills with (0, 1, 2,…) and can be used mostly when an object enters a PDF or similar. overwrite allows to remove the axis first in case there are already some set.

Parameters:overwrite (bool) – If axes are already set, replace the axes with the autofilled ones. If axes is already set and overwrite is False, raise an error.
Returns:the object with the new axes
Return type:object
Raises:AxesIncompatibleError – if the axes are already set and overwrite is False.
with_axes(axes: Union[int, Iterable[int], None], allow_superset: bool = True, allow_subset: bool = True) → zfit.core.coordinates.Coordinates[source]

Create a new instance that has axes; sorted by or set or dropped.

The behavior is as follows:

  • axes are already set: * input axes are None: the axes will be dropped. If no observables are set, an error

    will be raised, as no coordinates will be assigned to this instance anymore.

    • input axes are not None: the instance will be sorted by the incoming axes. If obs or other objects have an associated order (e.g. data, limits,…), they will be reordered as well. If a strict subset is given (and allow_subset is True), only a subset will be returned. This can be used to retrieve a subspace of limits, data etc. If a strict superset is given (and allow_superset is True), the axes will be sorted accordingly as if the axes not contained in the instances axes were not present in the input axes.
  • axes are not set: * if the input axes are None, the same object is returned. * if the input axes are not None, they will be set as-is and now correspond to the already

    existing obs in the object.

Args:
axes: Axes to sort/associate this instance with allow_superset: if False and a strict superset of the own axeservables is given, an error is raised. allow_subset:if False and a strict subset of the own axeservables is given, an error is raised.
Returns:
object: a copy of the object with the new ordering/axes
Raises:
  • CoordinatesUnderdefinedError – if obs is None and the instance does not have axes
  • AxesIncompatibleError – if axes is a superset and allow_superset is False or a subset and allow_allow_subset is False
with_obs(obs: Union[str, Iterable[str], zfit.Space, None], allow_superset: bool = True, allow_subset: bool = True) → zfit.core.coordinates.Coordinates[source]

Create a new instance that has obs; sorted by or set or dropped.

The behavior is as follows:

  • obs are already set: * input obs are None: the observables will be dropped. If no axes are set, an error

    will be raised, as no coordinates will be assigned to this instance anymore.

    • input obs are not None: the instance will be sorted by the incoming obs. If axes or other objects have an associated order (e.g. data, limits,…), they will be reordered as well. If a strict subset is given (and allow_subset is True), only a subset will be returned. This can be used to take a subspace of limits, data etc. If a strict superset is given (and allow_superset is True), the obs will be sorted accordingly as if the obs not contained in the instances obs were not in the input obs.
  • obs are not set: * if the input obs are None, the same object is returned. * if the input obs are not None, they will be set as-is and now correspond to the already

    existing axes in the object.

Parameters:
  • obs – Observables to sort/associate this instance with
  • allow_superset – if False and a strict superset of the own observables is given, an error
  • raised. (is) –
  • allow_subset – if False and a strict subset of the own observables is given, an error
  • raised.
Returns:

a copy of the object with the new ordering/observables

Return type:

object

Raises:
  • CoordinatesUnderdefinedError – if obs is None and the instance does not have axes
  • ObsIncompatibleError – if obs is a superset and allow_superset is False or a subset and allow_allow_subset is False
zfit.core.coordinates.convert_to_axes(axes, container=<class 'tuple'>)[source]

Convert obs to the list of obs, also if it is a ZfitSpace. Return None if axes is None.

Raises
TypeError: if the axes are not int
zfit.core.coordinates.convert_to_obs_str(obs, container=<class 'tuple'>)[source]

Convert obs to the list of obs, also if it is a ZfitSpace. Return None if obs is None.

Raises:TypeError – if the observable is not a string