示例#1
0
 def save(self, filename):
     """
     Save time vector states and inputs to file filename
     """
     from itertools import chain as ch
     f = open(filename, 'w')
     f.write('Time, ' + ', '.join(ch(self.sol['states'].keys())) + ', ' +
             ', '.join(ch(self.sol['inputs'].keys())) + '\n') 
     np.savetxt(f, np.vstack((self.sol['t'],
                              self.sol['states'].values(),
                              self.sol['inputs'].values())).T,
                   delimiter=', ')
     f.close()
示例#2
0
 def save(self, filename):
     """
     Save time vector states and inputs to file filename
     """
     from itertools import chain as ch
     f = open(filename, 'w')
     f.write('Time, ' + ', '.join(ch(self.sol['states'].keys())) + ', ' +
             ', '.join(ch(self.sol['inputs'].keys())) + '\n')
     np.savetxt(f,
                np.vstack((self.sol['t'], self.sol['states'].values(),
                           self.sol['inputs'].values())).T,
                delimiter=', ')
     f.close()
    def __init__(self, filename):
        self.filename = filename
        self.mzid = open(filename, "r")
        self.tree = xml.parse(self.mzid)
        self.root = self.tree.getroot()

        assert "mzIdentML" in self.root.tag, "%s does not appear to be a valid mzIdentML file."
        if self.root.get("version") != "1.1.0":
            print((
                "Multiplierz mzIdentML reader was written against the specification "
                "for mzIdentML version 1.1.0; this file is version %s, so there may "
                "be discrepancies in the results." % self.root.get("version")))

        self.getSourceMode()

        self.pfx = self.root.tag[:-9]  # Take out "mzIdentML", when present.
        # (There's probably a more proper way to do this!)

        # The below be done as-needed
        # or at least in a single iterator (but it seems fast enough.)
        self.parentMap = dict(
            sum([[(c.get("id"), p.get("id"))
                  for c in p if c.get("id") and p.get("id")]
                 for p in ch(
                     self.tree.getiterator(self.pfx + "ProteinAmbiguityGroup"),
                     self.tree.getiterator(self.pfx +
                                           "SpectrumIdentificationResult"))],
                []))

        proteinElements = self.root.getiterator(self.pfx +
                                                "ProteinDetectionHypothesis")
        self.proteinLookup = {prot.get("id"): prot for prot in proteinElements}

        spectrumElements = self.root.getiterator(
            self.pfx + "SpectrumIdentificationResult")
        self.spectrumLookup = {
            spec.get("id"): spec
            for spec in spectrumElements
        }

        pepIdElements = self.root.getiterator(self.pfx +
                                              "SpectrumIdentificationItem")
        self.pepIdLookup = {pepid.get("id"): pepid for pepid in pepIdElements}

        evidenceElements = self.root.getiterator(self.pfx + "PeptideEvidence")
        self.evidenceLookup = {evi.get("id"): evi for evi in evidenceElements}

        dbElements = self.root.getiterator(self.pfx + "DBSequence")
        self.dbLookup = {db.get("id"): db for db in dbElements}

        peptideElements = self.root.getiterator(self.pfx + "Peptide")
        self.peptideLookup = {pep.get("id"): pep for pep in peptideElements}

        fileElements = self.root.getiterator(self.pfx + "SpectraData")
        self.fileLookup = {data.get("id"): data for data in fileElements}

        self.dataFileScans = {}
        self.filePointers = {}
