コード例 #1
0
ファイル: parserDELWAQ.py プロジェクト: ogoe/OpenTelemac
    def __init__(self, fileName):

        # ~~> Read the steering file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        if not path.exists(fileName):
            print '... Could not file your DELWAQ file: ', fileName
            sys.exit(1)
        self.dwqList = self.parseDWQ(getFileContent(fileName))

        # ~~> Read the geometry file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        fle = self.dwqList['grid-indices-file']
        if not path.exists(fle):
            print '...Could not find the GEO file: ', fle
            sys.exit(1)
        self.geo = SELAFIN(fle)
        self.NPOIN3 = int(self.dwqList['grid-cells-first-direction'])
        if self.NPOIN3 != self.geo.NPOIN3:
            print '...In consistency in numbers with GEO file: ', self.NPOIN3, self.geo.NPOIN3
            sys.exit(1)
        self.NSEG3 = int(self.dwqList['grid-cells-second-direction'])

        # ~~> Read the CONLIM file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        fle = self.dwqList['grid-coordinates-file']
        if not path.exists(fle):
            print '...Could not find the CONLIM file: ', fle
            sys.exit(1)
        self.conlim = CONLIM(fle)

        # ~~> Time records ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        self.HYDRO0T = int(self.dwqList['hydrodynamic-start-time'])
        self.HYDROAT = int(self.dwqList['hydrodynamic-stop-time'])
        self.HYDRODT = int(self.dwqList['hydrodynamic-timestep'])
        self.HYDROIT = 1 + (self.HYDROAT - self.HYDRO0T) / self.HYDRODT
        self.HYDRO00 = 0
        self.tfrom = self.HYDRO0T
        self.tstop = self.HYDROAT
コード例 #2
0
def read_selafin():
    #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    # Openning the selafin file
    # This gives the name of the variables, and their index number
    #
    slf = SELAFIN(input_file)
    # Getting coordinates
    x = slf.MESHX
    y = slf.MESHY
    # Getting Variables
    print 'Variables in ' + input_file + ' are:'
    for i in range(len(slf.VARNAMES)):
        print '    ', i, '-->', slf.VARNAMES[i]

    #for i,name in enumerate(slf.VARNAMES):
    #	print '    ',i, ' - ',name
    # Get IKLE for mesh regularization
    ikle = np.array(slf.IKLE2)

    # total number of variables in the input file
    numvars = len(slf.VARNAMES)

    # total number of time records in the file
    nrecs = len(slf.tags["times"])

    # an array of size nrecs with values of time steps in the input file
    times = slf.tags["times"]
    print "number of records in input file : " + str(nrecs)
    #print "Available time steps to choose from: "
    #for i in range(len(times)):
    #	print str(times[i])

    #
    return slf, x, y, ikle, numvars, nrecs, times
コード例 #3
0
    def copyCommonData(self):

        SLFn = SELAFIN('')
        #   Meta data
        SLFn.TITLE = self.slf.TITLE
        SLFn.file = self.slf.file
        SLFn.IPARAM = self.slf.IPARAM
        #   Time
        SLFn.DATETIME = self.slf.DATETIME
        SLFn.tags = self.slf.tags
        #   Variables
        SLFn.NBV1 = self.slf.NBV1
        SLFn.VARNAMES = self.slf.VARNAMES
        SLFn.VARUNITS = self.slf.VARUNITS
        SLFn.NBV2 = self.slf.NBV2
        SLFn.CLDNAMES = self.slf.CLDNAMES
        SLFn.CLDUNITS = self.slf.CLDUNITS
        SLFn.NVAR = self.slf.NVAR
        SLFn.VARINDEX = range(self.slf.NVAR)
        #   Unchanged numbers
        SLFn.NPLAN = self.slf.NPLAN
        SLFn.NDP2 = self.slf.NDP2
        SLFn.NDP3 = self.slf.NDP3

        return SLFn
コード例 #4
0
    def add(self, typl, what):
        Caster.add(self, typl, what)

        # ~~> output from for 3D file
        if self.obtype == 'slf':
            if not self.oudata: self.oudata = SELAFIN()
        # ~~> unkonwn
        else:  # TODO: raise exception
            print '... do not know how to write to this format: ' + self.obtype
            sys.exit(1)
コード例 #5
0
 def __init__(self, meshfile, **kwargs):
     '''Reading a Telemac mesh and converting the format and reprojecting etc'''
     self.meshfile = meshfile
     self.useropts = kwargs
     if self.fileExists():
         self.slf = SELAFIN(meshfile)
         self.xmesh = self.slf.MESHX
         self.ymesh = self.slf.MESHY
         self.elements = self.slf.IKLE2
     if "bcfile" in self.useropts:
         self.bcfile = kwargs["bcfile"]
         print(self.bcfile)
コード例 #6
0
   def draw(self,type,what,fig):
      
      if 'sortie' in type.lower():
         # ~~> Load data
         sortie = getFileContent(what['file'])
         # ~~> Extract data
         data = getValueHistorySortie(sortie,what['vars'])
         # ~~> Deco
         # ~~> Draw data
         drawHistoryLines(plt,data,deco)

      elif 'SELAFIN' in type.upper():
         # ~~> Load data
         slf = SELAFIN(what['file'])

         if what['type'] == 'history':
            # ~~> Extract data
            vars = subsetVariablesSLF(what["vars"],slf.VARNAMES)
            support = xyLocateMeshSLF(what["extract"],slf.NELEM3,slf.IKLE,slf.MESHX,slf.MESHY)
            data = getValueHistorySLF(slf.file,slf.tags,what['time'],support,slf.TITLE,slf.NVAR,slf.NPOIN3,vars)
            # ~~> Deco
            if what.has_key('roi'):
               if what['roi'] != []: deco['roi'] = what['roi']
            # ~~> Draw data
            drawHistoryLines(plt,data,deco)
            
         elif what['type'] == 'v-section':
            # ~~> Extract data
            vars = subsetVariablesSLF(what["vars"],slf.VARNAMES)
            support = crossLocateMeshSLF(what["extract"],slf.NELEM3,slf.IKLE,slf.MESHX,slf.MESHY)
            data = getValuePolylineSLF(slf.file,slf.tags,what['time'],support,slf.TITLE,slf.NVAR,slf.NPOIN3,vars)
            # ~~> Deco
            deco['roi'] = [ [np.min(slf.MESHX),np.min(slf.MESHY)], [np.max(slf.MESHX),np.max(slf.MESHY)] ]
            if what.has_key('roi'):
               if what['roi'] != []: deco['roi'] = what['roi']
            # ~~> Draw data
            drawPolylineLines(plt,data,deco)

         else: print '... do not know how to draw this type: ' + what['type']

      else:
         print '... do not know how to draw this format: ' + type
