shnitsel.analyze.generic¶
Attributes¶
Functions¶
|
Calculate the 2-norm of a DataArray, reducing/squeezing the dimension with name dim |
|
Subtract the mean of a DataArray along a specified dimension. |
|
Calculate all possible pairwise differences over a given dimension |
|
Function to calculate the norm of a variable across all dimensions except the ones denoted in exclude |
|
Replaces each occurence of to_replace in da with the corresponding element of value. |
|
Subtract the minimum of an xr.DataArray from all the array's elements |
|
Compute pairwise distances and standardize it by removing the mean |
Module Contents¶
- norm(da, dim='direction', keep_attrs=None)¶
Calculate the 2-norm of a DataArray, reducing/squeezing the dimension with name dim
- Parameters:
da (xarray.DataArray) – Array to calculate the norm of
dim (shnitsel.core.typedefs.DimName) – Dimension to calculate norm along (and therby reduce), by default ‘direction’
optional – Dimension to calculate norm along (and therby reduce), by default ‘direction’
keep_attrs (bool | str | None) – How to deal with attributes; passed to xr.apply_ufunc, by default None
optional – How to deal with attributes; passed to xr.apply_ufunc, by default None
- Return type:
A DataArray with dimension dim reduced
- center(da, dim='frame', keep_attrs=None)¶
Subtract the mean of a DataArray along a specified dimension.
- Parameters:
- Returns:
Centered DataArray with the same dimensions as input.
- Return type:
DataArray
- subtract_combinations(da, dim, labels=False)¶
Calculate all possible pairwise differences over a given dimension
- Parameters:
da (xarray.DataArray) – Input DataArray; must contain dimension dim
dim (shnitsel.core.typedefs.DimName) – Dimension (of size $n$) to take pairwise differences over
labels (bool) – If True, label the pairwise differences based on the index of dim, by default False
optional – If True, label the pairwise differences based on the index of dim, by default False
- Return type:
A DataArray with the dimension dim replaced by a dimension ‘`dim`comb’ of size $n(n-1)/2$
- keep_norming(da, exclude=None)¶
Function to calculate the norm of a variable across all dimensions except the ones denoted in exclude
- Parameters:
da (xr.DataArray) – The data array to norm across all non-excluded dimensions
exclude (Collection[DimName] | None, optional) – The dimensions to exclude/retain. Defaults to [‘state’, ‘statecomb’, ‘frame’].
- Returns:
The resulting, normed array
- Return type:
xr.DataArray
- replace_total(da, to_replace, value)¶
Replaces each occurence of to_replace in da with the corresponding element of value. Replacement must be total, i.e. every element of da must be in to_replace. This permits a change of dtype between to_replace and value. This function is based on the snippets at https://github.com/pydata/xarray/issues/6377
- Parameters:
da (xarray.DataArray) – An xr.DataArray
to_replace (numpy.ndarray | list) – Values to replace
value (numpy.ndarray | list) – Values with which to replace them
- Return type:
An xr.DataArray with dtype matching value.
- relativize(da, **sel)¶
Subtract the minimum of an xr.DataArray from all the array’s elements
- Parameters:
da (xarray.DataArray) – The xr.DataArray from which to subtract the minimum
**sel – If keyword parameters are present, the reference minimum is picked
- Return type:
:param from those elements that remain after running
xarray.DataArray.sel(): :param using the keyword parameters as arguments.:- Return type:
The result of subtraction, with
attrsintact.- Parameters:
da (xarray.DataArray)
- pwdists(atXYZ, mean=False)¶
Compute pairwise distances and standardize it by removing the mean and L2-normalization (if your features are vectors and you want magnitudes only, to lose directional info)
- Parameters:
atXYZ (shnitsel.core.typedefs.AtXYZ) – A DataArray containing the atomic positions; must have a dimension called ‘atom’
mean (bool) – subtract mean if true to center data
- Return type:
A DataArray with the same dimensions as atXYZ but transposed
- get_standardized_pairwise_dists¶