Subset#
- class glue.core.subset.Subset(data, **kwargs)[source]#
Bases:
object
Base class to handle subsets of data.
These objects both describe subsets of a dataset, and relay any state changes to the hub that their parent data are assigned to.
This base class only directly implements the logic that relays state changes back to the hub. Subclasses implement the actual description and manipulation of data subsets
- Parameters:
- data
Data
The dataset that this subset describes
- data
Create a new subset object.
Note: the preferred way for creating subsets is via
new_subset_group()
. Manually-instantiated subsets will probably not be represented properly by the UIAttributes Summary
Returns a tuple of the ComponentIDs that this subset depends upon.
Convenience access to subset's label.
Methods Summary
broadcast
(attribute)Explicitly broadcast a SubsetUpdateMessage to the hub.
delete
()Broadcast a SubsetDeleteMessage to the hub, and stop broadcasting.
do_broadcast
(value)Set whether state changes to the subset are relayed to a hub.
paste
(other_subset)Paste subset state from other_subset onto self.
read_mask
(file_name)register
()Register a subset to its data, and start broadcasting state changes
Convert the current
SubsetState
to aMaskSubsetState
.Convert the current subset to a list of indices.
to_mask
([view])Convert the current subset to a mask.
write_mask
(file_name[, format])Write a subset mask out to file
Attributes Documentation
Methods Documentation
- broadcast(attribute)[source]#
Explicitly broadcast a SubsetUpdateMessage to the hub.
- Parameters:
- attributestr
The name of the attribute (if any) that should be broadcast as updated.
- delete()[source]#
Broadcast a SubsetDeleteMessage to the hub, and stop broadcasting.
Also removes subset reference from parent data’s subsets list.
- do_broadcast(value)[source]#
Set whether state changes to the subset are relayed to a hub.
It can be useful to turn off broadcasting, when modifying the subset in ways that don’t impact any of the clients.
- Attributes:
- valuebool
Whether the subset should broadcast state changes (True/False)
- state_as_mask()[source]#
Convert the current
SubsetState
to aMaskSubsetState
.
- to_index_list()[source]#
Convert the current subset to a list of indices. These index the elements in the (flattened) data object that belong to the subset.
If x is the numpy array corresponding to some component.data, the two following statements are equivalent:
x.flat[subset.to_index_list()] x[subset.to_mask()]
- Returns:
ndarray
A numpy array, giving the indices of elements in the data that belong to this subset.
- Raises:
- IncompatibleDataException
If an index list cannot be created for the requested data set.
- to_mask(view=None)[source]#
Convert the current subset to a mask.
- Parameters:
- viewobject
An optional view into the dataset (e.g. a slice) If present, the mask will pertain to the view and not the entire dataset.
- Returns:
ndarray
A boolean numpy array, the same shape as the data, that defines whether each element belongs to the subset.