コード例 #7
0
    def __init__(self,
                 SLFfileName,
                 CLMfileName,
                 SEQfileName='',
                 splitCONLIM=False,
                 DOMfileRoot=''):

        print '\n... Acquiring global files'
        # ~~> Acquire global CONLIM file
        print '    +> CONLIM file'
        self.clm = CONLIM(CLMfileName)
        self.isCONLIM = splitCONLIM

        # ~~> Acquire global SELAFIN file
        print '    +> SELAFIN file'
        self.slf = SELAFIN(SLFfileName)

        # ~~> Acquire global SELAFIN file
        if SEQfileName != '':
            print '    +> SEQUENCE file'
            self.NPARTS, self.NSPLIT, self.KSPLIT = self.getSplitFromSequence(
                np.array(getFileContent(SEQfileName), dtype='<i4'))
        else:
            self.NPARTS, self.NSPLIT, self.KSPLIT = self.getSplitFromNodeValues(
                'PROCESSORS')

        print '\n... Split by elements in ', self.NPARTS, ' parts\n'

        # ~~> Clean inconsistencies in boundary segments
        self.IPOBO, self.NSPLIT, self.KSPLIT = self.setSplitForBoundaries(
            self.NSPLIT, self.clm.KFRGL, self.KSPLIT)

        self.PINTER,self.PNHALO,self.PNODDS = \
           self.setSplitForElements( self.IPOBO,self.NPARTS,self.NSPLIT,self.KSPLIT )
        self.slfn = self.copyCommonData()

        # ~~> Optional output file names
        self.isDOMAIN = DOMfileRoot
コード例 #8
0
   def draw(self,type,what,fig):

      # ~~> Load data
      slf = SELAFIN(what['file'])

      # /!\ WACLEO: Temporary fix because TOMAWAC's IOs names are not yet standard TELEMAC
      if 'WACLEO' in type.upper() or \
         'SELAFIN' in type.upper():

         # ~~> Extract data
         elements = None; edges = []; edgexy = []

         # ~~> Deco
         xmin = np.min(slf.MESHX); xmax = np.max(slf.MESHX)
         ymin = np.min(slf.MESHY); ymax = np.max(slf.MESHY)
         if what.has_key('roi'):
            if what['roi'] != []:
               xmin = min(what['roi'][0][0],what['roi'][1][0])
               xmax = max(what['roi'][0][0],what['roi'][1][0])
               ymin = min(what['roi'][0][1],what['roi'][1][1])
               ymax = max(what['roi'][0][1],what['roi'][1][1])
         deco['roi'] = [[xmin,ymin],[xmax,ymax]]

         for var in what["vars"].split(';'):
            v,t = var.split(':')

            if "mesh" in t:
               # ~~> Extract mesh connectivity
               if elements == None: elements = np.dstack((slf.MESHX[slf.IKLE],slf.MESHY[slf.IKLE]))
               # ~~> Draw (works with triangles and quads)
               drawMesh2DElements(plt,elements,deco)

            elif "wire" in t:
               # ~~> Extract unique edges and outline /!\ assumes all same clowise orientation
               if edges == []:
                  for e in slf.IKLE:
                     for n in range(slf.NDP):
                        if (e[n],e[(n+1)%slf.NDP]) not in edges: edges.append((e[(n+1)%slf.NDP],e[n]))
                  # ~~> Assemble wires
                  for e in edges:
                     edgexy.append(( (slf.MESHX[e[0]],slf.MESHY[e[0]]) , (slf.MESHX[e[1]],slf.MESHY[e[1]]) ))
               # ~~> Draw (works with triangles and quads)
               drawMeshLines(plt,edgexy,deco)

            else:
               # ~~> Extract variable data
               VARSORS = []
               frame = 0
               if what.has_key('time'):
                  frame = int(what['time'][0])
                  if frame < 0: frame = max( 0, len(slf.tags['cores']) + frame )
               slf.file.seek(slf.tags['cores'][frame])
               slf.file.read(4+4+4)
               for ivar in range(slf.NVAR):
                  slf.file.read(4)
                  if v.upper() in slf.VARNAMES[ivar].strip():
                     VARSORS.append(np.asarray(unpack('>'+str(slf.NPOIN3)+'f',slf.file.read(4*slf.NPOIN3))))
                  else:
                     slf.file.read(4*slf.NPOIN3)
                  slf.file.read(4)
               # ~~> Multi-variables calculations
               MESHX = np.array(slf.MESHX); MESHY = np.array(slf.MESHY)
               if len(VARSORS) > 1:
                  if "arrow" in t or "angle" in t:
                     if what['extract'] != []:
                        dx = (xmax-xmin)/what['extract'][0][0]
                        dy = (ymax-ymin)/what['extract'][0][1]
                        grid = np.meshgrid(np.arange(xmin, xmax+dx, dx),np.arange(ymin, ymax+dy, dy))
                        MESHX = np.concatenate(grid[0]); MESHY = np.concatenate(grid[1])
                        le,ln,bn = xyLocateMeshSLF(np.dstack((MESHX,MESHY))[0],slf.NELEM3,slf.IKLE,slf.MESHX,slf.MESHY)
                        VARSOR = [np.zeros(len(le),np.float32),np.zeros(len(le),np.float32)]
                        for xy in range(len(bn)):
                           if le[xy] >= 0:
                              VARSOR[0][xy] = bn[xy][0]*VARSORS[0][ln[xy][0]] + bn[xy][1]*VARSORS[0][ln[xy][1]] + bn[xy][2]*VARSORS[0][ln[xy][2]]
                              VARSOR[1][xy] = bn[xy][0]*VARSORS[1][ln[xy][0]] + bn[xy][1]*VARSORS[1][ln[xy][1]] + bn[xy][2]*VARSORS[1][ln[xy][2]]
                  else:
                     t = "map"
                     VARSOR = np.sqrt(np.sum(np.power(np.dstack(VARSORS[0:2])[0],2),axis=1))
               else:
                  VARSOR = VARSORS[0]
               # ~~> Element types
               if slf.NDP == 3: IKLE = np.array(slf.IKLE)
               elif slf.NDP == 4:
                  # ~~> split each quad into triangles
                  IKLE = np.delete(np.concatenate((slf.IKLE,np.roll(slf.IKLE,2,axis=1))),np.s_[3::],axis=1)
               # ~~> Draw (multiple options possible)
               if "map" in t: drawColouredTriMaps(plt,(slf.MESHX,slf.MESHY,IKLE,VARSOR),deco)
               if "label" in t: drawLabeledTriContours(plt,(slf.MESHX,slf.MESHY,slf.IKLE,VARSOR),deco)
               if "arrow" in t: drawColouredTriVects(plt,(MESHX,MESHY,VARSOR,False),deco)
               if "angle" in t: drawColouredTriVects(plt,(MESHX,MESHY,VARSOR,True),deco)

      else:
         print '... do not know how to draw this format: ' + type

      slf.file.close()

      return
