コード例 #1
0
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)
コード例 #2
0
def testRead():
    dataway = '../samples/lake/2D.txt'
    metadataway = '../samples/lake/2D_metadata.txt'
    h5way = '2D.h5'
    hm = HDF5Manager([BarGridKernel])

    grid = FileFormatLoader.PspModifiedLoader().read(dataway)
    myre = re.compile('^#(.*):(.*)$')
    with open(metadataway) as f:
        for line in f:
            if line.startswith('#'):
                k, v = myre.match(line).groups()
                grid.metadata[k.strip()] = v.strip()
    grid.metadata[METADATA.statedimension] = int(
        grid.metadata[METADATA.statedimension])
    grid.metadata['results.submissiondate'] = time.strftime(
        '%Y-%m-%d %H:%M', time.localtime())
    print grid.permutation
    print grid.originCoords
    hm.writeKernel(grid, h5way)
    grid = []
    #    grid2 = hm.readKernel(h5way)
    #    print(grid2.metadata)
    #    print(metadata.category)
    #    print(grid2.metadata[METADATA.category])
    #    print(grid2.metadata[METADATA.results_submissiondate])
    #    print(grid2.metadata[METADATA.results_formatparametervalues])
    #    print grid2.permutation
    #    print grid2.originCoords
    #    print(grid2.kernelMinPoint)
    #    print(grid2.kernelMaxPoint)
    return grid
コード例 #3
0
def testReadKdTree():
    dataway = '../samples/3D_languesIsa_dil0.txt'
    metadataway = '../samples/3D_languesIsa_dil0_metadata.txt'
    h5way = '3D_languesIsa_dil0.h5'
    hm = HDF5Manager([KdTree])
    metadata = {}
    myre = re.compile('^#(.*):(.*)$')
    with open(metadataway) as f:
        for line in f:
            if line.startswith('#'):
                k, v = myre.match(line).groups()
                metadata[k.strip()] = v.strip()
    metadata[METADATA.statedimension] = int(metadata[METADATA.statedimension])
    metadata['results.submissiondate'] = time.strftime('%Y-%m-%d %H:%M',
                                                       time.localtime())
    #    return metadata

    explorationdomain = metadata[
        METADATA.results_softwareparametervalues].split("/")[0].split(",")
    origin = explorationdomain[:len(explorationdomain) / 2]
    opposite = explorationdomain[len(explorationdomain) / 2:]
    k = KdTree.readViabilitree(dataway, metadata, origin, opposite)
    print(k.cells[0])
    print("Kdtree loaded with %d cells" % len(k.cells))
    hm.writeKernel(k, h5way)
    k2 = hm.readKernel(h5way)
    return k2
コード例 #4
0
def CompareProcedure():
    with HDF5Reader('2Dlake_light.h5') as f:
        # TODO nothing is done with these metadata
        metadata = f.readMetadata()
        # reading the data attributes for determining the format
        dataAttributes = f.readDataAttributes()
        data = f.readData()
    print dataAttributes['intervals']
    print dataAttributes[METADATA.resultformat_title]

    bargridoh = BarGridKernel.initFromHDF5(metadata, dataAttributes, data)

    hm = HDF5Manager([BarGridKernel])
    bargrid = hm.readKernel('2Dlake_light.h5')
    bargrid2 = FileFormatLoader.PspModifiedLoader().read(
        '../samples/2D_light.txt')

    distancegriddimensions = [31, 31]  #[301,301]
    distancegridintervals = map(lambda e: e - 1, distancegriddimensions)

    resizebargrid = bargrid.toBarGridKernel(bargrid.originCoords,
                                            bargrid.oppositeCoords,
                                            distancegridintervals)
    resizebargrid2 = bargrid2.toBarGridKernel(bargrid2.originCoords,
                                              bargrid2.oppositeCoords,
                                              distancegridintervals)

    print(bargrid.bars[0])
    print(bargrid2.bars[0])
    print(bargrid.bars[10000])
    print(bargrid2.bars[10000])
    for i in range(len(bargrid.bars)):
        if bargrid.bars[i][2] != bargrid2.bars[i][2]:
            print bargrid.bars[i]
            print bargrid2.bars[i]
            print "merde"

    print(bargrid.originCoords)
    print(bargridoh.originCoords)
    print(bargrid.oppositeCoords)
    print(bargridoh.oppositeCoords)
    print(bargrid.intervalNumberperaxis)
    print(bargridoh.intervalNumberperaxis)
    print(bargrid.permutation)
    print(bargridoh.permutation)

    print(resizebargrid.bars[0])
    print(resizebargrid2.bars[0])
    print(resizebargrid.bars[30])
    print(resizebargrid2.bars[30])
    for i in range(len(resizebargrid.bars)):
        if resizebargrid.bars[i][2] != resizebargrid2.bars[i][2]:
            print resizebargrid.bars[i]
            print resizebargrid2.bars[i]
            print "merde"
    print "youpi"
コード例 #5
0
                        break
                    else:
                        next_point[i] = start_int[i]
                bgk.addBar(next_point, start_int[-1], end_int[-1])
        return bgk


if __name__ == "__main__":
    data = []
    minbounds = []
    maxbounds = []
    neworigin = []
    newopposite = []

    resizebargrids = []
    hm = HDF5Manager([BarGridKernel])
    bargrid = hm.readKernel('2Dlake_light.h5')
    data1 = bargrid.getDataToPlot()

    intervalSizes = np.array(bargrid.getIntervalSizes())
    if (len(minbounds) > 0):
        minbounds = [min(minbounds[i],list(np.array(bargrid.getMinBounds())-intervalSizes/2)[i]) for i in range(len(minbounds))]
        maxbounds = [max(maxbounds[i],list(np.array(bargrid.getMaxBounds())+intervalSizes/2)[i]) for i in range(len(maxbounds))]

    else :
        minbounds = list(np.array(bargrid.getMinBounds())-intervalSizes/2)
	maxbounds = list(np.array(bargrid.getMaxBounds())+intervalSizes/2)
    '''
    #To delete to show the original bargrid
    distancegriddimensions = [10,10]#[int(ppa),int(ppa)] #[301,301]
    distancegridintervals = map(lambda e: e-1, distancegriddimensions)
コード例 #6
0
from django.core.management.base import BaseCommand
from sharekernel.models import *
from django.core.files import File
from FileFormatLoader import Loader
import re
import METADATA
from django.utils import timezone
from hdf5common import HDF5Manager
import tempfile
from BarGridKernel import BarGridKernel
from django.utils.text import slugify
from sharekernel.views import findandsaveobject
from django.contrib.auth.models import User
from init_database import clear_database, create_defaultusers, create_defaultformats

hdf5manager = HDF5Manager([BarGridKernel])


def addKernel(kernel, user):
    resultformat_md = {
        k: v
        for k, v in kernel.metadata.iteritems() if k.startswith("resultformat")
    }
    resultformat = findandsaveobject(
        ResultFormat,
        metadata={
            METADATA.resultformat_title:
            resultformat_md[METADATA.resultformat_title]
        },
        fields={'submitter': user},
        add_metadata=resultformat_md)
コード例 #7
0
  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')
コード例 #8
0
        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')
コード例 #9
0
 def __init__(self, strategies=[BarGridKernel, KdTree]):
     self.hdf5manager = HDF5Manager(strategies)