Structure¶
- class astrodendro.Structure(indices, values, children=[], idx=None, dendrogram=None)¶
Bases:
object
A structure in the dendrogram, for example a leaf or a branch.
A structure that is part of a dendrogram knows which other structures it is related to. For example, it is possible to get the parent structure containing the present structure
s
by using theparent
attribute:>>> s.parent <Structure type=branch idx=2152>
Likewise, the
children
attribute can be used to get a list of all sub-structures:>>> s.children [<Structure type=branch idx=1680>, <Structure type=branch idx=5771>]
A number of attributes and methods are available to explore the structure in more detail, such as the
indices
andvalues
methods, which return the indices and values of the pixels that are part of the structure. These and other methods have asubtree=
option, which ifTrue
(the default) returns the quantities related to structure and all sub-structures, and ifFalse
includes only the pixels that are part of the structure, but excluding any sub-structure.Attributes Summary
Find the ancestor of this leaf/branch non-recursively.
A list of all the sub-structures contained in the present structure.
Get a flattened list of all child leaves and branches.
This is defined as the minimum value in the children structures, or the peak value of the present structure if it has no children.
Whether the present structure is a branch.
Whether the present structure is a leaf.
The level of the structure, i.e. how many structures need to be traversed to reach the present structure.
The parent structure containing the present structure.
The maximum value of pixels belonging to the branch (excluding sub-structure).
The minimum value of pixels belonging to the branch (excluding sub-structure).
Methods Summary
get_mask
([shape, subtree])Return a boolean mask outlining the structure.
get_npix
([subtree])Return the number of pixels in this structure.
get_peak
([subtree])Return (index, value) for the pixel with maximum value.
indices
([subtree])The indices of the pixels in this branch.
sorted_leaves
([sort_key, reverse, subtree])Return a list of sorted leaves.
values
([subtree])The values of the pixels in this branch.
Attributes Documentation
- ancestor¶
Find the ancestor of this leaf/branch non-recursively.
This always returns an object (may return self if the object has no parent). Results are partially cached to reduce recursion depth. The caching assumes that once an object has been given a parent, that parent will never change.
This method should be equivalent to:
- if self.parent == None:
return self
- else:
return self.parent.ancestor
- children¶
A list of all the sub-structures contained in the present structure.
- descendants¶
Get a flattened list of all child leaves and branches.
- height¶
This is defined as the minimum value in the children structures, or the peak value of the present structure if it has no children.
- is_branch¶
Whether the present structure is a branch.
- is_leaf¶
Whether the present structure is a leaf.
- level¶
The level of the structure, i.e. how many structures need to be traversed to reach the present structure.
This is 0 for structures in the trunk, with values increasing in steps of 1 towards the leaves.
- newick¶
- parent¶
The parent structure containing the present structure.
- smallest_index¶
- vmax¶
The maximum value of pixels belonging to the branch (excluding sub-structure).
- vmin¶
The minimum value of pixels belonging to the branch (excluding sub-structure).
Methods Documentation
- get_mask(shape=None, subtree=True)¶
Return a boolean mask outlining the structure.
- Parameters:
- shapetuple, optional
The shape of the array upon which to compute the mask. This is only required if the structure is not attached to a dendrogram.
- subtreebool, optional
Whether to recursively include all sub-structures in the mask.
- Returns:
- mask
ndarray
The mask outlining the structure (
False
values are used outside the structure, andTrue
values inside).
- mask
- get_npix(subtree=True)¶
Return the number of pixels in this structure.
- Parameters:
- subtreebool, optional
Whether to recursively include all sub-structures when counting the pixels.
- Returns:
- n_pixint
The number of pixels in this structure
- get_peak(subtree=True)¶
Return (index, value) for the pixel with maximum value.
- Parameters:
- subtreebool, optional
Whether to recursively include all sub-structures when searching for the peak.
- Returns:
- indextuple
The n-dimensional index of the peak pixel
- valuefloat
The value of the peak pixel
- indices(subtree=True)¶
The indices of the pixels in this branch.
- Parameters:
- subtreebool, optional
Whether to recursively include all sub-structures
- sorted_leaves(sort_key=<function Structure.<lambda>>, reverse=False, subtree=True)¶
Return a list of sorted leaves.
- Parameters:
- sort_keyfunction, optional
A function which given a structure will return a scalar that is then used for sorting. By default, this is set to a function that returns the peak value of a structure (including descendants).
- reversebool, optional
Whether to reverse the sorting.
- subtreebool, optional
Whether to recursively include all sub-structures in the list.
- Returns:
- leaveslist
A list of sorted leaves
- values(subtree=True)¶
The values of the pixels in this branch.
- Parameters:
- subtreebool, optional
Whether to recursively include all sub-structures