Ejemplo n.º 1
0
 def __init__(self,filename,mode="r+",cNames=None,shape=None, Fs = 1000.0):
     assert mode in ["r","r+","w+"], "Unsupported mode"
     self._fn = filename
     
     try:
         self.f = open(self._fn, mode)
     except:
         raise IOError, "Die angegebene Datei konnte nicht geöffnet werden!"
     
     if mode in ["r","r+"]:
         s = self.f.read(struct.calcsize(fmtF32header))
         (self.header["formatName"],self.header["formatVer"],self.header["sbChinfo"],self.header["sbData"],self.header["numChannels"],self.header["numDatapoints"],self.header["samplRate"],self.header["tStart"], self.header["tEnd"], self.header["reservedString"], self.header["datatype"], self.header["samplesize"], self.header["minsample"], self.header["maxsample"],self.header["reserved2"]) = struct.unpack(fmtF32header,s)
         
         self.numChannels=self.header["numChannels"]
         #print self.numChannels
         if self.numChannels > 500 or self.numChannels < 1:
             raise Exception, "The chosen file is either in an unrecognized format or corrupt!"
         if self.header["sbData"] != (struct.calcsize(fmtF32header)+self.numChannels*struct.calcsize(fmtF32channelinfo)):
             #print "Der Wert für das Anfangsbyte der Daten war falsch gesetzt. Korrigiere..."
             self.header["sbData"] = (struct.calcsize(fmtF32header)+self.numChannels*struct.calcsize(fmtF32channelinfo))
         self.fmtSample = "= %if" % self.numChannels
         self._channel_names = []
         self._channel_units = []
         for i in range(0,self.numChannels):
             s = self.f.read(struct.calcsize(fmtF32channelinfo))
             (chName, chUnit, reserved3) = struct.unpack(fmtF32channelinfo,s)
             self._channel_names.append(chName)
             self._channel_units.append(chUnit)
         self._shape = (self.header["numDatapoints"],self.header["numChannels"])
         #FIXED: closinf self.f before opening memmap.
         self.f.close()
         
         shape_from_header = (self.header["numDatapoints"], self.header["numChannels"])
         MemoryMappedBinaryDataFile.__init__(self, filename, mode, shape_from_header, 
                         data_offset = self.header["sbData"], 
                         dtype=np.float32, Fs = self.header["samplRate"],
                         channel_names=cNames)
     elif mode=="w+":
         assert shape != None, "Shape must be given."
         assert len(shape) == 2, "Only 2d is possible"
         if cNames != None:
             assert len(cNames)>0, "List of channel names must be longer than 0!"
             assert shape[1] == len(cNames) 
             self._channel_names = [str(x) for x in cNames]  
         self.header["sbData"] = int(self.header["sbChinfo"]+shape[1]*struct.calcsize(fmtF32channelinfo))   
         self.header["numChannels"] = shape[1]
         self.header["numDatapoints"] = shape[0]
         self.header["samplRate"] = float(Fs)
         self.f.close()            
         MemoryMappedBinaryDataFile.__init__(self, filename, mode, shape, 
                         data_offset = self.header["sbData"], 
                         dtype=np.float32, Fs = Fs,
                         channel_names=cNames)
         del self._mm
         self._mm = None
         self.f = open(self._fn, "r+")
         self.writeHeader()
         self.f.close()
         self._reopen_memmap()
Ejemplo n.º 2
0
 def __init__(self,filename,mode="r+",cNames=None,shape=None, Fs = 1000.0, numChannels=122):
     """Documentation needed"""
     fileSize = os.stat(filename).st_size
     numDatapoints = int(fileSize/numChannels/4)
     MemoryMappedBinaryDataFile.__init__(self, filename, mode, 
                 shape = (numDatapoints, numChannels),
                 data_offset=0,
                 dtype=">f", Fs = Fs, channel_names=cNames)
Ejemplo n.º 3
0
 def __init__(self,
              filename,
              mode="r+",
              cNames=None,
              shape=None,
              Fs=1000.0,
              numChannels=122):
     """Documentation needed"""
     fileSize = os.stat(filename).st_size
     numDatapoints = int(fileSize / numChannels / 4)
     MemoryMappedBinaryDataFile.__init__(self,
                                         filename,
                                         mode,
                                         shape=(numDatapoints, numChannels),
                                         data_offset=0,
                                         dtype=">f",
                                         Fs=Fs,
                                         channel_names=cNames)