Example #1
0
def isJcampOpusStackFile(filename):
    if not JcampFileParser.isJcampFile(filename):
        return False
    # Parse the first scan
    jcamp = JcampFileParser.JcampFileParser(filename, single=True)
    scan = jcamp[0]
    header = parseFileHeader(scan.fileheader())
    if "BLOCKS" in header:
        if header["BLOCKS"] > 1:
            return True
    return False
Example #2
0
def isJcampOpusStackFile(filename):
    if not JcampFileParser.isJcampFile(filename):
        return False
    # Parse the first scan
    jcamp = JcampFileParser.JcampFileParser(filename, single=True)
    scan = jcamp[0]
    header = parseFileHeader(scan.fileheader())
    if "BLOCKS" in header:
        if header["BLOCKS"] > 1:
            return True
    return False
Example #3
0
def Specfile(filename):
    if BlissSpecFile.isBlissSpecFile(filename):
        return BlissSpecFile.BlissSpecFile(filename)
    if sys.version_info < (3, 0):
        f = open(filename)
    else:
        f = open(filename, 'r', errors="ignore")
    line0 = f.readline()
    if filename.upper().endswith('DTA'):
        #TwinMic single column file
        line = line0 * 1
        line = line.replace('\r', '')
        line = line.replace('\n', '')
        line = line.replace('\t', ' ')
        s = line.split(' ')
        if len(s) == 2:
            if len(s[-1]) == 0:
                try:
                    float(s[0])
                    f.close()
                    output = specfilewrapper(filename, dta=True)
                    return output
                except:
                    #try to read in other way
                    pass

    # this piece of code checks if we deal with a SPEC file
    # Prior to any data, all lines have to be either empty or starting
    # by the hash character.
    line = line0
    while (len(line)):
        if len(line) > 1:
            if line[0:2] == '#S':
                if ('#SIGNALTYPE' in line) or \
                   ('#SPECTRUM' in line):
                    line = ""
                break
            elif line[0] not in ['#', ' ', '\r']:
                line = ""
                break
        try:
            line = f.readline()
        except:
            line = ""
            break
    f.close()
    # end of specfile identification
    amptek = False
    qxas = False
    if len(line):
        #it is a Specfile
        _logger.debug("This looks as a specfile")
        output = specfile.Specfile(filename)
    elif SPX and ArtaxFileParser.isArtaxFile(filename):
        _logger.debug("This looks as an Artax file")
        output = ArtaxFileParser.ArtaxFileParser(filename)
    else:
        _logger.debug("this does not look as a specfile")
        if len(line0) > 7:
            if line0.startswith('$SPEC_ID') or\
               line0.startswith('$DATE_MEA') or\
               line0.startswith('$MEAS_TIM') or\
               line0.startswith('$Core_ID') or\
               line0.startswith('$Section_ID'):
                qxas = True
        if (not qxas) and line0.startswith('<<'):
            amptek = True
        if (not qxas) and (
                not amptek) and Fit2DChiFileParser.isFit2DChiFile(filename):
            return Fit2DChiFileParser.Fit2DChiFileParser(filename)
        if (not qxas) and (
                not amptek) and APSMEDFileParser.isAPSMEDFile(filename):
            return APSMEDFileParser.APSMEDFileParser(filename)
        if (not qxas) and (not amptek) and SRSFileParser.isSRSFile(filename):
            _logger.debug("SRSFileParser")
            return SRSFileParser.SRSFileParser(filename)
        if (not qxas) and (
                not amptek) and BAXSCSVFileParser.isBAXSCSVFile(filename):
            _logger.debug("BAXSCSVFileParser")
            return BAXSCSVFileParser.BAXSCSVFileParser(filename)
        if (not qxas) and (not amptek) and \
           OlympusCSVFileParser.isOlympusCSVFile(filename):
            _logger.debug("OlympusCSVFileParser")
            return OlympusCSVFileParser.OlympusCSVFileParser(filename)
        if (not qxas) and (not amptek) and \
           ThermoEMSFileParser.isThermoEMSFile(filename):
            _logger.debug("ThermoEMSFileParser")
            return ThermoEMSFileParser.ThermoEMSFileParser(filename)
        if (not qxas) and (not amptek) and \
           JcampFileParser.isJcampFile(filename):
            _logger.debug("JcampFileParser")
            return JcampFileParser.JcampFileParser(filename)
        output = specfilewrapper(filename, amptek=amptek, qxas=qxas)
    return output
