helper module

Define misc helper functions.

Todo

Clean this, check what is still used.

recursive_items(dictionary)[source]

Recursively list all keys of a possibly nested dictionary.

Parameters:

dictionary (dict[Any, Any])

Return type:

Iterator[str]

recursive_getter(wanted_key, dictionary, **kwargs)[source]

Get first key in a possibly nested dictionary.

Parameters:
Return type:

Any

flatten(nest)[source]

Flatten nested list of lists of…

Parameters:

nest (Iterable[TypeVar(T)])

Return type:

Iterator[TypeVar(T)]

chunks(lst, n_size)[source]

Yield successive n_size-ed chunks from lst.

https://stackoverflow.com/questions/312443/how-do-i-split-a-list-into-equal ly-sized-chunks

Parameters:
Return type:

Generator[list[TypeVar(T)], int, None]

remove_duplicates(iterable)[source]

Create an iterator without duplicates.

Taken from: https://stackoverflow.com/questions/32012878/iterator-object-for-removing-duplicates-in-python

Parameters:

iterable (Iterable[TypeVar(T)])

Return type:

Iterator[TypeVar(T)]

pd_output(df, header='')[source]

Return a formatted string representation of a pandas DataFrame.

Parameters:
Return type:

str

pascal_case(message)[source]

Convert a string to Pascal case (as class names).

Examples

>>> pascal_case("bonjoure sa_vA")
"BonjoureSaVa"
>>> pascal_case("BonjoureSaVa")
"BonjoureSaVa"
Parameters:

message (str)

Return type:

str

get_constructor(name, constructors)[source]

Get the proper class from a string and dict of classes.

Parameters:
Return type:

type

get_constructors(names, constructors)[source]

Get several class constructors from their names.

Parameters:
Return type:

Generator[type, None, None]

resample(x_1, y_1, x_2, y_2)[source]

Downsample y_highres(olution) to x_1 or x_2 (the one with low res).

Parameters:
Return type:

tuple[ndarray, ndarray, ndarray, ndarray]

range_vals(name, data)[source]

Return formatted first and last value of the data array.

Parameters:
Return type:

str

range_vals_object(obj, name)[source]

Return first and last value of the name attr from obj.

Parameters:
Return type:

str

save_energy_phase_tm(lin)[source]

Save energy, phase, transfer matrix as a function of s.

s [m] E[MeV] phi[rad] M_11 M_12 M_21 M_22

Parameters:

lin (object) – Object of corresponding to desired output.

Return type:

None