Segmentation of lnPi (segment)#
Routines to segment lnPi
find max/peaks in lnPi
segment lnPi about these peaks
determine free energy difference between segments a. Merge based on low free energy difference
combination of 1-3.
Functions:
|
Find local max with fall backs min_distance and filter. |
Classes:
|
Data segmenter: |
|
Helper class to create phases |
|
Base class to build Phases objects from scalar values of lnz. |
|
create phases from scalar value of mu for fixed value of mu for other species |
|
Create phases from scalar value of mu at fixed value of dmu for other species |
|
Here, None is the index we will set. |
- lnpy.segment.peak_local_max_adaptive(data, *, style='indices', mask=None, min_distance=None, threshold_rel=0.0, threshold_abs=0.2, num_peaks_max=None, connectivity=None, errors='warn', **kwargs)[source]#
Find local max with fall backs min_distance and filter.
This is an adaptation of
peak_local_max(), which is called iteratively until the number of peaks is less than num_peaks_max.- Parameters:
data (array-like) – Image data to analyze
style (
{'indices', 'mask', 'marker'}) – Controls output styleindices : indices of peaks
mask : array of bool marking peak locations
marker : array of int
mask (
Noneorndarrayofbool) – Mask using “image” convention. Where mask is True, values are included.min_distance (
intor sequence ofint, optional) – min_distance parameter. If sequence, then callpeak_local_max()until number of peaks<=num_peaks_max. Default value is(5, 10, 15, 20, 25).threshold_rel, threshold_abs (
float) – thresholds parametersnum_peaks_max (
int, optional) – Max number of maxima/peaks to find. If not specified, any number of peaks allowed.connectivity (
int, optional) – Maximum number of orthogonal hops to consider a pixel/voxel as a neighbor. Accepted values are ranging from 1 toinput.ndim. IfNone, a full connectivity ofinput.ndimis used.errors (
{'ignore','raise','warn'}, default'warn') –If raise, raise exception if npeaks > num_peaks_max
If ignore, return all found maxima
If warn, raise warning if npeaks > num_peaks_max
**kwargs – Extra arguments to
skimage.feature.peak_local_max()
- Returns:
out (
ndarrayofintorlistofndarrayofbool) – Depending on the value of indices.
See also
Notes
The option mask is passed as the value labels in
peak_local_max()
- class lnpy.segment.Segmenter(peak_kws=NOTHING, watershed_kws=NOTHING)[source]#
Bases:
MyAttrsMixinData segmenter:
- Parameters:
min_distance (
intor sequence ofint, optional) – min_distance parameter. If sequence, then callpeak_local_max()until number of peaks<=num_peaks_max. Default value is(5, 10, 15, 20, 25).peak_kws (mapping, optional) – Optional parameters to
peak_local_max_adaptive()watershed_kws (mapping, optional) – Optional parameters to
watershed()
Methods:
peaks(data, *[, style, mask])Interface to
peak_local_max_adaptive()with default values from self.watershed(data, markers, mask, *[, connectivity])Interface to
skimage.segmentation.watershed()functionsegment_lnpi(lnpi[, markers, peak_kws, ...])Perform segmentations of lnPi object using watershed on negative of lnPi data.
asdict()Convert object to dictionary.
assign(**kws)Alias to
new_like().new_like(**kws)Create a new object with optional parameters.
- peaks(data, *, style='marker', mask=None, **kwargs)[source]#
Interface to
peak_local_max_adaptive()with default values from self.- Parameters:
data (array-like) – Image data to analyze
style (
{'indices', 'mask', 'marker'}) – Controls output styleindices : indices of peaks
mask : array of bool marking peak locations
marker : array of int
mask (
Noneorndarrayofbool) – Mask using “image” convention. Where mask is True, values are included.**kwargs – Extra arguments to
peak_local_max_adaptive(). Note that these overrideself.peak_kws.
- Returns:
ndarrayofintor sequence ofndarray– Ifstyle=='marker', then return label array. Otherwise, return indices of peaks.
See also
Notes
Any value not set will be inherited from self.peak_kws
- watershed(data, markers, mask, *, connectivity=None, **kwargs)[source]#
Interface to
skimage.segmentation.watershed()function- Parameters:
data (array-like) – Image data to analyze
markers (
int, orndarrayofint, optional) – Same shape as image. The desired number of markers, or an array marking the basins with the values to be assigned in the label matrix. Zero means not a marker. If None (no markers given), the local minima of the image are used as markers.mask (
Noneorndarrayofbool) – Mask using “image” convention. Where mask is True, values are included.connectivity (
ndarray, optional) – An array with the same number of dimensions as image whose non-zero elements indicate neighbors for connection. Following the scipy convention, default is a one-connected array of the dimension of the image.**kwargs – Extra arguments to
watershed()
- Returns:
labels (
ndarrayofint) – Each unique value i in labels indicates a mask. That islabels == iis a mask for feature i.
See also
- segment_lnpi(lnpi, markers=None, peak_kws=None, watershed_kws=None)[source]#
Perform segmentations of lnPi object using watershed on negative of lnPi data.
- Parameters:
lnpi (
lnPiMasked) – Object to be segmentedmarkers (
int, orndarrayofint, optional) – Same shape as image. The desired number of markers, or an array marking the basins with the values to be assigned in the label matrix. Zero means not a marker. If None (no markers given), the local minima of the image are used as markers.peak_kws (mapping, optional) – Optional parameters to
peak_local_max_adaptive()watershed_kws (mapping, optional) – Optional parameters to
watershed()
- Returns:
labels (
ndarrayofint) – Each unique value i in labels indicates a mask. That islabels == iis a mask for feature i.
See also
- assign(**kws)[source]#
Alias to
new_like().
- class lnpy.segment.PhaseCreator(nmax, ref, nmax_peak=None, segmenter=NOTHING, peak_kws=NOTHING, watershed_kws=NOTHING, tag_phases=None, phases_factory=<bound method lnPiCollection.from_list of <class 'lnpy.lnpiseries.lnPiCollection'>>, free_energy_kws=NOTHING, merge_phases=True, merge_kws=NOTHING, merge_phase_ids=True)[source]#
Bases:
MyAttrsMixinHelper class to create phases
- Parameters:
nmax (
int) – Maximum number of phases to allownmax_peak (
int, optional) – if specified, the allowable number of peaks to locate. This can be useful for some cases. These phases will be merged out at the end.ref (
lnPiMasked, optional) – Reference object.segmenter (
Segmenter, optional) – segmenter object to create labels/masks. Defaults to using base segmenter.peak_kws (mapping, optional) – Optional parameters to
peak_local_max_adaptive()watershed_kws (mapping, optional) – Optional parameters to
watershed()tag_phases (
callable(), optional) – Optional function which takes a list oflnPiMaskedobjects and returns on integer label for each object.phases_factory (
callable(), optional) – Factory function for returning Collection from a list oflnPiMaskedobject. Defaults tolnPiCollection.from_list().free_energy_kws (mapping, optional) – Optional arguments to
wFreeEnergy.from_labels()merge_phases (
bool, defaultTrue) – If True, merge phases usingwFreeEnergy.merge_regions()merge_kws (mapping, optional) – Optional arguments to
wFreeEnergy.merge_regions()merge_phase_ids (
bool, defaultTrue) – IfTrue, merge phases with same phase id (fromtag_phases).
Methods:
build_phases([lnz, efac, phases_factory, ...])Construct 'phases' for a lnPi object.
build_phases_mu(lnz)Factory constructor at fixed values of mu
build_phases_dmu(dlnz)Factory constructor at fixed values of dmu.
asdict()Convert object to dictionary.
assign(**kws)Alias to
new_like().new_like(**kws)Create a new object with optional parameters.
- build_phases(lnz=None, *, efac=None, phases_factory=True, phase_kws=None)[source]#
Construct ‘phases’ for a lnPi object.
This is quite an involved process. The steps are
Optionally find the location of the maxima in lnPi.
Segment lnpi using watershed
Merge phases which are energetically similar
Optionally merge phases which have the same phase_id
- Parameters:
lnz (
intor sequence ofint, optional) – lnz value to evaluate ref at. If not specified, use ref.lnzefac (
float, optional) – Optional value to use in energetic merging of phases.connectivity (
int, optional) – Maximum number of orthogonal hops to consider a pixel/voxel as a neighbor. Accepted values are ranging from 1 toinput.ndim. IfNone, a full connectivity ofinput.ndimis used.phases_factory (
callable()orbool, defaultTrue) – Function to convert list of phases into Phases object. If phases_factoryTrue, revert to self.phases_factory. If phases_factory isFalse, do not apply a factory, and return list oflnpy.lnpidata.lnPiMaskedand array of phase indices.phase_kws (mapping, optional) – Extra arguments to phases_factory
- Returns:
output (
listoflnPiMaskedandndarray, orlnPiCollection) – If no phase creator, return list of lnPiMasked objects and array of phase indices. Otherwise, lnPiCollection object.
- build_phases_mu(lnz)[source]#
Factory constructor at fixed values of mu
- Parameters:
{lnz_buildphases_mu}
See also
Examples
>>> import lnpy.examples >>> e = lnpy.examples.hsmix_example()
The default build phases from this multicomponent system requires specifies the activity for both species. For example:
>>> e.phase_creator.build_phases([0.1, 0.2]) <class lnPiCollection> lnz_0 lnz_1 phase 0.1 0.2 0 [0.1, 0.2] 1 [0.1, 0.2] dtype: object
But if we want to creat phases at a fixed value of either lnz_0 or lnz_1, we can do the following:
>>> b = e.phase_creator.build_phases_mu([None, 0.5])
Note the syntax [None, 0.5]. This means that calling b(lnz_0) will create a new object at [lnz_0, 0.5].
>>> b(0.1) <class lnPiCollection> lnz_0 lnz_1 phase 0.1 0.5 0 [0.1, 0.5] 1 [0.1, 0.5] dtype: object
Likewise, we can fix lnz_0 with
>>> b = e.phase_creator.build_phases_mu([0.5, None])
>>> b(0.1) <class lnPiCollection> lnz_0 lnz_1 phase 0.5 0.1 0 [0.5, 0.1] 1 [0.5, 0.1] dtype: object
To create an object at fixed value of
dmu_i = lnz_i - lnz_fixed, we use the following:>>> b = e.phase_creator.build_phases_dmu([None, 0.5])
Now any phase created will have
lnz = [lnz_0, 0.5 + lnz_0]>>> b(0.5) <class lnPiCollection> lnz_0 lnz_1 phase 0.5 1.0 0 [0.5, 1.0] 1 [0.5, 1.0] dtype: object
- build_phases_dmu(dlnz)[source]#
Factory constructor at fixed values of dmu.
Parameter#
{dlnz_buildphases_dmu}
See also
- assign(**kws)[source]#
Alias to
new_like().
- class lnpy.segment.BuildPhasesBase(x, phase_creator)[source]#
Bases:
objectBase class to build Phases objects from scalar values of lnz.
Methods:
__call__(lnz_index, *[, phases_factory])Build phases from scalar value of lnz.
- __call__(lnz_index, *, phases_factory=True, **kwargs)[source]#
Build phases from scalar value of lnz.
- Parameters:
lnz_index (
float) – Value of lnz for self.index index.{phases_factory}
**kwargs – Extra arguments to
PhaseCreator.build_phases()
- Returns:
output (
listoflnPiMaskedandndarray, orlnPiCollection) – If no phase creator, return list of lnPiMasked objects and array of phase indices. Otherwise, lnPiCollection object.
See also
- class lnpy.segment.BuildPhases_mu(lnz, phase_creator)[source]#
Bases:
BuildPhasesBasecreate phases from scalar value of mu for fixed value of mu for other species
- Parameters:
lnz (
listoffloatorNone) – 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.phase_creator (
PhaseCreator) – Factory method to create phases collection object. For example,lnPiCollection.from_list().
Methods:
__call__(lnz_index, *[, phases_factory])Build phases from scalar value of lnz.
- __call__(lnz_index, *, phases_factory=True, **kwargs)[source]#
Build phases from scalar value of lnz.
- Parameters:
lnz_index (
float) – Value of lnz for self.index index.{phases_factory}
**kwargs – Extra arguments to
PhaseCreator.build_phases()
- Returns:
output (
listoflnPiMaskedandndarray, orlnPiCollection) – If no phase creator, return list of lnPiMasked objects and array of phase indices. Otherwise, lnPiCollection object.
See also
- class lnpy.segment.BuildPhases_dmu(dlnz, phase_creator)[source]#
Bases:
BuildPhasesBaseCreate phases from scalar value of mu at fixed value of dmu for other species
- Parameters:
dlnz (
listoffloatorNone) – list with one element equal to None. This is the component which will be varied For example, dlnz=[dlnz0,None,dlnz2] implies use values of dlnz0,dlnz2 for components 0 and 2, and vary component 1. dlnz_i = lnz_i - lnz_index, where lnz_index is the value varied.phase_creator (
PhaseCreator) – Factory method to create phases collection object. For example,lnPiCollection.from_list().
Methods:
__call__(lnz_index, *[, phases_factory])Build phases from scalar value of lnz.
- __call__(lnz_index, *, phases_factory=True, **kwargs)[source]#
Build phases from scalar value of lnz.
- Parameters:
lnz_index (
float) – Value of lnz for self.index index.{phases_factory}
**kwargs – Extra arguments to
PhaseCreator.build_phases()
- Returns:
output (
listoflnPiMaskedandndarray, orlnPiCollection) – If no phase creator, return list of lnPiMasked objects and array of phase indices. Otherwise, lnPiCollection object.
See also
- class lnpy.segment.BuildPhases_Fixed_betaOmega(lnz, free_index, beta_omega, phase_creator)[source]#
Bases:
BuildPhasesBaseHere, None is the index we will set. Free_index is the one which will be varied to reach specified beta_omega
Methods:
__call__(lnz_index, *[, phases_factory, ...])Build phases from scalar value of lnz.
- __call__(lnz_index, *, phases_factory=True, lnz_free_index=None, **kwargs)[source]#
Build phases from scalar value of lnz.
- Parameters:
lnz_index (
float) – Value of lnz for self.index index.{phases_factory}
**kwargs – Extra arguments to
PhaseCreator.build_phases()
- Returns:
output (
listoflnPiMaskedandndarray, orlnPiCollection) – If no phase creator, return list of lnPiMasked objects and array of phase indices. Otherwise, lnPiCollection object.
See also