Utility functions (utils)#
Functions:
|
Convert an array from one 'mask' convention to another. |
|
Perform convention change of sequence of masks |
|
Convert labels array to list of masks |
|
Convert list of masks to labels |
|
Inverse of ffill |
|
Create a lnz_iter object for varying a single lnz |
|
Create matrix of distances from elements of mask to nearest background point |
|
Convert a |
|
Convert a |
|
Convert |
Convert array to scalar. |
Classes:
Interface to |
- lnpy.utils.mask_change_convention(mask, convention_in='image', convention_out='masked')[source]#
Convert an array from one ‘mask’ convention to another.
- Parameters:
convention_in, convention_out (
stringorbool) – Convention for input and output. Convention for mask. Allowable values are:'image' ``or ``True: True values included, False values excluded. This is the normal convention inscipy.ndimage.'masked'orFalse: False values are included, True values are excluded. This is the convention innumpy.ma
- Returns:
ndarray– New ‘mask’ array with specified convention.
- lnpy.utils.masks_change_convention(masks, convention_in='image', convention_out='masked')[source]#
Perform convention change of sequence of masks
- Parameters:
masks (sequence of array-like) – masks[i] is the ‘ith’ mask
convention_in, convention_out (
stringorboolorNone) – Convention for input and output. Convention for mask. Allowable values are:‘image’ or True : True values included, False values excluded. This is the normal convention in
scipy.ndimage.‘masked’ or False: False values are included, True values are excluded. This is the convention in
numpy.ma
If None, then pass return input mask
- Returns:
new_masks (
listofndarray) – New ‘masks’ array with specified convention.
- lnpy.utils.labels_to_masks(labels, features=None, include_boundary=False, convention='image', check_features=True, **kwargs)[source]#
Convert labels array to list of masks
- Parameters:
labels (
ndarrayofint) – Each unique value i in labels indicates a mask. That islabels == i.features (sequence of
int) – If specified, extract only those locations wherelabels == featurefor all valuesfeature in features. That is, select a subset of unique label values.include_boundary (
bool) – if True, include boundary regions in output maskconvention (
stringorbool) – Convention for mask. Allowable values are:- ‘image’ or TrueTrue values included, False values excluded.
This is the normal convention in
scipy.ndimage.
- ‘masked’ or False: False values are included, True values are excluded.
This is the convention in
numpy.ma
check_features (
bool) – if True, then make sure each feature is in labels**kwargs – arguments to find_boundary if include_boundary is True default to mode=’outer’, connectivity=labels.ndim
- Returns:
- lnpy.utils.masks_to_labels(masks, features=None, convention='image', dtype=<class 'numpy.int64'>)[source]#
Convert list of masks to labels
- Parameters:
masks (
listof array-like ofbool) – list of mask arrays.features (sequence of
int) – If specified, extract only those locations wherelabels == featurefor all valuesfeature in features. That is, select a subset of unique label values.convention (
stringorbool) – Convention for mask. Allowable values are:- ‘image’ or TrueTrue values included, False values excluded.
This is the normal convention in
scipy.ndimage.
- ‘masked’ or False: False values are included, True values are excluded.
This is the convention in
numpy.ma
- Returns:
ndarray– Label array.
See also
- lnpy.utils.get_lnz_iter(lnz, x)[source]#
Create a lnz_iter object for varying a single lnz
- Parameters:
- Returns:
ndarray– Shape(len(x),len(lnz)). array with rows [lnz0,lnz1,lnz2]
- lnpy.utils.distance_matrix(mask, convention='image')[source]#
Create matrix of distances from elements of mask to nearest background point
- Parameters:
mask (array-like) – image mask
- Returns:
distance (
ndarray) – Same shape as mask. Distance from possible feature elements to background
See also
- lnpy.utils.lnpimasked_to_dataset(data, keys=('lnpi', 'PE'))[source]#
Convert a
lnPiMaskedobject into asDataset.- Parameters:
data (
lnPiMasked)- Returns:
output (
Dataset)
- lnpy.utils.dataset_to_lnpimasked(ds, lnpi_name='lnpi', pe_name='PE', extra_kws=None, **kwargs)[source]#
Convert a
Datasetto alnPiMaskedobject.- Parameters:
- Returns:
lnpi (
lnPiMasked)
- class lnpy.utils.RootResultDict[source]#
Bases:
dictInterface to
scipy.optimize.RootResults.
- lnpy.utils.rootresults_to_rootresultdict(r, residual)[source]#
Convert
scipy.optimize.RootResultsto typed dictionary