astrodendro.structure.Structure¶
-
class
astrodendro.structure.Structure(indices, values, children=[], idx=None, dendrogram=None)¶ 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
sby using theparentattribute:>>> s.parent <Structure type=branch idx=2152>
Likewise, the
childrenattribute 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
indicesandvaluesmethods, 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 ifFalseincludes only the pixels that are part of the structure, but excluding any sub-structure.Attributes
is_leafWhether the present structure is a leaf. is_branchWhether the present structure is a branch. vminThe minimum value of pixels belonging to the branch (excluding sub-structure). vmaxThe maximum value of pixels belonging to the branch (excluding sub-structure). heightThis is defined as the minimum value in the children structures, or the peak value of the present structure if it has no children. ancestorFind the ancestor of this leaf/branch non-recursively. parentThe parent structure containing the present structure. childrenA list of all the sub-structures contained in the present structure. descendantsGet a flattened list of all child leaves and branches. levelThe level of the structure, i.e. newickMethods
indices([subtree])The indices of the pixels in this branch. values([subtree])The values of the pixels in this branch. get_npix([subtree])Return the number of pixels in this structure. get_peak([subtree])Return (index, value) for the pixel with maximum value. sorted_leaves([sort_key, reverse, subtree])Return a list of sorted leaves. get_mask([shape, subtree])Return a boolean mask outlining the structure. Methods (detail)
-
indices(subtree=True)¶ The indices of the pixels in this branch.
Parameters: subtree : bool, optional
Whether to recursively include all sub-structures
-
values(subtree=True)¶ The values of the pixels in this branch.
Parameters: subtree : bool, optional
Whether to recursively include all sub-structures
-
get_npix(subtree=True)¶ Return the number of pixels in this structure.
Parameters: subtree : bool, optional
Whether to recursively include all sub-structures when counting the pixels.
Returns: n_pix : int
The number of pixels in this structure
-
get_peak(subtree=True)¶ Return (index, value) for the pixel with maximum value.
Parameters: subtree : bool, optional
Whether to recursively include all sub-structures when searching for the peak.
Returns: index : tuple
The n-dimensional index of the peak pixel
value : float
The value of the peak pixel
-
sorted_leaves(sort_key=<function <lambda>>, reverse=False, subtree=True)¶ Return a list of sorted leaves.
Parameters: sort_key : function, 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).
reverse : bool, optional
Whether to reverse the sorting.
subtree : bool, optional
Whether to recursively include all sub-structures in the list.
Returns: leaves : list
A list of sorted leaves
-
get_mask(shape=None, subtree=True)¶ Return a boolean mask outlining the structure.
Parameters: shape : tuple, 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.
subtree : bool, optional
Whether to recursively include all sub-structures in the mask.
Returns: mask :
ndarrayThe mask outlining the structure (
Falsevalues are used outside the structure, andTruevalues inside).
-