Utility functions (pesfit.utils)
¶
-
pesfit.utils.
argpick
(cliargs, argkey, defaults)¶ Command-line input argument picker.
Parameters
- cliargs: dict
Command-line inputs
- argkey: str
Argument key.
- defaults: any
Default value for the argument if no input is found.
-
pesfit.utils.
df_collect
(params, extra_params=None, currdf=None)¶ Collect parameters from fitting outcome.
Parameters
- params: instance of
lmfit.parameter.Parameters
. Collection of fitting parameters.
- extra_params: dict | None
Extra parameters supplied as a dictionary
- currdf: instance of
pandas.DataFrame
| None An existing dataframe to append new data to.
Return
- df: instance of
pandas.DataFrame
Fitting parameters reformatted as a dataframe (keeps only names and values).
- params: instance of
-
pesfit.utils.
dict_depth
(dic, level=0)¶ Check the depth of a dictionary.
Parameters
- dic: dict
Instance of dictionary object or its subclass.
- level: int | 0
Starting level of the depth counting.
-
pesfit.utils.
dictmerge
(D, others)¶ Merge a dictionary with other dictionaries
Parameters
- D: dict
Main dictionary.
- others: list/tuple/dict
Other dictionary or composite dictionarized elements.
Return
- D: dict
Merged dictionary.
-
pesfit.utils.
grid_indices
(x, y, dtyp='float', ordering='rc', flatten=True)¶ Construct grid indices.
Parameters
- x, y: 1D array, 1D array
Single-axis x and y coordinates.
- dtyp: str | ‘float’
Data type of the generated grid indices.
- ordering: str | ‘rc’
Ordering of the indices (‘rc’ for row-column ordering, ‘xy’ for x-y ordering).
- flatten: bool | True
Option to flatten the grid indices.
-
pesfit.utils.
grid_resample
(data, coords_axes, coords_new=None, grid_scale=None, zoom_scale=None, interpolator=<class 'scipy.interpolate.interpolate.RegularGridInterpolator'>, ret='scaled', **kwds)¶ Resample data to new resolution.
Parameters
- data: numpy.ndarray
Data for resampling.
- coord_axes: list/tuple
Current coordinates matching the dimensions of the input data
- coords_new: list/tuple | None
New coordinates to resample the data with.
- grid_scale: list/tuple | None
Scaling factors along every axis.
- zoom_scale: numeric | None
Zooming-in factor.
- interpolator: func |
scipy.interpolate.RegularGridInterpolator
Interpolation function.
- **kwds: keyword arguments
Additional keyword arguments for the interpolation function.
-
pesfit.utils.
index_gen
(x)¶ Index generator.
-
pesfit.utils.
intnz
(num)¶ Output an integer at least larger than 1.
-
pesfit.utils.
load_pickle
(fname)¶ Load pickled object.
-
pesfit.utils.
merge_nested_dict
(dicts)¶ Merge nested dictionaries.
Parameter
- dicts: list/tuple
Collection of dictionaries
-
pesfit.utils.
partial_flatten
(arr, axis)¶ Partially flatten a multidimensional array.
Parameters
- arr: numpy array
Multidimensional array for partial flattening.
- axis: list/tuple
Axes to flatten.
Return
- arr_pf: numpy array
Partially flattened array.
-
pesfit.utils.
pickle_obj
(fname, obj)¶ Pickle object.
-
pesfit.utils.
randomize
(data, axis=0, seed=None)¶ Randomize data along one axis.
-
pesfit.utils.
riffle
(*arr)¶ Interleave multiple arrays of the same number of elements.
Parameter
- *arr: array
A number of arrays
Return
- riffarr: 1D array
An array with interleaving elements from each input array.
-
pesfit.utils.
shape_gen
(scale_vector)¶ Generate a series of vector-related quantities.
-
pesfit.utils.
tqdmenv
(env)¶ Choose tqdm progress bar executing environment.
Parameter
- env: str
Name of the environment, ‘classic’ for ordinary environment, ‘notebook’ for Jupyter notebook.