예제 #1
0
    def getFileHandle(self, inputfile):
        try:
            self._HDF5 = False
            if type(inputfile) == numpy.ndarray:
                return NumpyStack.NumpyStack(inputfile)

            if HDF5SUPPORT:
                if h5py.is_hdf5(inputfile):
                    self._HDF5 = True
                    try:
                        # if (len(self._filelist) == 1) && (self.mcaStep > 1)
                        # it should attempt to avoid loading  many times
                        # the stack into memory in case of multiple processes
                        return HDF5Stack1D.HDF5Stack1D(self._filelist,
                                                       self.selection)
                    except:
                        raise

            ffile = self.__tryEdf(inputfile)
            if ffile is None:
                ffile = self.__tryLucia(inputfile)
            if ffile is None:
                if inputfile[-3:] == "DAT":
                    ffile = self.__tryAifira(inputfile)
            if ffile is None:
                if LispixMap.isLispixMapFile(inputfile):
                    ffile = LispixMap.LispixMap(inputfile, native=False)
            if ffile is None:
                del ffile
                ffile = SpecFileLayer.SpecFileLayer()
                ffile.SetSource(inputfile)
            return ffile
        except:
            raise IOError("I do not know what to do with file %s" % inputfile)
예제 #2
0
 def getFileHandle(self, inputfile):
     try:
         self._HDF5 = False
         if HDF5SUPPORT:
             if h5py.is_hdf5(inputfile):
                 self._HDF5 = True
                 try:
                     return HDF5Stack1D.HDF5Stack1D(self._filelist,
                                                    self.selection)
                 except:
                     raise
         ffile = self.__tryEdf(inputfile)
         if ffile is None:
             ffile = self.__tryLucia(inputfile)
         if ffile is None:
             if inputfile[-3:] == "DAT":
                 ffile = self.__tryAifira(inputfile)
         if ffile is None:
             if LispixMap.isLispixMapFile(inputfile):
                 ffile = LispixMap.LispixMap(inputfile, native=False)
         if (ffile is None):
             del ffile
             ffile = SpecFileLayer.SpecFileLayer()
             ffile.SetSource(inputfile)
         return ffile
     except:
         raise IOError("I do not know what to do with file %s" % inputfile)
예제 #3
0
    def processList(self):
        self.__ncols = None
        self.__nrows = self.filestep
        counter = 0
        ffile   = SpecFileLayer.SpecFileLayer()
        for fitfile in self._filelist:
            self.onNewFile(fitfile, self._filelist)
            ffile.SetSource(fitfile)
            fileinfo = ffile.GetSourceInfo()
            # nscans = len(fileinfo['KeyList'])
            for scankey in  fileinfo['KeyList']:
                scan,order = scankey.split(".")
                info,data  = ffile.LoadSource(scankey)
                scan_obj = ffile.Source.select(scankey)
                if info['NbMca'] > 0:
                    for i in range(info['NbMca']):
                        point = int(i/info['NbMcaDet']) + 1
                        mca   = (i % info['NbMcaDet'])  + 1
                        key = "%s.%s.%05d.%d" % (scan,order,point,mca)
                        if i == 0:
                            mcainfo,mcadata = ffile.LoadSource(key)
                        mcadata = scan_obj.mca(i+1)
                        y0 = numpy.array(mcadata, numpy.float)
                        if counter == 0:
                            key0 = "%s key %s" % (os.path.basename(fitfile), key)
                            self.__ncols = len(y0)
                            image = numpy.zeros((self.__nrows,self.__ncols), \
                                                numpy.float)
                        if self.__ncols !=  len(y0):
                            print("spectrum has different number of columns")
                            print("skipping it")
                        else:
                            image[counter,:] = y0[:]
                            if (counter+1) == self.filestep:
                                if self.filestep > 1:
                                    key1    = "%s key %s" % (os.path.basename(fitfile), key)
                                    title = "%s to %s" % (key0, key1)
                                else:
                                    title = key0
                                if 1:
                                    ddict={}
                                    if 'Channel0' in mcainfo:
                                        ddict['MCA start ch'] =\
                                                   int(mcainfo['Channel0'])
                                    if 'McaCalib' in mcainfo:
                                        ddict['MCA a'] = mcainfo['McaCalib'][0]
                                        ddict['MCA b'] = mcainfo['McaCalib'][1]
                                        ddict['MCA c'] = mcainfo['McaCalib'][2]
                                else:
                                    ddict = mcainfo
                                ddict['Title'] = title
                                edfname = os.path.join(self.outputdir,title.replace(" ","_")+".edf")
                                edfout  = EdfFile.EdfFile(edfname)
                                edfout.WriteImage (ddict , image, Append=0)
                                counter = 0
                            else:
                                counter += 1

        self.onEnd()