コード例 #9
0
ファイル: convertHYCOM.py プロジェクト: ogoe/OpenTelemac
    def getHeaderHYCOM(self, bounds):

        # ~~> inheritence
        self.slf3d = SELAFIN('')  # slf3d
        self.slf2d = SELAFIN('')  # slf2d surface

        print '     +> Set SELAFIN Variables'
        self.slf3d.TITLE = ''
        self.slf3d.NBV1 = 6
        self.slf3d.NVAR = 6
        self.slf3d.VARINDEX = range(self.slf3d.NVAR)
        self.slf3d.VARNAMES = ['ELEVATION Z     ', \
           'SALINITY        ','TEMPERATURE     ', \
           'VELOCITY U      ','VELOCITY V      ','VELOCITY W      ']
        self.slf3d.VARUNITS = ['M               ', \
           'G/L             ','DEGREES         ', \
           'M/S             ','M/S             ','M/S             ']
        self.slf2d.TITLE = self.slf3d.TITLE
        self.slf2d.NBV1 = self.slf3d.NBV1 + 1
        self.slf2d.NVAR = self.slf3d.NVAR + 1
        self.slf2d.VARINDEX = range(self.slf2d.NVAR)
        self.slf2d.VARNAMES = self.slf3d.VARNAMES[0:-1]
        self.slf2d.VARNAMES.append('EMP             ')
        self.slf2d.VARNAMES.append('QTOT            ')
        self.slf2d.VARUNITS = self.slf3d.VARUNITS[0:-1]
        self.slf2d.VARUNITS.append('???             ')
        self.slf2d.VARUNITS.append('???             ')
        # ~~> server access,
        #     get the grid and header from the latest experiment
        self.hycomdata = self.experiments[0][0]

        # ~~~~ Grid coordinates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        success = False
        while not success:
            try:
                success = True
                # ~~> the whole of the 2D grid sizes
                print '     +> Extract HYCOM sizes'
                NX1D = self.hycomdata['X'].shape[0]
                NY1D = self.hycomdata['Y'].shape[0]
                print '     +> Extract HYCOM mesh'
                lonX1D = self.hycomdata['Longitude']['Longitude'].data[
                    0, 0:NX1D].ravel() % 360
                latY1D = self.hycomdata['Latitude']['Latitude'].data[
                    0:NY1D, 0].ravel()
            except:
                success = False
                print ' ... re-attempting '
        # ~~> lat,lon correction
        for i in range(NX1D):
            if (lonX1D[i] > 180): lonX1D[i] = lonX1D[i] - 360.0
        for i in range(2172, NY1D):
            latY1D[i] = 47.0 + (i - 2172) / 18.0
        # ~~> subset for the SELAFIN
        print '     +> Set SELAFIN mesh'
        self.hycomilon = np.where(
            (lonX1D >= bounds[0][1]) * (lonX1D <= bounds[1][1]))[0]
        self.hycomilat = np.where(
            (latY1D >= bounds[0][0]) * (latY1D <= bounds[1][0]))[0]
        x = lonX1D[self.hycomilon]
        y = latY1D[self.hycomilat]
        NX1D = len(x)
        NY1D = len(y)

        # ~~~~ MESH sizes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # ~~> 3D
        success = False
        while not success:
            try:
                success = True
                print '     +> Set SELAFIN sizes'
                self.slf3d.NPLAN = self.hycomdata['Depth'].shape[0]
                self.ZPLAN = self.hycomdata['Depth'][
                    0:self.slf3d.NPLAN][::-1]  # I do not know any other way
            except:
                success = False
                print ' ... re-attempting '
        self.slf3d.NDP2 = 3
        self.slf3d.NDP3 = 6
        self.slf3d.NPOIN2 = NX1D * NY1D
        self.slf3d.NPOIN3 = self.slf3d.NPOIN2 * self.slf3d.NPLAN
        self.slf3d.NELEM2 = 2 * (NX1D - 1) * (NY1D - 1)
        self.slf3d.NELEM3 = self.slf3d.NELEM2 * (self.slf3d.NPLAN - 1)
        self.slf3d.IPARAM = [0, 0, 0, 0, 0, 0, self.slf3d.NPLAN, 0, 0, 0]
        # ~~> 2D
        self.slf2d.NPLAN = 1
        self.slf2d.NDP2 = self.slf3d.NDP2
        self.slf2d.NDP3 = self.slf2d.NDP2
        self.slf2d.NPOIN2 = self.slf3d.NPOIN2
        self.slf2d.NPOIN3 = self.slf2d.NPOIN2
        self.slf2d.NELEM2 = self.slf3d.NELEM2
        self.slf2d.NELEM3 = self.slf2d.NELEM2
        self.slf2d.IPARAM = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0]

        print '     +> Set SELAFIN mesh'
        self.slf3d.MESHX = np.tile(x, NY1D).reshape(NY1D, NX1D).T.ravel()
        self.slf3d.MESHY = np.tile(y, NX1D)
        self.slf2d.MESHX = self.slf3d.MESHX[0:self.slf2d.NPOIN2]
        self.slf2d.MESHY = self.slf3d.MESHY[0:self.slf2d.NPOIN2]

        # ~~~~ Connectivity ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        print '     +> Set SELAFIN IKLE'
        ielem = 0
        pbar = ProgressBar(maxval=self.slf3d.NELEM3).start()
        self.slf3d.IKLE3 = np.zeros((self.slf3d.NELEM3, self.slf3d.NDP3),
                                    dtype=np.int)
        for k in range(1, self.slf3d.NPLAN):
            for i in range(1, NX1D):
                for j in range(1, NY1D):
                    ipoin = (i - 1) * NY1D + j - 1 + (k -
                                                      1) * self.slf3d.NPOIN2
                    # ~~> first prism
                    self.slf3d.IKLE3[ielem][0] = ipoin
                    self.slf3d.IKLE3[ielem][1] = ipoin + NY1D
                    self.slf3d.IKLE3[ielem][2] = ipoin + 1
                    self.slf3d.IKLE3[ielem][3] = ipoin + self.slf3d.NPOIN2
                    self.slf3d.IKLE3[ielem][
                        4] = ipoin + NY1D + self.slf3d.NPOIN2
                    self.slf3d.IKLE3[ielem][5] = ipoin + 1 + self.slf3d.NPOIN2
                    ielem = ielem + 1
                    pbar.update(ielem)
                    # ~~> second prism
                    self.slf3d.IKLE3[ielem][0] = ipoin + NY1D
                    self.slf3d.IKLE3[ielem][1] = ipoin + NY1D + 1
                    self.slf3d.IKLE3[ielem][2] = ipoin + 1
                    self.slf3d.IKLE3[ielem][
                        3] = ipoin + NY1D + self.slf3d.NPOIN2
                    self.slf3d.IKLE3[ielem][
                        4] = ipoin + NY1D + 1 + self.slf3d.NPOIN2
                    self.slf3d.IKLE3[ielem][5] = ipoin + 1 + self.slf3d.NPOIN2
                    ielem = ielem + 1
                    pbar.update(ielem)
        pbar.finish()
        self.slf2d.IKLE3 = np.compress(
            np.repeat([True, False], self.slf2d.NDP2),
            self.slf3d.IKLE3[0:self.slf3d.NELEM2],
            axis=1)  #.reshape((self.slf3d.NELEM2,self.slf3d.NDP2))

        # ~~~~ Boundaries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        print '     +> Set SELAFIN IPOBO'
        pbar = ProgressBar(maxval=NX1D + NY1D).start()
        self.slf3d.IPOB3 = np.zeros(self.slf3d.NPOIN3, dtype=np.int)
        # ~~> along the x-axis (lon)
        for i in range(NX1D):
            for k in range(1, self.slf3d.NPLAN + 1):
                ipoin = i * NY1D + (k - 1) * (2 * NX1D + 2 * NY1D - 4)
                self.slf3d.IPOB3[ipoin] = i + 1 + (k - 1) * (2 * NX1D +
                                                             2 * NY1D - 4)
                ipoin = i * NY1D - 1 + (k - 1) * (2 * NX1D + 2 * NY1D - 4)
                self.slf3d.IPOB3[ipoin] = 2 * NX1D + (
                    NY1D - 2) - i + (k - 1) * (2 * NX1D + 2 * NY1D - 4)
            pbar.update(i)
        # ~~> along the y-axis (alt)
        for i in range(1, NY1D):
            for k in range(1, self.slf3d.NPLAN + 1):
                ipoin = i + (k - 1) * (2 * NX1D + 2 * NY1D - 4)
                self.slf3d.IPOB3[ipoin] = 2 * NX1D + 2 * (NY1D - 2) - i + 1 + (
                    k - 1) * (2 * NX1D + 2 * NY1D - 4)
                ipoin = NY1D * (NX1D - 1) + i + (k - 1) * (2 * NX1D +
                                                           2 * NY1D - 4)
                self.slf3d.IPOB3[ipoin] = NX1D + i + (k - 1) * (2 * NX1D +
                                                                2 * NY1D - 4)
            pbar.update(i + NX1D)
        pbar.finish()
        self.slf2d.IPOB3 = self.slf3d.IPOB3[0:self.slf3d.NPOIN2]
