Coordinates#
- class zfit.dimension.Coordinates(obs=None, axes=None)[source]#
Bases:
ZfitOrderableDimensional
- property obs: Optional[Tuple[str, ...]]#
Return the observables, string identifier for the coordinate system.
- Return type
Optional
[Tuple
[str
,...
]]
- property axes: Optional[Tuple[int]]#
Return the axes, integer based identifier(indices) for the coordinate system.
- Return type
Optional
[Tuple
[int
]]
- property n_obs: int#
Return the number of observables, the dimensionality.
Corresponds to the last dimension.
- Return type
int
- with_obs(obs, allow_superset=True, allow_subset=True)[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 (ztyping.ObsTypeInput | None) – Observables to sort/associate this instance with
allow_superset (bool) – if False and a strict superset of the own observables is given, an error
raised. (is) –
allow_subset (bool) – if False and a strict subset of the own observables is given, an error
raised. –
- Return type
- Returns
A copy of the object with the new ordering/observables
- 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
- with_axes(axes, allow_superset=True, allow_subset=True)[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.
- Parameters
axes (ztyping.AxesTypeInput | None) – Axes to sort/associate this instance with
allow_superset (bool) – if False and a strict superset of the own axeservables is given, an error
raised. (is) –
allow_subset (bool) – if False and a strict subset of the own axeservables is given, an error
raised. –
- Return type
- Returns
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_autofill_axes(overwrite=False)[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.object.obs -> ('x', 'z', 'y') object.axes -> None object.with_autofill_axes() object.obs -> ('x', 'z', 'y') object.axes -> (0, 1, 2)
- Parameters
overwrite (
bool
) – If axes are already set, replace the axes with the autofilled ones. If axes is already set andoverwrite
is False, raise an error.- Return type
ZfitOrderableDimensional
- Returns
The object with the new axes
- Raises
AxesIncompatibleError – if the axes are already set and
overwrite
is False.
- get_reorder_indices(obs=None, axes=None)[source]#
Indices that would order the instances obs as
obs
respectively the instances axes asaxes
.- 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.
- Raises
CoordinatesUnderdefinedError – If neither
obs
noraxes
is given
- reorder_x(x, *, x_obs=None, x_axes=None, func_obs=None, func_axes=None)[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 withfunc_obs
resp.func_axes
.Switching
func_obs
forx_obs
resp.func_axes
forx_axes
inverts the reordering of x.- Parameters
x (tf.Tensor | np.ndarray) – Tensor to be reordered, last dimension should be n_obs resp. n_axes
x_obs (ztyping.ObsTypeInput) – Observables associated with x. If both, x_obs and x_axes are given, this has precedency over the latter.
x_axes (ztyping.AxesTypeInput) – Axes associated with x.
func_obs (ztyping.ObsTypeInput) – 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
andfunc_axes
are given, this has precedency over the latter.func_axes (ztyping.AxesTypeInput) – Axe associated with a function that x will be given to. Reorders x accordingly and assumes self.axes to be the axes of x.
- Return type
ztyping.XTypeReturnNoData
- Returns
The reordered array-like object