perch.ph

Classes

PH()

Base persistent homology class.

Structures([structures, img_shape, wcs, ...])

Class for managing a collection of Structure objects.

class perch.ph.PH

Bases: object

Base persistent homology class.

Attributes:

datanp.ndarray

Input data array.

n_dimint

Number of dimensions in image.

max_Hiint

Maximum homology dimension to compute.

generatorsnp.ndarray

Persistent homology generators.

strucsperch.Structures

Structure object.

ph_fxnfunction

Function for computing PH (cripser or pycripser).

noisefloat

Noise map.

compute_hom(max_Hi=None, wcs=None, flip_data=True, verbose=True, embedded=False, noise=None, prep_img_kwargs={})

Compute persistent homology.

Parameters:

datanp.ndarray

Input data array.

max_Hiint

Maximum homology dimension to compute.

wcsastropy.wcs.WCS

WCS object.

flip_databool

Flip data array.

verbosebool

Print progress.

embeddedbool

Compute embedded PH.

noisenp.ndarray

Noise map of same shape as data.

Returns:

perch.PH

Persistent homology object.

Examples

Compute persistent homology of a small 2D image with a single Gaussian peak:

>>> import numpy as np
>>> from perch.ph import PH
>>> y, x = np.indices((8, 8))
>>> img = np.exp(-((y - 3)**2 + (x - 4)**2) / 2.0).astype(np.float32)
>>> ph = PH.compute_hom(data=img, verbose=False)
>>> ph.generators.shape
(1, 10)
export_generators(fname, odir='./')

Export generators to file.

Parameters:

fnamestr

File name.

odirstr

Output directory.

filter(dimension=None, min_life=None, max_life=None, min_birth=None, max_birth=None, min_death=None, max_death=None, min_life_norm_birth=None, min_life_norm_death=None, inds_dir=None, mask=None)

Filter structures.

Parameters:

dimensionint

Homology dimension.

min_lifefloat

Minimum lifetime.

max_lifefloat

Maximum lifetime.

min_birthfloat

Minimum birth.

max_birthfloat

Maximum birth.

min_deathfloat

Minimum death.

max_deathfloat

Maximum death.

min_life_norm_birthfloat

Minimum normalized lifetime at birth.

min_life_norm_deathfloat

Minimum normalized lifetime at death.

inds_dirstr

Directory for saving/loading indices.

masknp.ndarray

Mask for filtering.

Returns:

perch.Structures

Filtered structures.

Examples

Keep only the H0 generators from a precomputed persistent-homology result:

>>> import numpy as np
>>> from perch.ph import PH
>>> y, x = np.indices((8, 8))
>>> img = np.exp(-((y - 3)**2 + (x - 4)**2) / 2.0).astype(np.float32)
>>> ph = PH.compute_hom(data=img, verbose=False)
>>> h0 = ph.filter(dimension=0)
>>> h0.n_struc
1
load_from(odir='./', data=None, wcs=None, max_Hi=None, conv_fac=None, noise=None)

Load generators from file.

Parameters:

fnamestr

File name.

odirstr

Output directory.

datanp.ndarray

Input data array.

wcsastropy.wcs.WCS

WCS object.

max_Hiint

Maximum homology dimension to compute.

conv_facfloat

Conversion factor.

noisenp.ndarray

Noise map of same shape as data.

Returns:

perch.PH

Persistent homology object.