コード例 #10
0
    def getHeaderJCOPE2(self, bounds):

        # ~~> inheritence
        self.slf3d = SELAFIN('')  # slf3d
        self.slf2d = SELAFIN('')  # slf2d surface

        print '     +> Set SELAFIN Variables'
        self.slf3d.TITLE = ''
        self.slf3d.NBV1 = 6
        self.slf3d.NVAR = 6
        self.slf3d.VARINDEX = range(self.slf3d.NVAR)
        self.slf3d.VARNAMES = ['ELEVATION Z     ', \
           'SALINITY        ','TEMPERATURE     ', \
           'VELOCITY U      ','VELOCITY V      ','VELOCITY W      ']
        self.slf3d.VARUNITS = ['M               ', \
           '                ','                ', \
           'M/S             ','M/S             ','M/S             ']
        self.slf2d.TITLE = self.slf3d.TITLE
        self.slf2d.NBV1 = self.slf3d.NBV1 - 1
        self.slf2d.NVAR = self.slf2d.NBV1
        self.slf2d.VARINDEX = range(self.slf2d.NVAR)
        self.slf2d.VARNAMES = self.slf3d.VARNAMES[0:-1]
        self.slf2d.VARUNITS = self.slf3d.VARUNITS[0:-1]

        # ~~~~ Grid coordinates ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        # ~~> the whole of the 2D grid sizes
        print '     +> Extract JCOPE2 sizes'
        # /!\ 't' gives me access to NPLAN in 3D
        jcope2data = self.experiments[0][0]['temp']
        NX1D = jcope2data['lon'].shape[0]
        NY1D = jcope2data['lat'].shape[0]
        print '     +> Extract JCOPE2 mesh'
        lonX1D = jcope2data['lon'].data[0:NX1D]
        latY1D = jcope2data['lat'].data[0:NY1D]
        # ~~> no correction for lat,lon
        # ~~> subset for the SELAFIN
        print '     +> Set SELAFIN mesh'
        self.jcope2ilon = np.where(
            (lonX1D >= bounds[0][1]) * (lonX1D <= bounds[1][1]))[0]
        self.jcope2ilat = np.where(
            (latY1D >= bounds[0][0]) * (latY1D <= bounds[1][0]))[0]
        x = lonX1D[self.jcope2ilon]
        y = latY1D[self.jcope2ilat]
        NX1D = len(x)
        NY1D = len(y)

        # ~~~~ MESH sizes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        print '     +> Set SELAFIN sizes'
        # ~~> 3D
        self.slf3d.NPLAN = jcope2data['lev'].shape[0]
        self.ZPLAN = jcope2data['lev'][
            0:self.slf3d.NPLAN][::-1]  # I do not know any other way
        self.slf3d.NDP2 = 3
        self.slf3d.NDP3 = 6
        self.slf3d.NPOIN2 = NX1D * NY1D
        self.slf3d.NPOIN3 = self.slf3d.NPOIN2 * self.slf3d.NPLAN
        self.slf3d.NELEM2 = 2 * (NX1D - 1) * (NY1D - 1)
        self.slf3d.NELEM3 = self.slf3d.NELEM2 * (self.slf3d.NPLAN - 1)
        self.slf3d.IPARAM = [0, 0, 0, 0, 0, 0, self.slf3d.NPLAN, 0, 0, 0]
        # ~~> 2D
        self.slf2d.NPLAN = 1
        self.slf2d.NDP2 = self.slf3d.NDP2
        self.slf2d.NDP3 = self.slf2d.NDP2
        self.slf2d.NPOIN2 = self.slf3d.NPOIN2
        self.slf2d.NPOIN3 = self.slf2d.NPOIN2
        self.slf2d.NELEM2 = self.slf3d.NELEM2
        self.slf2d.NELEM3 = self.slf2d.NELEM2
        self.slf2d.IPARAM = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0]

        # ~~~~ Connectivity ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        print '     +> Set the default SELAFIN IKLE 3D'
        ielem = 0
        pbar = ProgressBar(maxval=self.slf3d.NELEM3).start()
        self.slf3d.IKLE3 = np.zeros((self.slf3d.NELEM3, self.slf3d.NDP3),
                                    dtype=np.int)
        for k in range(1, self.slf3d.NPLAN):
            for i in range(1, NX1D):
                for j in range(1, NY1D):
                    ipoin = (i - 1) * NY1D + j - 1 + (k -
                                                      1) * self.slf3d.NPOIN2
                    # ~~> first prism
                    self.slf3d.IKLE3[ielem][0] = ipoin
                    self.slf3d.IKLE3[ielem][1] = ipoin + NY1D
                    self.slf3d.IKLE3[ielem][2] = ipoin + 1
                    self.slf3d.IKLE3[ielem][3] = ipoin + self.slf3d.NPOIN2
                    self.slf3d.IKLE3[ielem][
                        4] = ipoin + NY1D + self.slf3d.NPOIN2
                    self.slf3d.IKLE3[ielem][5] = ipoin + 1 + self.slf3d.NPOIN2
                    ielem = ielem + 1
                    pbar.update(ielem)
                    # ~~> second prism
                    self.slf3d.IKLE3[ielem][0] = ipoin + NY1D
                    self.slf3d.IKLE3[ielem][1] = ipoin + NY1D + 1
                    self.slf3d.IKLE3[ielem][2] = ipoin + 1
                    self.slf3d.IKLE3[ielem][
                        3] = ipoin + NY1D + self.slf3d.NPOIN2
                    self.slf3d.IKLE3[ielem][
                        4] = ipoin + NY1D + 1 + self.slf3d.NPOIN2
                    self.slf3d.IKLE3[ielem][5] = ipoin + 1 + self.slf3d.NPOIN2
                    ielem = ielem + 1
                    pbar.update(ielem)
        pbar.finish()
        self.slf2d.IKLE3 = np.compress(
            [True, True, True, False, False, False],
            self.slf3d.IKLE3[0:self.slf3d.NELEM2],
            axis=1)  #.reshape((self.slf3d.NELEM2,self.slf3d.NDP2))

        # ~~~~ Boundaries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        print '     +> Set SELAFIN IPOBO'
        pbar = ProgressBar(maxval=NX1D + NY1D).start()
        IPOB2 = np.zeros(self.slf3d.NPOIN2, dtype=np.int)
        # ~~> along the x-axis (lon)
        for i in range(NX1D):
            ipoin = i * NY1D
            IPOB2[ipoin] = i + 1
            ipoin = i * NY1D - 1
            IPOB2[ipoin] = 2 * NX1D + (NY1D - 2) - i
            pbar.update(i)
        # ~~> along the y-axis (alt)
        for i in range(1, NY1D):
            ipoin = i
            IPOB2[ipoin] = 2 * NX1D + 2 * (NY1D - 2) - i + 1
            ipoin = NY1D * (NX1D - 1) + i
            IPOB2[ipoin] = NX1D + i
            pbar.update(i + NX1D)
        pbar.finish()

        # ~~~~ Connectivity ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        # /!\ 'el' gives me access to the real mesh removing elements with -99 values
        print '     +> Mask the non-values from the SELAFIN IKLE'
        jcope2data = self.experiments[0][0]['el']
        var = np.swapaxes(
            jcope2data['el'].data[0, 0,
                                  self.jcope2ilat[0]:self.jcope2ilat[-1] + 1,
                                  self.jcope2ilon[0]:self.jcope2ilon[-1] +
                                  1][0], 1, 2).ravel()
        # ~> the elements you wish to keep
        MASK2 = self.slf2d.IKLE3[np.where(
            np.sum(np.in1d(
                self.slf2d.IKLE3, np.compress(var > -99, np.arange(len(
                    var)))).reshape(self.slf2d.NELEM2, self.slf2d.NDP2),
                   axis=1) == 3)]

        self.slf2d.NELEM2 = len(MASK2)
        self.slf2d.NELEM3 = self.slf2d.NELEM2
        self.slf3d.NELEM2 = self.slf2d.NELEM2
        self.slf3d.NELEM3 = self.slf3d.NELEM2 * (self.slf3d.NPLAN - 1)

        # ~~> re-numbering IKLE2 as a local connectivity matrix
        KNOLG, indices = np.unique(np.ravel(MASK2), return_index=True)
        KNOGL = dict(zip(KNOLG, range(len(KNOLG))))
        self.MASK2 = np.in1d(np.arange(len(var)), KNOLG)
        self.MASK3 = np.tile(self.MASK2, self.slf3d.NPLAN)
        self.slf2d.IKLE2 = -np.ones_like(MASK2, dtype=np.int)
        for k in range(len(MASK2)):
            self.slf2d.IKLE2[k] = [
                KNOGL[MASK2[k][0]], KNOGL[MASK2[k][1]], KNOGL[MASK2[k][2]]
            ]

        self.slf3d.NPOIN2 = len(KNOLG)
        self.slf3d.NPOIN3 = self.slf3d.NPOIN2 * self.slf3d.NPLAN
        self.slf2d.NPOIN2 = self.slf3d.NPOIN2
        self.slf2d.NPOIN3 = self.slf2d.NPOIN2

        # ~~> re-connecting the upper floors
        self.slf2d.IKLE3 = self.slf2d.IKLE2
        self.slf3d.IKLE2 = self.slf2d.IKLE2
        self.slf3d.IKLE3 = \
           np.repeat(self.slf2d.NPOIN2*np.arange(self.slf3d.NPLAN-1),self.slf2d.NELEM2*self.slf3d.NDP3).reshape((self.slf2d.NELEM2*(self.slf3d.NPLAN-1),self.slf3d.NDP3)) + \
           np.tile(np.add(np.tile(self.slf2d.IKLE2,2),np.repeat(self.slf2d.NPOIN2*np.arange(2),self.slf3d.NDP2)),(self.slf3d.NPLAN-1,1))

        # ~~~~ Boundaries ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        self.slf2d.IPOB2 = IPOB2[self.MASK2]
        self.slf2d.IPOB3 = self.slf2d.IPOB2
        self.slf3d.IPOB2 = self.slf2d.IPOB2
        self.slf3d.IPOB3 = np.ravel(
            np.add(
                np.repeat(self.slf2d.IPOB2, self.slf3d.NPLAN).reshape(
                    (self.slf2d.NPOIN2, self.slf3d.NPLAN)),
                self.slf2d.NPOIN2 * np.arange(self.slf3d.NPLAN)).T)

        # ~~~~ Mesh ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        print '     +> Set SELAFIN mesh'
        self.slf3d.MESHX = np.tile(x, NY1D).reshape(
            NY1D, NX1D).T.ravel()[self.MASK2] + 0.042
        self.slf3d.MESHY = np.tile(y, NX1D)[self.MASK2] + 0.042
        self.slf2d.MESHX = self.slf3d.MESHX
        self.slf2d.MESHY = self.slf3d.MESHY
