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 impements 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

attributes Returns a tuple of the ComponentIDs that this subset
label Convenience access to subset’s label
style
subset_state

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_as_mask() Convert the current SubsetState to a MaskSubsetState
to_index_list() 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

attributes

Returns a tuple of the ComponentIDs that this subset depends upon

label

Convenience access to subset’s label

style
subset_state

Methods Documentation

broadcast(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()[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: value: Whether the subset should broadcast state changes (True/False)

paste(other_subset)[source]

paste subset state from other_subset onto self

read_mask(file_name)[source]
register()[source]

Register a subset to its data, and start broadcasting state changes

state_as_mask()[source]

Convert the current SubsetState to a MaskSubsetState

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:

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: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.
Returns:
A boolean numpy array, the same shape as the data, that defines whether each element belongs to the subset.
write_mask(file_name, format='fits')[source]

Write a subset mask out to file

Parameters:
  • file_name – name of file to write to
  • format – Name of format to write to. Currently, only “fits” is supported