예제 #4
0
    def testSpecMesh(self):
        filename = os.path.join(self.path, 'meshscan.dat')

        # SpecFileStack: only works with one detector
        nDet = 1
        info = XrfData.generateSpecMesh(filename, nDet=nDet, same=False)
        nDet0, nRows0, nColumns0, nChannels = info['data'].shape

        from PyMca5.PyMcaIO import SpecFileStack
        stack = SpecFileStack.SpecFileStack(filelist=[filename]).data
        self.assertEqual(nDet, nDet0)
        self.assertEqual(stack.shape, (1, nRows0 * nColumns0, nChannels))

        for i in range(nRows0):
            for j in range(nColumns0):
                for k in range(1):
                    # C-order (row-major)
                    mca = stack[k, i * nColumns0 + j]
                    numpy.testing.assert_array_equal(mca, info['data'][k, i,
                                                                       j])

        # SpecFileLayer: works with more than one detector
        nDet = 2
        info = XrfData.generateSpecMesh(filename, nDet=nDet, same=False)
        nDet0, nRows0, nColumns0, nChannels = info['data'].shape
        nCounters0 = 2

        from PyMca5.PyMcaCore import SpecFileLayer
        ffile = SpecFileLayer.SpecFileLayer()
        ffile.SetSource(filename)
        fileinfo = ffile.GetSourceInfo()
        scaninfo, counters = ffile.LoadSource('1.1')
        scan = ffile.Source.select('1.1')
        nCounters, nRows, nColumns = counters.shape
        self.assertEqual(scaninfo['NbMcaDet'], nDet)
        self.assertEqual(scaninfo['NbMca'], nDet * nColumns * nRows)
        self.assertEqual(nColumns, nColumns0)
        self.assertEqual(nRows, nRows0)
        self.assertEqual(nCounters, nCounters0)
        self.assertEqual(nDet, nDet0)

        for i in range(nRows):
            for j in range(nColumns):
                for k in range(nDet):
                    mca = scan.mca(i * nColumns * nDet + j * nDet + k + 1)
                    # TODO: bug in specfile (reads one channel less)
                    numpy.testing.assert_array_equal(mca, info['data'][k, i,
                                                                       j])
        del ffile.Source
예제 #5
0
def test():
    import sys
    from PyMca5.PyMcaCore import SpecFileLayer
    app = qt.QApplication([])
    tab = SpecFileMcaTable()
    d = SpecFileLayer.SpecFileLayer()
    if len(sys.argv) > 1:
        d.SetSource(sys.argv[1])
    else:
        d.SetSource('03novs060sum.mca')
    info, data = d.LoadSource('1.1')
    tab.build(info)
    tab.setSelectedMca(["1.1"])
    tab.show()
    app.exec()
예제 #6
0
def test():
    from PyMca5.PyMcaCore import SpecFileLayer

    if len(sys.argv) < 3:
        print("USAGE: %s <filename> <key>" % sys.argv[0])
        sys.exit(0)

    d = SpecFileLayer.SpecFileLayer()

    d.SetSource(sys.argv[1])
    info, data = d.LoadSource(sys.argv[2])

    app = qt.QApplication([])
    wid = SpecFileDataInfo(info)
    wid.show()
    app.exec_()