示例#1
0
   def castProfileAtPolyline(self,whatVARS,whatTIME,whatPOINTS):

      # ~~> Extract data
      # what['vars']: list of pairs variables:support2d delimited by ';'
      vars = subsetVariablesSLF(whatVARS,self.VARNAMES)
      # what['time']: list of frames or (times,) delimited by ';'
      t = parseArrayFrame(whatTIME,len(self.tags['cores']))
      # what['extract']: could be list delimited by ';', of:
      #    + points (x;y),
      #    + 2D points (x;y) bundled within (x;y)#n or (x;y)@d#n, delimited by ';'
      #      where n is a plan number and d is depth from that plane (or the surface by default)
      xyo = []; zpo = []
      for xyi,zpi in parseArrayPoint(whatPOINTS,self.NPLAN):
         if type(xyi) == type(()): xyo.append(xyi)
         else: xyo.append( (self.MESHX[xyi],self.MESHY[xyi]) )
         for p in zpi:                         # /!\ common deinition of plans
            if p not in zpo: zpo.append(p)     # /!\ only allowing plans for now
      xys,support2d = sliceMesh(xyo,self.IKLE2,self.MESHX,self.MESHY,self.tree)
      # - support2d[i][0] is either the douplets of nodes for each edges crossing with the polyline
      # - support2d[i][1] is the plan or depth definition
      support3d = [ (s2d,zpo) for s2d in support2d ]  # common vertical definition to all points
      data = getValuePolylineSLF(self.file,self.tags,t,support3d,self.NVAR,self.NPOIN3,self.NPLAN,vars)
      # Distance d-axis
      distot = 0.0
      d = [ distot ]
      for xy in range(len(xys)-1):
         distot += np.sqrt( np.power(xys[xy+1][0]-xys[xy][0],2) + np.power(xys[xy+1][1]-xys[xy][1],2) )
         d.append(distot)
      # ~~> Draw/Dump data
      return ('Distance (m)',d),[('v-section',vars[1],self.tags['times'][t],zpo,data)]
示例#2
0
   def castHistoryAtPoints(self,whatVARS,whatTIME,whatPOINTS):

      # ~~> Extract data
      # whatVARS: list of pairs variables:support delimited by ';' (/!\ support is ignored)
      vars = subsetVariablesSLF(whatVARS,self.VARNAMES)
      # whatTIME: list of frames or (times,) delimited by ';'
      t = parseArrayFrame(whatTIME,len(self.tags['cores']))
      # whatPOINTS: could be list delimited by ';', of:
      #    + points (x;y),
      #    + 2D points (x;y) bundled within (x;y)#n or (x;y)@d#n, delimited by ';'
      #      where n is a plan number and d is depth from that plane (or the surface by default)
      support2d = []; zps = []
      pAP = parseArrayPoint(whatPOINTS,self.NPLAN)
      for xyi,zpi in pAP:
         if type(xyi) == type(()): support2d.append( xysLocateMesh(xyi,self.IKLE2,self.MESHX,self.MESHY,self.tree,self.neighbours) )
         else: support2d.append( xyi )
         zps.append( zpi )
      support3d = zip(support2d,zps)
      # - support2d[i][0] is either the node or the triplet of nodes for each element including (x,y)
      # - support2d[i][1] is the plan or depth definition
      data = getValueHistorySLF(self.file,self.tags,t,support3d,self.NVAR,self.NPOIN3,self.NPLAN,vars)

      # ~~> Draw/Dump data
      return ('Time (s)',self.tags['times'][t]), \
         [('',[n.replace(' ','_').replace(',',';') for n in vars[1]],[(str(n[0])+':'+str(m)).replace(' ','').replace(',',';') for n in pAP for m in n[1]],data)]
示例#3
0
def mapDecoDefault(decoUser, default):

    # ~~~ melting the pot ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    mpar = {}  # mpar, contains the matplotlib parameters (defaults)
    upar = deepcopy(
        default)  # upar, contains the user parameters (from the XML)
    for name in decoUser:
        if name not in ['look', 'data']: upar.update({name: decoUser[name]})
    for name in decoUser:
        if name in ['look', 'data']: upar.update(decoUser[name][0])

    # ~~~ special conversions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # Replaces the relevat mpar by the upar values
    for key in upar.keys():  # /!\ the .keys() is necessary
        if key in mpl.rcParams.keys():
            if type(mpl.rcParams[key]) == type(upar[key]):
                mpar[key] = deepcopy(upar[key])
                del upar[key]
            else:
                if type(mpl.rcParams[key]) == type([]):
                    if type(mpl.rcParams[key][0]) == type(1) or type(
                            mpl.rcParams[key][0]) == type(1.0):
                        mpar[key] = parseArrayFrame(upar[key])
                        del upar[key]
                    elif type(mpl.rcParams[key][0]) == type("") or type(
                            mpl.rcParams[key][0]) == type(unicode('')):
                        print upar[key].strip('[]')
                        mpar[key] = [
                            s.strip() for s in upar[key].strip('[]').replace(
                                ';', ',').split(',')
                        ]
                        del upar[key]
                    else:
                        print '... I did not know ', type(
                            mpl.rcParams[key]
                        ), ' for key:', key, '. Could be an acceptable type'
                        sys.exit(1)
                elif type(mpl.rcParams[key]) == type(True):
                    mpar[key] = (upar[key].lower() == 'true')
                    del upar[key]
                elif type(mpl.rcParams[key]) == type(1):
                    mpar[key] = int(upar[key])
                    del upar[key]
                elif type(mpl.rcParams[key]) == type(1.0):
                    mpar[key] = float(upar[key])
                    del upar[key]
                elif type(mpl.rcParams[key]) == type(""):
                    mpar[key] = upar[key]
                    del upar[key]
                elif mpl.rcParams[key] == None:
                    mpar[key] = upar[key]
                    del upar[key]
                elif type(mpl.rcParams[key][0]) == type(unicode('')):
                    mpar[key] = upar[key]
                    del upar[key]
                else:
                    print '... I did not know ', type(
                        mpl.rcParams[key]
                    ), ' for key:', key, '. Could be an acceptable type'
                    sys.exit(1)
        elif key == "dpi":
            if upar[key] != '':
                mpar.update({'savefig.dpi': int(upar[key])})
                mpar.update({'figure.dpi': int(upar[key])})
            del upar[key]
        elif key == "size":
            if upar[key] != '':
                mpar.update({'figure.figsize': parseArrayPaires(upar[key])[0]})
            del upar[key]
        elif key == "roi":
            if upar[key] != '':
                pairs = parseArrayPaires(upar[key])
                if len(pairs) == 2: pairs.extend([(0., 0.), (0., 0.)])
                elif len(pairs) != 4:
                    print '... could not interprete roi (' + upar[
                        key] + '): ' + pairs
                    sys.exit(1)
                upar[key] = pairs

    return mpar, upar
示例#4
0
def whatTimeSLF(instr,ctimes):
   # instr ~ what['time']: list of frames or (times,) delimited by ';'
   # ctimes ~ slf.tags['cores']: list of time
   return parseArrayFrame(instr,len(ctimes))