コード例 #11
0
A script to map 2D or 3D outter model results into a SELAFIN, onto the
   one frame of contained SELAFIN file of your choosing (your MESH).
      '''))
   parser.add_argument( "args",default='',nargs=3 )
   options = parser.parse_args()

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ slf new mesh ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   geoFile = options.args[0]
   if not path.exists(geoFile):
      print '... the provided geoFile does not seem to exist: '+geoFile+'\n\n'
      sys.exit(1)

# Find corresponding (x,y) in corresponding new mesh
   print '   +> getting hold of the GEO file and of its bathymetry'
   geo = SELAFIN(geoFile)
   xys = np.vstack( (geo.MESHX,geo.MESHY) ).T
   bat = geo.getVariablesAt( 0,subsetVariablesSLF("BOTTOM: ",geo.VARNAMES)[0] )[0]

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ slf existing res ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   slfFile = options.args[1]
   if not path.exists(slfFile):
      print '... the provided geoFile does not seem to exist: '+slfFile+'\n\n'
      sys.exit(1)
   slf = SELAFIN(slfFile)
   slf.setKDTree()
   slf.setMPLTri()

   print '   +> support extraction'
   # Extract triangles and weights in 2D
コード例 #12
0
ファイル: convertToATM.py プロジェクト: ogoe/OpenTelemac
A script to map weather type data contained into a SELAFIN, onto a
   spatially and time varying SELAFIN file of your choosing (your MESH).
      '''))
    parser.add_argument("args", default='', nargs=3)
    options = parser.parse_args()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ slf new mesh ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    geoFile = options.args[0]
    if not path.exists(geoFile):
        print '... the provided geoFile does not seem to exist: ' + geoFile + '\n\n'
        sys.exit(1)

