def _setup(self, color, alpha, label): self.color = color self.label = label # trigger disambiguation self.style = VisualAttributes(parent=self) self.style.markersize *= 2.5 self.style.color = color self.style.alpha = alpha
class GroupedSubset(Subset): """ A member of a SubsetGroup, whose internal representation is shared with other group members """ subset_state = Pointer('group.subset_state') label = Pointer('group.label') def __init__(self, data, group): """ :param data: :class:`~glue.core.data.Data` instance to bind to :param group: :class:`~glue.core.subset_group.SubsetGroup` """ self.group = group super(GroupedSubset, self).__init__(data, label=group.label, color=group.style.color, alpha=group.style.alpha) def _setup(self, color, alpha, label): self.color = color self.label = label # trigger disambiguation self.style = VisualAttributes(parent=self) self.style.markersize *= 2.5 self.style.color = color self.style.alpha = alpha # skip state setting here @property def verbose_label(self): return "%s (%s)" % (self.label, self.data.label) def sync_style(self, other): self.style.set(other) def __eq__(self, other): return other is self # In Python 3, if __eq__ is defined, then __hash__ has to be re-defined if six.PY3: __hash__ = object.__hash__ def __gluestate__(self, context): return dict(group=context.id(self.group), style=context.do(self.style)) @classmethod def __setgluestate__(cls, rec, context): dummy_grp = SubsetGroup() # __init__ needs group.label self = cls(None, dummy_grp) yield self self.group = context.object(rec['group']) self.style = context.object(rec['style'])
def __init__(self, color=settings.SUBSET_COLORS[0], alpha=0.5, label=None, subset_state=None): """ Create a new empty SubsetGroup Note: By convention, SubsetGroups should be created via DataCollection.new_subset. """ self.subsets = [] if subset_state is None: self.subset_state = SubsetState() else: self.subset_state = subset_state self.label = label self.style = VisualAttributes(parent=self) self.style.markersize *= 2.5 self.style.linewidth *= 2.5 self.style.color = color self.style.alpha = alpha
def __init__(self, data, color=settings.SUBSET_COLORS[0], alpha=0.5, label=None): """ 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 """ self._broadcasting = False # must be first def self.data = data self.label = label # trigger disambiguation self.subset_state = SubsetState() # calls proper setter method self.style = VisualAttributes(parent=self) self.style.markersize *= 1.5 self.style.color = color self.style.alpha = alpha # We assign a UUID which can then be used for example in equations # for derived components - the idea is that this doesn't change over # the life cycle of glue, so it is a more reliable way to refer to # components in strings than using labels self._uuid = str(uuid.uuid4())
def load_stacked_sequence(self, raster_data): for window, window_data in raster_data.items(): w_data = Data(label=f"{window.replace(' ', '_')}") w_data.coords = window_data.wcs w_data.add_component(Component(window_data.data), f"{window.replace(' ', '_')}") w_data.style = VisualAttributes(color='#7A617C') self.datasets.append(w_data)
def _setup(self, color, alpha, label): self.color = color self.label = label # trigger disambiguation self.style = VisualAttributes(parent=self) self.style.markersize *= 1.5 self.style.color = color self.style.alpha = alpha self.subset_state = SubsetState() # calls proper setter method
def load_sunpy_map(self, sunpy_map): sunpy_map_loaded = sunpy.map.Map(sunpy_map) label = 'sunpy-map-' + sunpy_map_loaded.name data = Data(label=label) data.coords = sunpy_map_loaded.wcs # preferred way, preserves more info in some cases data.meta = sunpy_map_loaded.meta data.add_component(Component(sunpy_map_loaded.data), sunpy_map_loaded.name) data.style = VisualAttributes(color='#FDB813', preferred_cmap=sunpy_map.cmap) self.datasets.append(data)
def load_sequence(self, raster_data): for window, window_data in raster_data.items(): for i, scan_data in enumerate(window_data): w_data = Data(label=f"{window.replace(' ', '_')}-scan-{i}") w_data.coords = scan_data.wcs w_data.add_component(Component(scan_data.data), f"{window}-scan-{i}") w_data.meta = scan_data.meta w_data.style = VisualAttributes(color='#5A4FCF') self.datasets.append(w_data)
def _parse_iris_raster(data, label): result = [] for window, window_data in data.items(): for i, scan_data in enumerate(window_data): w_data = Data(label=f"{window.replace(' ', '_')}-scan-{i}") w_data.coords = WCSCoordinates(scan_data.header) w_data.add_component(Component(scan_data.data), f"{window}-scan-{i}") w_data.meta = scan_data.meta w_data.style = VisualAttributes(color='#5A4FCF') result.append(w_data) return result
def load_sji(self, sji): with fits.open(sji) as hdul: hdul.verify("fix") label = hdul[0].header['TDESC1'] + hdul[0].header['OBSID'] data = Data(label=label) data.coords = WCSCoordinates(hdul[0].header) data.meta = hdul[0].header preferred_cmap_name = 'IRIS ' + hdul[0].header['TDESC1'].replace( '_', ' ') data.style = VisualAttributes(preferred_cmap=preferred_cmap_name) data.add_component(Component(hdul[0].data), label) self.datasets.append(data)
def __init__(self, label="", coords=None, **kwargs): """ :param label: label for data :type label: str Extra array-like keywords are extracted into components """ self._shape = () # Components self._components = OrderedDict() self._externally_derivable_components = OrderedDict() self._pixel_aligned_data = OrderedDict() self._pixel_component_ids = ComponentIDList() self._world_component_ids = ComponentIDList() # Coordinate conversion object self.coords = coords or Coordinates() self.id = ComponentIDDict(self) # Metadata self.meta = OrderedDict() # Subsets of the data self._subsets = [] # Hub that the data is attached to self.hub = None self.style = VisualAttributes(parent=self) self._coordinate_links = [] self.data = self self.label = label self.edit_subset = None for lbl, data in sorted(kwargs.items()): self.add_component(data, lbl) self._key_joins = {} # To avoid circular references when saving objects with references to # the data, we make sure that all Data objects have a UUID that can # uniquely identify them. self.uuid = str(uuid.uuid4())
def _parse_iris_raster(data, label): """ Parse IRIS Level 2 raster files so that it can be loaded by glue. """ w_dataset = [] for window, window_data in data.items(): for i, scan_data in enumerate(window_data): w_data = Data(label=f"{window.replace(' ', '_')}-{scan_data.meta['OBSID']}-scan-{i}") w_data.coords = WCSCoordinates(scan_data.wcs.to_header()) w_data.add_component(Component(scan_data.data), f"{window.replace(' ', '_')}-{scan_data.meta['OBSID']}-scan-{i}") w_data.meta = scan_data.meta w_data.style = VisualAttributes(color='#5A4FCF') w_dataset.append(w_data) return w_dataset
def _parse_sunpy_map(data, label): """ Parse SunPy map so that it can be loaded by ``glue``. """ scan_map = data label = label + '-' + scan_map.name result = Data(label=label) result.coords = scan_map.wcs # preferred way, preserves more info in some cases result.add_component(Component(scan_map.data), scan_map.name) result.meta = scan_map.meta result.style = VisualAttributes(color='#FDB813', preferred_cmap=scan_map.cmap) return result
def __init__(self, label="", **kwargs): """ :param label: label for data :type label: str Extra array-like keywords are extracted into components """ # Coordinate conversion object self.coords = Coordinates() self._shape = () # Components self._components = OrderedDict() self._pixel_component_ids = [] self._world_component_ids = [] self.id = ComponentIDDict(self) # Subsets of the data self._subsets = [] # Hub that the data is attached to self.hub = None self.style = VisualAttributes(parent=self) self._coordinate_links = None self.data = self self.label = label self.edit_subset = None for lbl, data in sorted(kwargs.items()): self.add_component(data, lbl) self._key_joins = {}
def __init__(self, data, color=settings.SUBSET_COLORS[0], alpha=0.5, label=None): """ 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 """ self._broadcasting = False # must be first def self.data = data self.label = label # trigger disambiguation self.subset_state = SubsetState() # calls proper setter method self.style = VisualAttributes(parent=self) self.style.markersize *= 1.5 self.style.color = color self.style.alpha = alpha