Ejemplo n.º 1
0
    def _readImageListHdf5(self, filenamelist):
        if h5py is None:
            self._criticalError("Cannot read HDF5 files (h5py is missing)")
            return None, None
        imagelist = []
        imagenames = []
        shape = tuple(sorted(self._requiredShape))

        def match(dset):
            return tuple(sorted(dset.shape)) == shape

        for uri in filenamelist:
            tmp = uri.split('::')
            if len(tmp) == 1:
                tmp = uri, None
            filename, h5path = tmp
            # URI exists?
            if h5path:
                with HDF5Widget.h5open(filename) as hdf5File:
                    if h5path not in hdf5File:
                        h5path = None
            # Prompt for missing HDF5 path
            if not h5path:
                tmp = HDF5Widget.getUri(parent=self._dialogParent,
                                        filename=filename,
                                        message='Select Group or Dataset')
                if not tmp:
                    return None, None
                tmp = tmp.split('::')
                if len(tmp) == 2:
                    h5path = tmp[1]
            if not h5path:
                return None, None
            # Add datasets from HDF5 path
            with HDF5Widget.h5open(filename) as hdf5File:
                # If `h5path` is an instance of NXdata, only the signals
                # (including auxilary signals) are considered for `match`.
                datasets = NexusUtils.selectDatasets(hdf5File[h5path],
                                                     match=match)
                if not datasets:
                    self._criticalError(
                        "No (valid) datasets were found in '%s::%s'" %
                        (filename, h5path))
                    return None, None
                elif len({dset.size for dset in datasets}) > 1:
                    self._criticalError(
                        "'%s::%s' contains datasets with different sizes. Select datasets separately."
                        % (filename, h5path))
                    return None, None
                else:
                    for dset in datasets:
                        imagename = '/'.join(dset.name.split('/')[-2:])
                        imagelist.append(dset[()])
                        imagenames.append(imagename)
        if not imagenames:
            self._criticalError('No valid data provided')
        return imagenames, imagelist
Ejemplo n.º 2
0
 def _loadExternalData(self):
     getfilter = True
     fileTypeList = ["EDF Files (*edf *ccd *tif)"]
     if HDF5:
         fileTypeList.append('HDF5 Files (*.h5 *.nxs *.hdf *.hdf5)')
     fileTypeList.append('ASCII Files (*)')
     fileTypeList.append("EDF Files (*)")
     message = "Open data file"
     filenamelist, ffilter = PyMcaFileDialogs.getFileList(
         parent=None,
         filetypelist=fileTypeList,
         message=message,
         getfilter=getfilter,
         single=True,
         currentfilter=None)
     if len(filenamelist) < 1:
         return
     filename = filenamelist[0]
     if ffilter.startswith('HDF5'):
         data = HDF5Widget.getDatasetValueDialog(
             filename=filename,
             message='Select your data set by a double click')
     elif ffilter.startswith("EDF"):
         edf = EdfFile.EdfFile(filename, "rb")
         if edf.GetNumImages() > 1:
             # TODO: A dialog showing the different images
             # based on the external images browser needed
             _logger.warning("WARNING: Taking first image")
         data = edf.GetData(0)
         edf = None
     elif ffilter.startswith("ASCII"):
         #data=numpy.loadtxt(filename)
         sf = specfilewrapper.Specfile(filename)
         targetScan = sf[0]
         data = numpy.array(targetScan.data().T, copy=True)
         targetScan = None
         sf = None
     return data
Ejemplo n.º 3
0
 def _loadExternalData(self):
     getfilter = True
     fileTypeList = ["EDF Files (*edf *ccd *tif)"]
     if HDF5:
         fileTypeList.append('HDF5 Files (*.h5 *.nxs *.hdf *.hdf5)')
     fileTypeList.append('ASCII Files (*)') 
     fileTypeList.append("EDF Files (*)")
     message = "Open data file"
     filenamelist, ffilter = PyMcaFileDialogs.getFileList(parent=None,
                                 filetypelist=fileTypeList,
                                 message=message,
                                 getfilter=getfilter,
                                 single=True,
                                 currentfilter=None)
     if len(filenamelist) < 1:
         return
     filename = filenamelist[0]
     if ffilter.startswith('HDF5'):
         data = HDF5Widget.getDatasetValueDialog(
                 filename=filename,
                 message='Select your data set by a double click')
     elif ffilter.startswith("EDF"):
         edf = EdfFile.EdfFile(filename, "rb")
         if edf.GetNumImages() > 1:
             # TODO: A dialog showing the different images
             # based on the external images browser needed
             _logger.warning("WARNING: Taking first image")
         data = edf.GetData(0)
         edf = None
     elif ffilter.startswith("ASCII"):
         #data=numpy.loadtxt(filename)
         sf = specfilewrapper.Specfile(filename)
         targetScan = sf[0]
         data = numpy.array(targetScan.data().T, copy=True)
         targetScan = None
         sf = None
     return data