示例#4
0
    def __init__(self, filename):
        self.filename = filename
        self.mzid = open(filename, "r")
        self.tree = xml.parse(self.mzid)
        self.root = self.tree.getroot()

        assert "mzIdentML" in self.root.tag, "%s does not appear to be a valid mzIdentML file."
        if self.root.get("version") != "1.1.0":
            print ("Multiplierz mzIdentML reader was written against the specification "
                   "for mzIdentML version 1.1.0; this file is version %s, so there may "
                   "be discrepancies in the results." % self.root.get("version"))

        self.pfx = self.root.tag[:-9] # Take out "mzIdentML"        

        #print "Indexing file..." # Really this could all be done on an as-needed basis.
        self.parentMap = dict(sum([[(c.get("id"),p.get("id")) for c in p if c.get("id") and p.get("id")]
                                   for p in ch(self.tree.getiterator(self.pfx + "ProteinAmbiguityGroup"),
                                               self.tree.getiterator(self.pfx + "SpectrumIdentificationResult"))], []))

        proteinElements = self.root.getiterator(self.pfx + "ProteinDetectionHypothesis")
        #self.proteinLookup = {prot.get("id"):prot for prot in proteinElements}
        self.proteinLookup = dict([(prot.get("id"), prot) for prot in proteinElements])

        spectrumElements = self.root.getiterator(self.pfx + "SpectrumIdentificationResult")
        #self.spectrumLookup = {spec.get("id"):spec for spec in spectrumElements}
        self.spectrumLookup = dict([(spec.get("id"), spec) for spec in spectrumElements])

        pepIdElements = self.root.getiterator(self.pfx + "SpectrumIdentificationItem")
        #self.pepIdLookup = {pepid.get("id"):pepid for pepid in pepIdElements}
        self.pepIdLookup = dict([(pepid.get("id"), pepid) for pepid in pepIdElements])

        evidenceElements = self.root.getiterator(self.pfx + "PeptideEvidence")
        #self.evidenceLookup = {evi.get("id"):evi for evi in evidenceElements}
        self.evidenceLookup = dict([(evi.get("id"), evi) for evi in evidenceElements])

        dbElements = self.root.getiterator(self.pfx + "DBSequence")
        #self.dbLookup = {db.get("id"):db for db in dbElements}
        self.dbLookup = dict([(db.get("id"), db) for db in dbElements])

        peptideElements = self.root.getiterator(self.pfx + "Peptide")
        #self.peptideLookup = {pep.get("id"):pep for pep in peptideElements}
        self.peptideLookup = dict([(pep.get("id"), pep) for pep in peptideElements])

        fileElements = self.root.getiterator(self.pfx + "SpectraData")
        #self.fileLookup = {data.get("id"):data for data in fileElements}
        self.fileLookup = dict([(data.get("id"), data) for data in fileElements])
        #print "Indexing complete."

        self.dataFileScans = {}
        self.filePointers = {}
示例#5
0
def handle_photo(photo_path, method, frame_count=None, full_path=False):
    paths = ['{}/{}'.format(photo_path, file_path) for file_path in os.listdir(photo_path)]
    files = ['{}/{}'.format(p, f) for p in ifil(os.path.isdir, paths) for f in os.listdir(p)]
    files = list(ch(files, list(ifil(os.path.isfile, paths))))
    finalimage = None
    result_name = '{count}'.format(count=frame_count) if frame_count else ''

    for i, file_path in enumerate(files):
        what = imghdr.what(file_path)
        if what in [None, 'gif']:
            files.pop(i)
            continue
        currentimage = Image.open(file_path)
        if what in ['png']:
            try:
                bg = Image.new("RGB", currentimage.size, (255, 255, 255))
                bg.paste(currentimage, mask=currentimage)
                currentimage = bg
            except ValueError:
                pass
        if finalimage is None:
            finalimage = currentimage
            continue
        if frame_count and i != 1 and i % frame_count:
            continue
        if method == 'both':
            lighter = handle_photo(photo_path, 'lighter', frame_count, full_path=True)
            darker = handle_photo(photo_path, 'darker', frame_count, full_path=True)
            l_img = Image.open(lighter)
            d_img = Image.open(darker)
            res = ImageChops.blend(l_img, d_img, 0.5)
            path, name = save_result(res, photo_path, result_name, method)
            return name
        if method == 'diff':
            if i < 1:
                continue
            prev = Image.open(files[i - 1])
            diff = ImageChops.difference(currentimage, prev)
            finalimage = ImageChops.add(finalimage, diff)
        if method == 'lighter':
            finalimage = ImageChops.lighter(finalimage, currentimage)
        if method == 'darker':
            finalimage = ImageChops.darker(finalimage, currentimage)
    path, name = save_result(finalimage, photo_path, result_name, method)
    return path if full_path else name