コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
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'),
    ]
コード例 #5
0
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
コード例 #6
0
 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())
コード例 #7
0
 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
コード例 #8
0
 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())
コード例 #9
0
ファイル: GroupDialog.py プロジェクト: WuZifan/silx
 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")
コード例 #10
0
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'),
    ]
コード例 #11
0
 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)