Utility functions (utils)#

Functions:

get_lnz_iter(lnz, x)

Create a lnz_iter object for varying a single lnz

distance_matrix(mask[, convention])

Create matrix of distances from elements of mask to nearest background point

lnpimasked_to_dataset(data[, keys])

Convert a lnPiMasked object into as Dataset.

dataset_to_lnpimasked(ds[, lnpi_name, ...])

Convert a Dataset to a lnPiMasked object.

peek_at(iterable)

Returns the first value from iterable, as well as a new iterator with the same content as the original iterable

lnpy.core.utils.get_lnz_iter(lnz, x)[source]#

Create a lnz_iter object for varying a single lnz

Parameters:
  • lnz (list) – list with one element equal to None. This is the component which will be varied For example, lnz=[lnz0,None,lnz2] implies use values of lnz0,lnz2 for components 0 and 2, and vary component 1

  • x (ndarray) – values to insert for variable component

Returns:

ndarray – Shape (len(x),len(lnz)). array with rows [lnz0,lnz1,lnz2]

lnpy.core.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

  • convention (str or bool, default 'image') – mask convention

Returns:

distance (ndarray) – Same shape as mask. Distance from possible feature elements to background

lnpy.core.utils.lnpimasked_to_dataset(data, keys=('lnpi', 'PE'))[source]#

Convert a lnPiMasked object into as Dataset.

Parameters:

data (lnPiMasked)

Returns:

output (Dataset)

lnpy.core.utils.dataset_to_lnpimasked(ds, lnpi_name='lnpi', pe_name='PE', extra_kws=None, **kwargs)[source]#

Convert a Dataset to a lnPiMasked object.

Parameters:
  • ds (Dataset)

  • lnpi_name, pe_name (str) – Names of ‘lnPi’ and ‘PE’ parameters

  • extra_kws (mapping, optional) – parameter extra_kws. Note that if pe_name found in ds, then will add it to extra_kws.

Returns:

lnpi (lnPiMasked)

lnpy.core.utils.peek_at(iterable)[source]#

Returns the first value from iterable, as well as a new iterator with the same content as the original iterable