Subset¶
-
class
glue.core.subset.
Subset
(data, color='#E31A1C', alpha=0.5, label=None)[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
Create a new subset object.
Note: the preferred way for creating subsets is via DataCollection.new_subset_group. Manually-instantiated subsets will probably not be represented properly by the UI
Attributes Summary
Returns a tuple of the ComponentIDs that this subset depends upon
Convenience access to subset’s label
Methods Summary
broadcast
(self, attribute)Explicitly broadcast a SubsetUpdateMessage to the hub
component_ids
(self)delete
(self)Broadcast a SubsetDeleteMessage to the hub, and stop broadcasting
do_broadcast
(self, value)Set whether state changes to the subset are relayed to a hub.
paste
(self, other_subset)paste subset state from other_subset onto self
read_mask
(self, file_name)register
(self)Register a subset to its data, and start broadcasting state changes
state_as_mask
(self)Convert the current SubsetState to a MaskSubsetState
to_index_list
(self)Convert the current subset to a list of indices.
to_mask
(self[, view])Convert the current subset to a mask.
write_mask
(self, file_name[, format])Write a subset mask out to file
Attributes Documentation
Methods Documentation
-
broadcast
(self, attribute)[source]¶ Explicitly broadcast a SubsetUpdateMessage to the hub
- Parameters
attribute (
str
) – The name of the attribute (if any) that should be broadcast as updated.
-
delete
(self)[source]¶ Broadcast a SubsetDeleteMessage to the hub, and stop broadcasting
Also removes subset reference from parent data’s subsets list
-
do_broadcast
(self, 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: value: Whether the subset should broadcast state changes (True/False)
-
to_index_list
(self)[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:
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
(self, view=None)[source]¶ Convert the current subset to a mask.
- Parameters
view –
- An optional view into the dataset (e.g. a slice)
If present, the mask will pertain to the view and not the entire dataset.
A boolean numpy array, the same shape as the data, that defines whether each element belongs to the subset.