def _readDataGeneral(self,stepSlice=0,shotSlice=None,fileSlice=0,fieldName=None): fileSlice = tools.iterfy(fileSlice) stepSlice = tools.iterfy(stepSlice) #self.readTime(stepSlice,shotSlice,fileSlice) #if not self._existsInSelf("time"): #timeStampObj = memdata(self,"timestamp",fileSlice[0]) #self._addToSelf("time",timeStampObj) outS = [] # NB: Here is an issue, doesn't make sense like it is right now... for stepNum in stepSlice: # check if memory chached exists and the already read values contains what we need.. #print "TODO: add slice1 in slice2 ..., the current one does not work with None ..." #print "r1=range(5,100); r2=range(10,20); [idx for (idx,x) in zip(range(len(r1)),r1) if x in r2]" fileNum,FstepNum = self._getFileStep(stepNum) addr = address(fileNum,stepNum,"shotSlice") if (not self._existsInSelf(addr)) or (len(tools.iterDiff( self._getFromSelf(addr), shotSlice) )==0): path = self._paths["data"][FstepNum][0] path = getPath(path) #de=bug if (shotSlice is None): data = [h5r(self._h5s[fileNum],path)[...] % tt for tt in self.time[stepNum]] else: if isinstance(shotSlice,np.ndarray) and shotSlice.dtype is np.dtype(int): data = np.asarray([h5r(self._h5s[fileNum],path % self.time[stepNum][ts])[...] for ts in shotSlice]) #tshotSlice = np.zeros([data.len()],dtype=bool) #tshotSlice[shotSlice]=True #shotSlice=tshotSlice #data = data[shotSlice] else: data = self._getFromSelf(address(fileNum,stepNum,"_data")) # store is asked to use memory cache if (self._useMemoryCache): # save in .fileNum.stepNum._data self._addToSelf(address(fileNum,stepNum,"_data"),data) self._addToSelf(address(fileNum,stepNum,"shotSlice"),shotSlice) if (isinstance(data.dtype.names,tuple)): for fieldname in data.dtype.names: self._addToSelf(address(fileNum,stepNum,fieldname),data[fieldname]) if ( not (fieldname in self.__dict__) ): timeStampObj = memdata(self,"timestamp",fileNum) dataObj = memdata(self,fieldname,fileNum,timeStampObj) self._addToSelf(fieldname,dataObj) #else: #timeStampObj = memdata(self,"timestamp",fileNum) #dataObj = memdata(self,"_data",fileNum,timeStampObj) #tools.addToObj(self,"_data",dataObj) outS.append(data) return outS
def _readEpicsAllData(self,datapath,timepath): stepSlice = range(self.Nsteps) stepSlice = tools.iterfy(stepSlice) outD = [] outT = [] for stepNum in stepSlice: fileNum,FstepNum = self._getFileStep(stepNum) cpath = datapath % FstepNum # really beautiful, same for python 3 ? data = h5r(self._h5s[fileNum],cpath) outD.append(data['value']) time = data['stamp'] time.dtype.names = ('seconds','nanoseconds') outT.append(time) return [outD,outT]
def _readTime(self,path,stepSlice=None,shotSlice=None): if stepSlice is None: stepSlice = range(self.Nsteps) stepSlice = tools.iterfy(stepSlice) times = [] for stepNum in stepSlice: fileNum,FstepNum = self._getFileStep(stepNum) tpath = path time = h5r(self._h5s[fileNum],tpath) try: if (shotSlice is None): time = time[...] else: time = time[shotSlice] except: time = np.array([]) #raise NotImplementedError('Use the source, luke!') times.append(time) return times
def _readPointDataGeneral(self,path,field=None,stepSlice=None,shotSlice=None): if stepSlice is None: stepSlice = range(self.Nsteps) stepSlice = tools.iterfy(stepSlice) #self.readTime(stepSlice,shotSlice,fileSlice) #if not self._existsInSelf("time"): #timeStampObj = memdata(self,"timestamp",fileSlice[0]) ##self._addToSelf("time",timeStampObj) outS = [] for stepNum in stepSlice: fileNum,FstepNum = self._getFileStep(stepNum) cpath = path cpath = getPath(cpath) data = h5r(self._h5s[fileNum],cpath) try: if (shotSlice is None): data = data[...] else: data = data[shotSlice] except: data = np.array([]) outS.append(data) # find structure with something in outSind = 0 for toutS in outS: if len(toutS)>0: break outSind+=1 if outS[outSind].dtype.names: if not field is None: index = '' while not field in outS[outSind].dtype.names: index = field[-1] + index field = field[:-1] index = int(index) fields = [field] else: fields = outS[outSind].dtype.names index = None pret = [[dd[tfield] if len(dd)>0 else np.array([]) for dd in outS ] for tfield in fields] ret = [] retfields = [] for tret,tfield in zip(pret,fields): if tret[0].ndim==2: noofvecs = np.shape(outS[0][tfield])[1] if not index is None: indices = [index] else: indices = range(noofvecs) for tindex in indices: strfmt = '%0' + '%dd' %(1+np.floor(np.log10(noofvecs))) tname = tfield + strfmt %(tindex) ret.append([sd[:,tindex] if np.ndim(sd)==2 else np.asarray([]) for sd in tret ]) retfields.append(tname) else: ret.append(tret) retfields.append(tfield) else: ret = [outS] retfields = ['data'] return ret,retfields