Example #4
0
def Specfile(filename):
    f = open(filename)
    line0 = f.readline()
    if filename.upper().endswith('DTA'):
        #TwinMic single column file
        line = line0 * 1
        line = line.replace('\r', '')
        line = line.replace('\n', '')
        line = line.replace('\t', ' ')
        s = line.split(' ')
        if len(s) == 2:
            if len(s[-1]) == 0:
                try:
                    float(s[0])
                    f.close()
                    output = specfilewrapper(filename, dta=True)
                    f.close()
                    return output
                except:
                    #try to read in other way
                    pass
    line = line0
    while (len(line)):
        if len(line) > 1:
            if line[0:2] == '#S':
                if ('#SIGNALTYPE' in line) or \
                   ('#SPECTRUM' in line):
                    line = ""
                break
        line = f.readline()
    f.close()
    amptek = False
    qxas = False
    if len(line):
        #it is a Specfile
        _logger.debug("This looks as a specfile")
        output = specfile.Specfile(filename)
    elif SPX and filename.upper().endswith("SPX"):
        _logger.debug("This looks as an SPX file")
        output = SPXFileParser.SPXFileParser(filename)
    else:
        _logger.debug("this does not look as a specfile")
        if len(line0) > 7:
            if line0.startswith('$SPEC_ID') or\
               line0.startswith('$DATE_MEA') or\
               line0.startswith('$MEAS_TIM') or\
               line0.startswith('$Core_ID') or\
               line0.startswith('$Section_ID'):
                qxas = True
        if (not qxas) and line0.startswith('<<'):
            amptek = True
        if (not qxas) and (
                not amptek) and Fit2DChiFileParser.isFit2DChiFile(filename):
            return Fit2DChiFileParser.Fit2DChiFileParser(filename)
        if (not qxas) and (
                not amptek) and APSMEDFileParser.isAPSMEDFile(filename):
            return APSMEDFileParser.APSMEDFileParser(filename)
        if (not qxas) and (not amptek) and SRSFileParser.isSRSFile(filename):
            _logger.debug("SRSFileParser")
            return SRSFileParser.SRSFileParser(filename)
        if (not qxas) and (
                not amptek) and BAXSCSVFileParser.isBAXSCSVFile(filename):
            _logger.debug("BAXSCSVFileParser")
            return BAXSCSVFileParser.BAXSCSVFileParser(filename)
        if (not qxas) and (not amptek) and \
           OlympusCSVFileParser.isOlympusCSVFile(filename):
            _logger.debug("OlympusCSVFileParser")
            return OlympusCSVFileParser.OlympusCSVFileParser(filename)
        if (not qxas) and (not amptek) and \
           ThermoEMSFileParser.isThermoEMSFile(filename):
            _logger.debug("ThermoEMSFileParser")
            return ThermoEMSFileParser.ThermoEMSFileParser(filename)
        if (not qxas) and (not amptek) and \
           JcampFileParser.isJcampFile(filename):
            _logger.debug("JcampFileParser")
            return JcampFileParser.JcampFileParser(filename)
        output = specfilewrapper(filename, amptek=amptek, qxas=qxas)
    return output
Example #5
0
    def __init__(self, filename):
        DataObject.DataObject.__init__(self)
        fileParser = JcampFileParser.JcampFileParser(filename, single=False)
        scan = fileParser[0]
        fileHeader = scan.fileheader()
        firstHeaderInfo = parseFileHeader(fileHeader)
        if scan.nbmca() == 0:
            scan = fileParser[1]
        nBlocks = firstHeaderInfo["BLOCKS"]
        nbmca = scan.nbmca()

        # take the last mca of the scan
        lastMca = scan.mca(nbmca)
        nChannels = lastMca.size
        calib = scan.header('@CALIB')[0]
        if len(calib):
            calib = [float(x) for x in calib.split()[1:]]
        else:
            calib = [0.0, 1.0, 0.0]
        chann = scan.header('@CHANN')[0]
        if len(chann):
            ctxt = chann.split()
            if len(ctxt) == 5:
                chann = float(ctxt[2])
            else:
                chann = 0.0
        else:
            chann = 0.0

        # assume all mca have the same size, calibration, ...
        data = numpy.zeros((1, nBlocks, nChannels), dtype=numpy.float32)
        nScans = fileParser.scanno()
        mcaIndex = 0
        for i in range(nScans):
            scan = fileParser[i]
            if scan.nbmca():
                mcaData = scan.mca(scan.nbmca())
                data[0, mcaIndex] = mcaData
                mcaIndex += 1

        # make use of the collected information
        # shape
        xShape = firstHeaderInfo.get("$MAP_POINTS_IN_X", None)
        yShape = firstHeaderInfo.get("$MAP_POINTS_IN_Y", None)
        if (xShape is not None) and (yShape is not None):
            if xShape * yShape == nBlocks:
                data.shape = yShape, xShape, nChannels
            else:
                print("PRODUCT DOES NOT MATCH NUMBER OF BLOCKS")

        #scales
        xScale = [0.0, 1.0]
        yScale = [0.0, 1.0]
        xScale[0] = firstHeaderInfo.get("$MAP_ORIGIN_X", 0.0)
        xScale[1] = firstHeaderInfo.get("$MAP_DELTA_X", 1.0)
        yScale[0] = firstHeaderInfo.get("$MAP_ORIGIN_Y", 0.0)
        yScale[1] = firstHeaderInfo.get("$MAP_DELTA_Y", 1.0)

        self.sourceName = filename
        self.info = {}
        self.info["SourceType"] = SOURCE_TYPE
        self.info["SourceName"] = self.sourceName
        shape = self.data.shape
        for i in range(len(shape)):
            key = 'Dim_%d' % (i + 1, )
            self.info[key] = shape[i]
        self.info["NumberOfFiles"] = 1
        self.info["McaIndex"] = 2
        self.info["McaCalib"] = calib
        self.info["Channel0"] = chann
        self.info["xScale"] = xScale
        self.info["yScale"] = yScale
        self.data = data
