def writeViablesPointsHDF5(filename, dt, p0, l0, dp, dl, np, nl): with open(filename+".txt", 'w') as f: f.write("Pas de temps : {:f}\n".format(dt)) firstCol,tabp = computeTrajectoryP(dt, p0, l0, dp, dl, np, nl, umax, nmax, pmax, lmax, b, r, q, m) iLmin=ceil((lmin-l0)/dl) iLmax=floor((lmax-l0)/dl) iPmax=floor(pmax/dp) # preparing regulargridkernel grid=numpy.array([ i>=iLmin and i<=iLmax and j<=iPmax and (i<firstCol or (i<firstCol+len(tabp) and p0+j*dp<=tabp[i-firstCol])) for i in numpy.arange(nl) for j in numpy.arange(np) ]).reshape(np,nl) rgk = RegularGridKernel([p0,l0],[dp,dl]) rgk.setGrid(grid) # preparing gridbarkernel bars = [] for i in range(int(iLmin),int(iLmax+1)): viablesPoints=numpy.argwhere(grid[i]) if len(viablesPoints)>0: bars.append([i,viablesPoints[0][0],viablesPoints[-1][0]]) bgk = BarGridKernel([p0,l0],None, None, data=bars) # writing raw points for i in range(nl): for j in range(np): if grid[i,j]: f.write("{:f} {:f}\n".format(l0+i*dl,p0+j*dp)) HDF5Manager.writeKernel(rgk, filename+".h5", compression="gzip", compression_opts=9) writeHDF5_coords(rgk, filename+"_coords.h5", compression="gzip", compression_opts=9)
def initFromHDF5(cls, metadata, dataAttributes, data): ''' Create an object of class BarGridKernel from attributes and data loaded from an HDF5 file. This method is intended to be used by the method hdf5common.readKernel ''' return cls(dataAttributes['origin'], dataAttributes['steps'], data=data, metadata=metadata) @overrides def getData(self): return self.grid def setGrid(self, grid): self.dimensionsExtents = grid.shape self.grid = grid def set(self, coords, value): self.grid.put([coords], value) def get(self, coords): return self.grid[coords] @overrides def isInSet(self, point): # TODO raise NotImplementedError if __name__ == "__main__": from hdf5common import HDF5Manager grid = RegularGridKernel([0,0,0], [1,1,1], [10,10,10]) grid.set([3,1,0], True) HDF5Manager.writeKernel(grid, 'test.h5')
return cls(dataAttributes['origin'], dataAttributes['steps'], data=data, metadata=metadata) @overrides def getData(self): return self.grid def setGrid(self, grid): self.dimensionsExtents = grid.shape self.grid = grid def set(self, coords, value): self.grid.put([coords], value) def get(self, coords): return self.grid[coords] @overrides def isInSet(self, point): # TODO raise NotImplementedError if __name__ == "__main__": from hdf5common import HDF5Manager grid = RegularGridKernel([0, 0, 0], [1, 1, 1], [10, 10, 10]) grid.set([3, 1, 0], True) HDF5Manager.writeKernel(grid, 'test.h5')