# Find corresponding (x,y) in corresponding new mesh
    print '   +> getting hold of the GEO file'
    geo = SELAFIN(geoFile)
    xys = np.vstack((geo.MESHX, geo.MESHY)).T

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ slf existing res ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    slfFile = options.args[1]
    if not path.exists(slfFile):
        print '... the provided slfFile does not seem to exist: ' + slfFile + '\n\n'
        sys.exit(1)
    slf = SELAFIN(slfFile)
    slf.setKDTree()
    slf.setMPLTri()

    print '   +> support extraction'
    # Extract triangles and weights in 2D
    support2d = []
コード例 #13
0
b = np.subtract(b, 1)

# to create the output file
#fout = open("junk.out","w")

#for i in range(len(b)):
#	fout.write(str(b[i]) + '\n')

# now we can delete the temp file
os.remove(temp_nodes_file)
os.remove(temp_elements_file)
os.remove(temp_boundaries_file)

# now to write the SELAFIN mesh file
slf2d = SELAFIN('')

#print '     +> Set SELAFIN variables'
slf2d.TITLE = 'Converted from gmsh'
slf2d.NBV1 = 1
slf2d.NVAR = 1
slf2d.VARINDEX = range(slf2d.NVAR)
slf2d.VARNAMES.append('BOTTOM          ')
slf2d.VARUNITS.append('M               ')

#print '     +> Set SELAFIN sizes'
slf2d.NPLAN = 1
slf2d.NDP2 = 3
slf2d.NDP3 = 3
slf2d.NPOIN2 = n
slf2d.NPOIN3 = n
コード例 #14
0
    def add(self, typl, what):
        Caster.add(self, typl, what)

        # ~~> output from for 2D file
        if self.obtype == 'slf':
            #self.obdump.add(self.object[what['file']])
            cast = self.get(typl, what)
            support = cast.support
            values = cast.values
            if len(support) != 3:
                print '... not enough information to save as 2d variable'
                sys.exit(1)
            obj = self.object[what['file']]
            # ~~ SELAFIN header ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            if not self.oudata:
                self.oudata = SELAFIN('')
                # create the out header
                self.oudata.TITLE = ''  # TODO: pass it on from what and deco
                self.oudata.NBV1 = 0
                self.oudata.VARNAMES = []
                self.oudata.VARUNITS = []
                self.oudata.IPARAM = obj.IPARAM
                self.oudata.IPARAM[6] = 1  # 3D being forced to 2D
                self.oudata.NDP2 = len(support[2][0])
                if np.all([obj.IKLE2, support[2]]):
                    self.oudata.IKLE2 = support[3]
                    self.oudata.IPOB2 = np.zeros(len(supoort[0]), dtype=np.int)
                    self.oudata.MESHX = support[0]
                    self.oudata.MESHY = support[1]
                else:
                    self.oudata.IKLE2 = obj.IKLE2
                    self.oudata.IPOB2 = obj.IPOB2  # IPOBO missing from support
                    self.oudata.MESHX = obj.MESHX
                    self.oudata.MESHY = obj.MESHY
                self.oudata.NELEM2 = len(self.oudata.IKLE2)
                self.oudata.NPOIN2 = len(self.oudata.MESHX)
                self.oudata.NELEM3 = self.oudata.NELEM2
                self.oudata.NPOIN3 = self.oudata.NPOIN2
                self.oudata.NDP3 = self.oudata.NDP2
                self.oudata.NPLAN = 1
            vars, vtypes = whatVarsSLF(what['vars'], obj.VARNAMES)
            self.oudata.NBV1 = self.oudata.NBV1 + len(vars[0])
            self.oudata.NBV2 = 0
            self.oudata.NVAR = self.oudata.NBV1 + self.oudata.NBV2
            self.oudata.CLDNAMES = []
            self.oudata.CLDUNITS = []
            self.oudata.VARINDEX = range(self.oudata.NVAR)
            for ivar, ival in zip(vars[0], range(len(vars[0]))):
                self.oudata.VARNAMES.append(obj.VARNAMES[ivar])
                self.oudata.VARUNITS.append(obj.VARUNITS[ivar])
                self.obdata.update({obj.VARNAMES[ivar]: [values[ival]]})
            if max(self.oudata.IPARAM[9], obj.IPARAM[9]) > 0:
                if self.oudata.DATETIME != obj.DATETIME:
                    self.oudata.IPARAM[9] = 0
            if self.oudata.NELEM2 != obj.NELEM2 or self.oudata.NPOIN2 != obj.NPOIN2:
                print '... mismatch between the 2D sizes of layers of a same save2d object '
                sys.exit(1)
            self.oudata.IKLE3 = self.oudata.IKLE2
            self.oudata.IPOB3 = self.oudata.IPOB2

        # ~~> unkonwn
        else:  # TODO: raise exception
            print '... do not know how to write to this format: ' + self.obtype
            sys.exit(1)
