perch.structures

Classes

Structure([pi, id, id_ph, img_shape, sdir])

Class for storing information about a topological structure in an image.

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

Class for managing a collection of Structure objects.

class perch.structures.Structures(structures=None, img_shape=None, wcs=None, struc_map=None, level_map=None, inds_dir='./')

Bases: object

Class for managing a collection of Structure objects.

Parameters:

structuresdict

Dictionary of Structure objects.

img_shapetuple

Shape of the image.

wcsastropy.wcs.WCS

World Coordinate System of the image.

struc_mapnp.ndarray

Map of structure IDs.

level_mapnp.ndarray

Map of structure levels.

add_attributes(prop_df)

Add attributes to the structures collection.

Parameters:

prop_dfpandas.DataFrame

DataFrame of properties.

clear_struc_map()

Clear the structure map.

compute_segment_hierarchy(img_jnp=None, s_include=None, clobber=True, export=True, odir='./', fname='run', verbose=False, calc_supp_props=True, clear_indices=True)

Compute the segment hierarchy.

Parameters:

img_jnpjnp.ndarray

Image data.

s_includelist

List of structure IDs to include.

clobberbool

Clear the hierarchy.

export_parentbool

Export the parent DataFrame.

odirstr

Output directory.

fnamestr

File name.

verbosebool

Verbose output.

clear_indicesbool

Clear the pixel indices after computation (saves memory).

Examples

Segment the H0 generators of a one-peak image and inspect the resulting per-pixel structure map:

>>> 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.compute_segment_hierarchy(img_jnp=img, verbose=False, export=False)
>>> h0.struc_map.shape
(8, 8)
>>> h0.n_struc
1
export_level_map(fname='run', odir='./')

Export the level map.

Parameters:

fnamestr

File name.

odirstr

Output directory.

export_segmentation(fname='run', odir='./')

Export all information needed to recreate the segmentation (struc_map, level_map, structure properties).

Parameters:

fnamestr

File name.

odirstr

Output directory.

export_struc_map(fname='run', odir='./')

Export the structure map.

Parameters:

fnamestr

File name.

odirstr

Output directory.

generators()
get_mask(s_include=None, use_descendants=True)

‘ Get a binary mask of the structures in s_include.

Parameters:

s_includelist

List of structure IDs to include.

use_descendantsbool

Include descendants of structures in s_include.

Returns:

masknp.ndarray

Binary mask.

get_struc_map_mask(s_include=None, use_descendants=True)

Get an ID mask of the structures in s_include.

Parameters:

s_includelist

List of structure IDs to include.

use_descendantsbool

Include descendants of structures in s_include.

Returns:

struc_map_masknp.ndarray

Masked structure map.

id_mask(s_include=None)

Return a struc_map-style array carrying only the IDs of the selected structures, with NaN elsewhere. Equivalent to get_struc_map_mask(s_include, use_descendants=False) but kept as a flatter, descendants-free entry point.

Parameters

s_includelist, optional

Structure IDs to keep. Defaults to all.

Returns

masknp.ndarray

Image-shaped array. Pixels belonging to a selected structure carry that structure’s ID; all other pixels are NaN.

load_from(odir='./', fname='run', check_success=True)

Load the structure hierarchy.

Parameters:

verbosebool

Verbose output.

odirstr

Output directory.

fnamestr

File name.

remove_struc(s_remove, verbose=False)

Remove a structure.

NOTE: in development. need to add recursive removal of structure from all parent descendant lists in hierarchy

Parameters:

s_removeint

Structure ID to remove.

verbosebool

Verbose output.

remove_strucs(remove_ids, verbose=False)
sort_birth(s_include=None, invert=False)

Sort the structures by birth.

Parameters:

s_includelist

List of structure IDs to include.

invertbool

Invert the sorting.

sort_death(s_include=None, invert=False)

Sort the structures by death.

Parameters:

s_includelist

List of structure IDs to include.

invertbool

Invert the sorting.