Example #6
0
def Specfile(filename):
    f = open(filename)
    line0  = f.readline()
    if filename.upper().endswith('DTA'):
        #TwinMic single column file
        line = line0 * 1
        line = line.replace('\r','')
        line = line.replace('\n','')
        line = line.replace('\t',' ')
        s = line.split(' ')
        if len(s) == 2:
            if len(s[-1]) == 0:
                try:
                    float(s[0])
                    f.close()
                    output = specfilewrapper(filename, dta=True)
                    f.close()
                    return output
                except:
                    #try to read in other way
                    pass
    line = line0
    while(len(line)):
        if len(line) > 1:
            if line[0:2] == '#S':
                if ('#SIGNALTYPE' in line) or \
                   ('#SPECTRUM' in line):
                    line = ""
                break
        line = f.readline()
    f.close()
    amptek = False
    qxas   = False
    if len(line):
        #it is a Specfile
        if DEBUG:
            print("This looks as a specfile")
        output=specfile.Specfile(filename)
    elif SPX and filename.upper().endswith("SPX"):
        if DEBUG:
            print("This looks as an SPX file")
        output = SPXFileParser.SPXFileParser(filename)
    else:
        if DEBUG:
            print("this does not look as a specfile")
        if len(line0) > 7:
            if line0.startswith('$SPEC_ID') or\
               line0.startswith('$DATE_MEA') or\
               line0.startswith('$MEAS_TIM') or\
               line0.startswith('$Core_ID') or\
               line0.startswith('$Section_ID'):
                qxas = True
        if (not qxas) and line0.startswith('<<'):
                amptek = True
        if (not qxas) and (not amptek) and Fit2DChiFileParser.isFit2DChiFile(filename):
            return Fit2DChiFileParser.Fit2DChiFileParser(filename)
        if (not qxas) and (not amptek) and APSMEDFileParser.isAPSMEDFile(filename):
            return APSMEDFileParser.APSMEDFileParser(filename)
        if (not qxas) and (not amptek) and SRSFileParser.isSRSFile(filename):
            if DEBUG:
                print("SRSFileParser")
            return SRSFileParser.SRSFileParser(filename)
        if (not qxas) and (not amptek) and BAXSCSVFileParser.isBAXSCSVFile(filename):
            if DEBUG:
                print("BAXSCSVFileParser")
            return BAXSCSVFileParser.BAXSCSVFileParser(filename)
        if (not qxas) and (not amptek) and \
           OlympusCSVFileParser.isOlympusCSVFile(filename):
            if DEBUG:
                print("OlympusCSVFileParser")
            return OlympusCSVFileParser.OlympusCSVFileParser(filename)
        if (not qxas) and (not amptek) and \
           ThermoEMSFileParser.isThermoEMSFile(filename):
            if DEBUG:
                print("ThermoEMSFileParser")
            return ThermoEMSFileParser.ThermoEMSFileParser(filename)
        if (not qxas) and (not amptek) and \
           JcampFileParser.isJcampFile(filename):
            if DEBUG:
                print("JcampFileParser")
            return JcampFileParser.JcampFileParser(filename)
        output = specfilewrapper(filename, amptek=amptek, qxas=qxas)
    return output