コード例 #15
0
def mesh2KML(meshFile, projection):
    if not os.path.isdir('static'):
        os.mkdir('static')
    else:
        # Remove old kml files
        for filename in glob.glob(os.path.join('static', '*.kml')):
            os.remove(filename)
    fname = meshFile[:-3] + 'kml'
    print("fname before split" + fname)
    fname = fname.split("/")[2]
    #fname = "Mesh_Final_V1.kml"
    print("fname is " + fname)
    myFile = os.path.join('static', fname)
    print(myFile)
    fOut = open(myFile, 'w')
    mainDir = 'static'
    inProj = Proj(init=projection)
    wgs = "epsg:4326"
    outProj = Proj(init=wgs)
    newScan = scanSELAFIN(meshFile)
    newScan.printHeader()

    slf = SELAFIN(meshFile)
    xmin = np.min(slf.MESHX)
    xmax = np.max(slf.MESHX)
    ymin = np.min(slf.MESHY)
    ymax = np.max(slf.MESHY)
    elements = np.dstack((slf.MESHX[slf.IKLE2], slf.MESHY[slf.IKLE2]))
    mesh = np.array(slf.IKLE2)
    x = slf.MESHX
    y = slf.MESHY
    nelem = len(elements[:, 0, 0])
    inKml = mainDir + "/meshviewer/polyCell.kml"
    fIn = open(inKml, 'r')
    lines = fIn.readlines()
    lcnt = 0
    for line in lines:
        if lcnt < 47:
            fOut.write(line)
        lcnt = lcnt + 1
    cnt = 0

    for i in range(0, nelem):
        x1 = elements[i, 0, 0]
        y1 = elements[i, 0, 1]
        #if x1>=xmin and x1<=xmax and y1>=ymin and y1<=ymax:
        if i >= 0:
            cnt = cnt + 1
            x2 = elements[i, 1, 0]
            y2 = elements[i, 1, 1]
            x3 = elements[i, 2, 0]
            y3 = elements[i, 2, 1]
            if projection != wgs:
                x1, y1 = transform(inProj, outProj, x1, y1)
                x2, y2 = transform(inProj, outProj, x2, y2)
                x3, y3 = transform(inProj, outProj, x3, y3)
            poly = (str(x1) + "," + str(y1) + "," + str(0) + " " + str(x2) +
                    "," + str(y2) + "," + str(0) + " " + str(x3) + "," +
                    str(y3) + "," + str(0) + " " + str(x1) + "," + str(y1) +
                    "," + str(0))
            fOut.write("<Placemark>" + "\n")
            fOut.write("<name>polyCell</name>" + "\n")
            fOut.write("<styleUrl>#msn_ylw-pushpin</styleUrl>" + "\n")
            fOut.write("<Polygon>" + "\n")
            fOut.write("<tessellate>1</tessellate>" + "\n")
            fOut.write("<altitudeMode>relativeToGround</altitudeMode>" + "\n")
            fOut.write("<outerBoundaryIs>" + "\n")
            fOut.write("<LinearRing>" + "\n")
            fOut.write("<coordinates>" + "\n")
            fOut.write(poly + "\n")
            fOut.write("</coordinates>" + "\n")
            fOut.write("</LinearRing>" + "\n")
            fOut.write("</outerBoundaryIs>" + "\n")
            fOut.write("</Polygon>" + "\n")
            fOut.write("</Placemark>" + "\n")

    fOut.write("</Document>" + "\n")
    fOut.write("</kml>" + "\n")
    fOut.close()
    fIn.close()
