def setUp(self): TestCaseQt.setUp(self) self.urls = OrderedDict() self._raw_data = {} self._folder = tempfile.mkdtemp() self._n_urls = 10 file_name = os.path.join(self._folder, 'test_inage_stack_file.h5') with h5py.File(file_name, 'w') as h5f: for i in range(self._n_urls): width = numpy.random.randint(10, 40) height = numpy.random.randint(10, 40) raw_data = numpy.random.random((width, height)) self._raw_data[i] = raw_data h5f[str(i)] = raw_data self.urls[i] = DataUrl(file_path=file_name, data_path=str(i), scheme='silx') self.widget = ImageStack() self.urlLoadedListener = SignalListener() self.widget.sigLoaded.connect(self.urlLoadedListener) self.currentUrlChangedListener = SignalListener() self.widget.sigCurrentUrlChanged.connect( self.currentUrlChangedListener)
def setCurrentUrl(self, url: typing.Union[DataUrl, str]) -> None: """ Define the url to be displayed :param url: url to be displayed :type: DataUrl """ assert isinstance(url, (DataUrl, str)) if isinstance(url, str): url = DataUrl(path=url) if url != self._current_url: self._current_url = url self.sigCurrentUrlChanged.emit(url.path()) old_url_table = self._urlsTable.blockSignals(True) old_slider = self._slider.blockSignals(True) self._urlsTable.setUrl(url) self._slider.setUrlIndex(self._urlIndexes[url.path()]) if self._current_url is None: self._plot.clear() else: if self._current_url.path() in self._urlData: self._plot.setData(self._urlData[url.path()]) else: self._load(url) self._notifyLoading() self._preFetch(self._getNNextUrls(self.__n_prefetch, url)) self._preFetch(self._getNPreviousUrls(self.__n_prefetch, url)) self._urlsTable.blockSignals(old_url_table) self._slider.blockSignals(old_slider)
def _updateUrl(self): # overloaded to filter for datasets nodes = list(self._tree.selectedH5Nodes()) newDatasetName = self._lineEditNewItem.text() isDatasetSelected = False if nodes: node = nodes[0] if silx.io.is_dataset(node.h5py_object): data_path = node.local_name isDatasetSelected = True elif silx.io.is_group(node.h5py_object): data_path = node.local_name if newDatasetName.lstrip("/"): if not data_path.endswith("/"): data_path += "/" data_path += newDatasetName.lstrip("/") isDatasetSelected = True if isDatasetSelected: self._selectedUrl = DataUrl(file_path=node.local_filename, data_path=data_path) self._okButton.setEnabled(True) self._labelSelection.setText( self._selectedUrl.path()) else: self._selectedUrl = None self._okButton.setEnabled(False) self._labelSelection.setText(self._selectDatasetStatusText)
def create_edf_url(file_name): """ create a simple DataUrl with a .edf file""" dsc = fabio.edfimage.EdfImage(data=create_random_image(), header={}) dsc.write(file_name) return [ DataUrl(file_path=file_name, data_slice=(0, ), scheme='fabio'), ]
def create_h5py_urls(n_url, file_name): """ creates n urls based on h5py""" res = [] with h5py.File(file_name, 'w') as h5f: for i in range(n_url): h5f[str(i)] = create_random_image() res.append( DataUrl(file_path=file_name, data_path=str(i), scheme='silx')) return res
def setFiles(self, files): urls = list() for _file in files: if os.path.isfile(_file): urls.append(DataUrl(file_path=_file, scheme=None)) urls.sort(key=lambda url: url.path()) window.setUrls(urls) window._selectionTable.setSelection(url_img_a=urls[0].path(), url_img_b=urls[1].path())
def dropEvent(self, event): mimeData = event.mimeData() if mimeData.hasFormat("application/x-silx-uri"): byteString = event.mimeData().data("application/x-silx-uri") path = byteString.data().decode("utf-8") url = DataUrl(path) self.setText(url.data_path()) else: qt.QMessageBox.critical(self, "Drop cancelled", "A HDF5 path is expected") return
def _updateUrl(self): nodes = list(self._tree.selectedH5Nodes()) subgroupName = self._lineEditNewItem.text() if nodes: node = nodes[0] data_path = node.local_name if subgroupName.lstrip("/"): if not data_path.endswith("/"): data_path += "/" data_path += subgroupName.lstrip("/") self._selectedUrl = DataUrl(file_path=node.local_filename, data_path=data_path) self._okButton.setEnabled(True) self._labelSelection.setText(self._selectedUrl.path())
def _updateUrl(self): nodes = list(self._tree.selectedH5Nodes()) subgroupName = self._lineEditSubgroup.text() if nodes: node = nodes[0] if silx.io.is_group(node.h5py_object): data_path = node.local_name if subgroupName.lstrip("/"): if not data_path.endswith("/"): data_path += "/" data_path += subgroupName.lstrip("/") self._selectedUrl = DataUrl(file_path=node.local_filename, data_path=data_path) self._okButton.setEnabled(True) self._labelSelection.setText(self._selectedUrl.path()) else: self._selectedUrl = None self._okButton.setEnabled(False) self._labelSelection.setText("Select a group")
def create_numpy_url(file_name): """ create a simple DataUrl with a .npy file """ numpy.save(file=file_name, arr=create_random_image()) return [ DataUrl(file_path=file_name, scheme='numpy'), ]
def test_silx_url(self): abs_a = os.path.abspath(self.a) url = DataUrl(abs_a).path() image = image_mdl.read_image_data(url) self.assertIsNotNone(image)