def testWeirdAxisInfos(self): """ If we add a dataset that has the channel axis in the wrong place, the operator should automatically transpose it to be last. """ weirdAxisFilename = os.path.join(self.workingDir, "WeirdAxes.npy") expected_data = numpy.random.random((3, 100, 100)) numpy.save(weirdAxisFilename, expected_data) info = FilesystemDatasetInfo(filePath=weirdAxisFilename, axistags=vigra.defaultAxistags("cxy")) op = OpDataSelectionGroup(graph=Graph(), forceAxisOrder=False) op.WorkingDirectory.setValue(self.workingDir) op.DatasetRoles.setValue(["RoleA"]) op.DatasetGroup.resize(1) op.DatasetGroup[0].setValue(info) assert op.ImageGroup[0].ready() data_from_op = op.ImageGroup[0][:].wait() assert data_from_op.dtype == expected_data.dtype assert data_from_op.shape == expected_data.shape, (data_from_op.shape, expected_data.shape) assert (data_from_op == expected_data).all() # op.Image is a synonym for op.ImageGroup[0] assert op.Image.ready() assert (op.Image[:].wait() == expected_data).all() # Ensure that files opened by the inner operators are closed before we exit. op.DatasetGroup.resize(0)
def testNoChannelAxis(self): """ If we add a dataset that is missing a channel axis altogether, the operator should automatically append a channel axis. """ noChannelFilename = os.path.join(self.workingDir, "NoChannelAxis.npy") noChannelData = numpy.random.random((100, 100)) numpy.save(noChannelFilename, noChannelData) info = FilesystemDatasetInfo(filePath=noChannelFilename, axistags=vigra.defaultAxistags("xy")) op = OpDataSelectionGroup(graph=Graph()) op.WorkingDirectory.setValue(self.workingDir) op.DatasetRoles.setValue(["RoleA"]) op.DatasetGroup.resize(1) op.DatasetGroup[0].setValue(info) assert op.ImageGroup[0].ready() # Note that we expect a channel axis to be appended to the data. expected_data = noChannelData[:, :, numpy.newaxis] data_from_op = op.ImageGroup[0][:].wait() assert data_from_op.dtype == expected_data.dtype assert data_from_op.shape == expected_data.shape assert (data_from_op == expected_data).all() # op.Image is a synonym for op.ImageGroup[0] assert op.Image.ready() assert (op.Image[:].wait() == expected_data).all() # Ensure that files opened by the inner operators are closed before we exit. op.DatasetGroup.resize(0)
def create_and_modify_widget( qtbot, infos: List[DatasetInfo], project_file: h5py.File, nickname: str = None, axiskeys: str = "", normalizeDisplay: bool = DONT_SET_NORMALIZE, drange: Tuple[Number, Number] = None, display_mode: str = None, location: type = None, ): project_file = project_file or empty_project_file() opDataSelectionGroup = OpDataSelectionGroup(graph=Graph()) opDataSelectionGroup.ProjectFile.setValue(project_file) opDataSelectionGroup.ProjectDataGroup.setValue(TOP_GROUP_NAME) serializer = DataSelectionSerializer(opDataSelectionGroup, TOP_GROUP_NAME) widget = DatasetInfoEditorWidget(None, infos, serializer) qtbot.addWidget(widget) widget.show() assert widget.multi_axes_display.text() == "Current: " + ", ".join( info.axiskeys for info in infos) if axiskeys: assert widget.axesEdit.isVisible() assert widget.axesEdit.isEnabled() widget.axesEdit.setText(axiskeys) if nickname: assert widget.nicknameEdit.isEnabled() widget.nicknameEdit.setText("SOME_NICKNAME") if normalizeDisplay is not DONT_SET_NORMALIZE: widget.normalizeDisplayComboBox.setCurrentIndex( widget.normalizeDisplayComboBox.findData(normalizeDisplay)) if drange is not None: widget.rangeMinSpinBox.setValue(drange[0]) widget.rangeMaxSpinBox.setValue(drange[1]) if display_mode is not None: index = widget.displayModeComboBox.findData(display_mode) widget.displayModeComboBox.setCurrentIndex(index) if location is not None: comboIndex = widget.storageComboBox.findData(location) widget.storageComboBox.setCurrentIndex(comboIndex) return widget
def test(self): """ Make sure that the dataset roles work the way we expect them to. """ infoA = DatasetInfo() infoA.filePath = self.group1Data[0][0] infoC = DatasetInfo() infoC.filePath = self.group1Data[1][0] graph = Graph() op = OpDataSelectionGroup(graph=graph) op.WorkingDirectory.setValue(self.workingDir) op.DatasetRoles.setValue(['RoleA', 'RoleB', 'RoleC']) op.DatasetGroup.resize(3) op.DatasetGroup[0].setValue(infoA) # Leave RoleB blank -- datasets other than the first are optional op.DatasetGroup[2].setValue(infoC) assert op.ImageGroup[0].ready() assert op.ImageGroup[2].ready() expectedDataA = self.group1Data[0][1] dataFromOpA = op.ImageGroup[0][:].wait() assert dataFromOpA.dtype == expectedDataA.dtype assert dataFromOpA.shape == expectedDataA.shape assert (dataFromOpA == expectedDataA).all() expectedDataC = self.group1Data[0][1] dataFromOpC = op.ImageGroup[0][:].wait() assert dataFromOpC.dtype == expectedDataC.dtype assert dataFromOpC.shape == expectedDataC.shape assert (dataFromOpC == expectedDataC).all() assert op.Image.ready() assert (op.Image[:].wait() == expectedDataA).all() # Ensure that files opened by the inner operators are closed before we exit. op.DatasetGroup.resize(0)
def testWeirdAxisInfos(self): """ If we add a dataset that has the channel axis in the wrong place, the operator should automatically transpose it to be last. """ weirdAxisFilename = os.path.join(self.workingDir, 'WeirdAxes.npy') weirdAxisData = numpy.random.random( (3,100,100) ) numpy.save(weirdAxisFilename, weirdAxisData) info = DatasetInfo() info.filePath = weirdAxisFilename info.axistags = vigra.defaultAxistags('cxy') graph = Graph() op = OpDataSelectionGroup( graph=graph ) op.WorkingDirectory.setValue( self.workingDir ) op.DatasetRoles.setValue( ['RoleA'] ) op.DatasetGroup.resize( 1 ) op.DatasetGroup[0].setValue( info ) assert op.ImageGroup[0].ready() # Note that we expect the channel axis to be transposed to be last. expected_data = weirdAxisData.transpose( 1,2,0 ) data_from_op = op.ImageGroup[0][:].wait() assert data_from_op.dtype == expected_data.dtype assert data_from_op.shape == expected_data.shape assert (data_from_op == expected_data).all() # op.Image is a synonym for op.ImageGroup[0] assert op.Image.ready() assert (op.Image[:].wait() == expected_data).all() # Ensure that files opened by the inner operators are closed before we exit. op.DatasetGroup.resize(0)
def test(self): infoA = DatasetInfo() infoA.filePath = self.group1Data[0][0] infoC = DatasetInfo() infoC.filePath = self.group1Data[1][0] graph = Graph() op = OpDataSelectionGroup(graph=graph) op.WorkingDirectory.setValue(self.workingDir) op.DatasetRoles.setValue(['RoleA', 'RoleB', 'RoleC']) op.DatasetGroup.resize(3) op.DatasetGroup[0].setValue(infoA) # Leave RoleB blank -- datasets other than the first are optional op.DatasetGroup[2].setValue(infoC) assert op.ImageGroup[0].ready() assert op.ImageGroup[2].ready() expectedDataA = self.group1Data[0][1] dataFromOpA = op.ImageGroup[0][:].wait() assert dataFromOpA.dtype == expectedDataA.dtype assert dataFromOpA.shape == expectedDataA.shape assert (dataFromOpA == expectedDataA).all() expectedDataC = self.group1Data[0][1] dataFromOpC = op.ImageGroup[0][:].wait() assert dataFromOpC.dtype == expectedDataC.dtype assert dataFromOpC.shape == expectedDataC.shape assert (dataFromOpC == expectedDataC).all() assert op.Image.ready() assert (op.Image[:].wait() == expectedDataA).all()