Exemplo n.º 1
0
    def __init__(self,fName):
        aPath=path.abspath(fName)
        pSep=aPath.split(path.sep)
        self.name=path.splitext(pSep[-1])[0]
        self.time=float(pSep[-2])
        self.function=pSep[-3]
        self.cloudName=pSep[-4]

        f=CleanCharactersFile(fName,charsToRemove="()")
        r=BytesIO(b(f.content))
        hLine=str(r.readline().strip()).replace("'","")

        # missing in some libraries
        if hLine.find("cellI tetFaceI")>0:
            hLine=hLine.replace("cellI tetFaceI","cellI faceI stepFraction tetFaceI")

        header=[str(n) for n in hLine.split()[1:]]
        spec=[]

        for name in header:
            if name in ["currentProc","cellI","faceI","tetFaceI","tetPtI","origProc","origId","typeId"]:
                spec.append((name,"i8"))
            elif name in ["active"]:
                spec.append((name,np.bool_))
            else:
                spec.append((str(name),"f8"))

        self.data=np.recfromtxt(r,dtype=spec)
Exemplo n.º 2
0
 def toNumpy(self, regexp, dtypes):
     import numpy as np
     try:
         return np.fromregex(StringIO(self.data), regexp, dtypes)
     except TypeError:
         from PyFoam.ThirdParty.six import BytesIO, b
         return np.fromregex(BytesIO(b(self.data)), regexp, dtypes)
Exemplo n.º 3
0
 def toNumpy(self, regexp, dtypes):
     """Assume that the unparsed data contains line-wise data and transform it to a numpy-array.
     @param regexp: regular expression where the groups correspond to the dtypes,
     @param dtypes: list with dtypes"""
     import numpy as np
     try:
         return np.fromregex(StringIO(self.data), regexp, dtypes)
     except TypeError:
         from PyFoam.ThirdParty.six import BytesIO, b
         return np.fromregex(BytesIO(b(self.data)), regexp, dtypes)
Exemplo n.º 4
0
 def testSpreadsheetReadFileHandleTest(self):
     sp = SpreadsheetData(txtName=BytesIO(filecontent))
     self.assertEqual(len(sp.names()), 4)