コード例 #16
0
    def main1(self):
        progress.setPercentage(0)
        progress.setText(str(ctime()) + " - Initialisation - Debut du script")
        #Chargement du fichier .res****************************************
        slf = SELAFIN(self.donnees_d_entree['pathselafin'])

        #Recherche du temps a traiter ***********************************************
        test = False
        for i, time in enumerate(slf.tags["times"]):
            progress.setText(
                str(ctime()) +
                " - Initialisation - Temps present dans le fichier : " +
                str(np.float64(time)))
            #print str(i) +" "+ str(time) + str(type(time))
            if float(time) == float(self.donnees_d_entree['temps']):
                test = True
                values = slf.getVALUES(i)
        if test:
            progress.setText(
                str(ctime()) + " - Initialisation - Temps traite : " +
                str(np.float64(self.donnees_d_entree['temps'])))
        else:
            raise GeoAlgorithmExecutionException(
                str(ctime()) + " - Initialisation - Erreur : \
                                   Temps non trouve")

        #Recherche de la variable a traiter ****************************************
        test = [False, False]
        tabparam = []
        donnees_d_entree['champs'] = QgsFields()
        for i, name in enumerate(slf.VARNAMES):
            progress.setText(
                str(ctime()) +
                " - Initialisation - Variable dans le fichier res : " +
                name.strip())
            tabparam.append([i, name.strip()])
            donnees_d_entree['champs'].append(
                QgsField(
                    str(name.strip()).translate(None, "?,!.;"),
                    QVariant.Double))
            if self.donnees_d_entree['Parametre_vitesse_X'] != None:
                if str(name).strip(
                ) == self.donnees_d_entree['Parametre_vitesse_X'].strip():
                    test[0] = True
                    self.donnees_d_entree['paramvalueX'] = i
                if str(name).strip(
                ) == self.donnees_d_entree['Parametre_vitesse_Y'].strip():
                    test[1] = True
                    self.donnees_d_entree['paramvalueY'] = i
            else:
                self.donnees_d_entree['paramvalueX'] = None
                self.donnees_d_entree['paramvalueY'] = None
        if self.donnees_d_entree['Parametre_vitesse_X'] != None:
            if test == [True, True]:
                progress.setText(
                    str(ctime()) + " - Initialisation - Parametre trouvee : " +
                    str(tabparam[self.donnees_d_entree['paramvalueX']]
                        [1]).strip() + " " + str(tabparam[
                            self.donnees_d_entree['paramvalueY']][1]).strip())
            else:
                raise GeoAlgorithmExecutionException(
                    str(ctime()) + " - Initialisation - Erreur : \
                                     Parametre vitesse non trouve")

        #Chargement de la topologie du .res ********************************************
        self.donnees_d_entree['mesh'] = np.array(slf.IKLE3)
        self.donnees_d_entree['x'] = slf.MESHX
        self.donnees_d_entree['y'] = slf.MESHY

        #Verifie que le shp n existe pas
        if isFileLocked(self.donnees_d_entree['pathshp'], True):
            raise GeoAlgorithmExecutionException(
                str(ctime()) + " - Initialisation - Erreur :\
                                   Fichier shape deja charge !!")

        #Chargement des donnees  ***********************************
        self.donnees_d_entree['ztri'] = []
        for i in range(len(tabparam)):
            self.donnees_d_entree['ztri'].append(values[i])

        #Lancement du thread **************************************************************************************

        self.worker = Worker(donnees_d_entree)
        if donnees_d_entree['traitementarriereplan'] == 0:
            self.worker.moveToThread(self.thread)
            self.thread.started.connect(self.worker.run)
            self.worker.progress.connect(progress.setPercentage)
            self.worker.status.connect(progress.setText)
            self.worker.finished.connect(workerFinished)
            self.worker.finished.connect(self.worker.deleteLater)
            self.thread.finished.connect(self.thread.deleteLater)
            self.worker.finished.connect(self.thread.quit)
            champ = QgsFields()
            writercontour = VectorWriter(
                self.donnees_d_entree['fichierdesortie_point'], None, champ,
                QGis.WKBMultiPoint,
                QgsCoordinateReferenceSystem(str(
                    self.donnees_d_entree['crs'])))
            self.thread.start()
        else:
            self.worker.run()
コード例 #17
0
            else: csvF.write(str(columns[i][j]) + ',')
    csvF.close()
    return


if __name__ == "__main__":

    ############################################################################
    #####                    Importing data                               ######
    ############################################################################

    # Times Series from Selafin file
    # 5113 is the node number
    # 0,1,2,8 are the variable indexes

    slf = SELAFIN("sis_foulness.slf")

    series = slf.getSERIES([5113], [0, 1, 2, 8])

    u = series[0][0]
    v = series[1][0]
    h = series[2][0]
    QSsuspension = series[3][0]

    # Experiment data from CSV file
    # always write the variable name in lower case

    csv = CSV()
    csv.getFileContent('fielddata.csv')
    t, QSexp = csv.getColumns('qs')
コード例 #18
0
ファイル: mesh2KML.py プロジェクト: johnmaskell/mapweb-test
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from pyproj import Proj, transform
import shutil
import re

mainDir = 'C:/windFarm/'
f = mainDir + 'wind_farm_mesh_02.slf'

newScan = scanSELAFIN(f)

newScan.printHeader()

slf = SELAFIN(f)
xmin = np.min(slf.MESHX)
xmax = np.max(slf.MESHX)
ymin = np.min(slf.MESHY)
ymax = np.max(slf.MESHY)
elements = np.dstack((slf.MESHX[slf.IKLE2], slf.MESHY[slf.IKLE2]))
mesh = np.array(slf.IKLE2)
x = slf.MESHX
y = slf.MESHY

print(elements.shape)

print(str(len(elements[:, 0, 0])))

nelem = len(elements[:, 0, 0])
コード例 #19
0
        print '... the provided cliFile does not seem to exist: ' + cliFile + '\n\n'
        sys.exit(1)
    geoFile = options.args[1]
    if not path.exists(cliFile):
        print '... the provided geoFile does not seem to exist: ' + geoFile + '\n\n'
        sys.exit(1)

    # Read the new CLI file to get boundary node numbers
    print '   +> getting hold of the CONLIM file and of its liquid boundaries'
    cli = CONLIM(cliFile)
    # Keeping only open boundary nodes
    BOR = np.extract(cli.BOR['lih'] != 2, cli.BOR['n'])

    # Find corresponding (x,y) in corresponding new mesh
    print '   +> getting hold of the GEO file and of its bathymetry'
    geo = SELAFIN(geoFile)
    xys = np.vstack((geo.MESHX[BOR - 1], geo.MESHY[BOR - 1])).T
    bat = geo.getVariablesAt(0,
                             subsetVariablesSLF("BOTTOM: ",
                                                geo.VARNAMES)[0])[0]

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ slf existing res ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    slfFile = options.args[2]
    if not path.exists(cliFile):
        print '... the provided slfFile does not seem to exist: ' + slfFile + '\n\n'
        sys.exit(1)
    slf = SELAFIN(slfFile)
    slf.setKDTree()
    slf.setMPLTri()
コード例 #20
0
from samplers.meshes import crossMesh,sliceMesh
from parsers.parserStrings import parseArrayPoint

################################################################################
#####                    MAIN PROGRAM                                 ##########
################################################################################

if __name__ == "__main__":
    
    ############################################################################
    #####                    Importing data                               ######
    ############################################################################

    # Cross section from Selafin file
      
    slf = SELAFIN("sis_sandpit.slf")
    slf.setKDTree()
    slf.setMPLTri()
    
    variable = 'bottom:line'
    coordinates = '(50.0;0.5)(130.0;0.5)'
    timef = [20]
    
    vars = subsetVariablesSLF(variable,slf.VARNAMES)
    xyo = []; zpo = [] 
    for xyi,zpi in parseArrayPoint(coordinates,slf.NPLAN):
       if type(xyi) == type(()): xyo.append(xyi)
       else: xyo.append( (slf.MESHX[xyi],slf.MESHY[xyi]) )
       for p in zpi:                         
           if p not in zpo: zpo.append(p)
    xys,support2d = sliceMesh(xyo,slf.IKLE2,slf.MESHX,slf.MESHY,slf.tree)