tools#
Various tools.
Functions
|
Shift to center avalanche. Example usage. |
Shift to center avalanche, per row. Example usage::. |
|
|
Make sure that all variables in a dictionary are documented in a docstring. The function assumes a docstring as follows::. |
|
Fill avalanche such that the largest spatial extension can be selected. |
|
Return original array. |
|
Save a list of strings (or other data, but mostly relevant for strings) with many duplicates as two datasets: |
|
Check if a dictionary/list |
|
Apply an independent roll for each dimensions of a single axis. |
Details
- depinning_inertia_2024.tools.center_avalanche(arr)#
- Shift to center avalanche. Example usage::
R = center_avalanche(S) C = np.roll(S, R)
- Parameters
arr – If the block yielded (or the number of times it yielded).
- Returns
Shift.
- depinning_inertia_2024.tools.center_avalanche_per_row(arr)#
Shift to center avalanche, per row. Example usage:
R = center_avalanche_per_row(S) C = indep_roll(S, R, axis=1)
Note that the input array is interpreted as follows: - any positive value == 1 - any zero or negative value == 0
- Parameters
arr – Per row: if the block yielded.
- Returns
Shift per row.
- depinning_inertia_2024.tools.check_docstring(string: str, variable: dict, key: str = ':return:')#
Make sure that all variables in a dictionary are documented in a docstring. The function assumes a docstring as follows:
:param a: ... :param b: ... :return: ...:: name: description
Thereby the docstring is split: 1. At a parameter (e.g. “:return:”) 2. At .. code-block:: or ::
The indented code after is assumed to be formatted as YAML and is the code we search.
- depinning_inertia_2024.tools.fill_avalanche(broken)#
Fill avalanche such that the largest spatial extension can be selected.
- Parameters
broken – Per block if it is broken.
- Returns
broken
for filled avalanche.
- depinning_inertia_2024.tools.h5py_read_unique(file: File, path: str, asstr: bool = False) ndarray #
Return original array. The array is stored by
depinning_inertia_2024.tools.h5py_save_unique()
.- Parameters
file – HDF5 archive.
path – Group containing
index
andvalue
.asstr – Return as list of strings.
- Returns
Data.
- depinning_inertia_2024.tools.h5py_save_unique(data: ArrayLike, file: File, path: str, asstr: bool = False, split: str = None)#
Save a list of strings (or other data, but mostly relevant for strings) with many duplicates as two datasets:
path/value
: list of unique strings.path/index
: per item which index frompath/value
to take.
Use
depinning_inertia_2024.tools.h5py_read_unique()
to read data.- Parameters
data – Data to store.
file – HDF5 archive.
path – Group containing
index
andvalue
.asstr – Convert to list of strings before storing.
split – Split every item for a list of strings before storing.
- depinning_inertia_2024.tools.inboth(a: dict | list, b: dict | list, name_a: str = 'a', name_b: str = 'b')#
Check if a dictionary/list
a
has all fields asb
and vice-versa.- Parameters
a – List or dictionary.
b – List or dictionary.
- depinning_inertia_2024.tools.indep_roll(arr, shifts, axis=1)#
Apply an independent roll for each dimensions of a single axis. See: https://stackoverflow.com/a/56175538/2646505
- Parameters
arr – Array of any shape.
shifts – Shifting to use for each dimension. Shape: (arr.shape[axis],).
axis – Axis along which elements are shifted.
- Returns
Rolled array.