def test_slice_subset_state(self): self.viewer.add_data(self.data) subset = self.data.new_subset() subset.subset_state = SliceSubsetState( self.data, [slice(1, 2), slice(None)]) assert self.viewer.layers[0].enabled assert self.viewer.layers[1].enabled
def test_incompatible_on_add(self): # Regression test for a bug when adding a dataset to a profile viewer # with a single incompatible subset. subset_state = SliceSubsetState(self.data, [slice(1, 2), slice(None)]) self.data_collection.new_subset_group(subset_state=subset_state, label='s1') data2 = Data(x=[[2, 3], [4, 3]], label='d2') self.data_collection.append(data2) self.viewer.add_data(data2)
def indices(self, value): if len(value) != self._original_data.ndim: raise ValueError( "The 'indices' tuple should have length {0}".format( self._original_data.ndim)) # For now we require the indices to be in the same position, i.e. we # don't allow changes in dimensionality of the derived dataset. if hasattr(self, '_indices'): changed = False for idim in range(self._original_data.ndim): before, after = self._indices[idim], value[idim] if type(before) != type(after): raise TypeError( "Can't change where the ``None`` values are in indices" ) elif before != after: changed = True else: changed = False self._indices = value # Compute a subset state that represents the indexing - this is used # for compute_statistic and compute_histogram slices = [slice(x) if x is None else x for x in self._indices] self._indices_subset_state = SliceSubsetState(self._original_data, slices) # Construct a list of original pixel component IDs self._original_pixel_cids = [] for idim in range(self._original_data.ndim): if self._indices[idim] is None: self._original_pixel_cids.append( self._original_data.pixel_component_ids[idim]) # Construct a list of original world component IDs self._original_world_cids = [] if len(self._original_data.world_component_ids) > 0: idim_new = 0 for idim in range(self._original_data.ndim): if self._indices[idim] is None: self._cid_to_original_cid[self.world_component_ids[ idim_new]] = self._original_data.world_component_ids[ idim] idim_new += 1 # Tell glue that the data has changed if changed and self.hub is not None: msg = NumericalDataChangedMessage(self) self.hub.broadcast(msg)
def test_clone(self): # Regression test for a bug that meant that deserializing a profile # viewer resulted in disabled layers self.viewer.add_data(self.data) subset = self.data.new_subset() subset.subset_state = SliceSubsetState( self.data, [slice(1, 2), slice(None)]) app = clone(self.app) assert app.viewers[0][0].layers[0].enabled assert app.viewers[0][0].layers[1].enabled app.close()