/[escript]/branches/stage3.1/doc/examples/cookbook/cblib2.py
ViewVC logotype

Contents of /branches/stage3.1/doc/examples/cookbook/cblib2.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2945 - (show annotations)
Wed Feb 24 00:17:46 2010 UTC (8 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 2989 byte(s)
Bringing release stage up to trunk version 2944

1 ########################################################
2 #
3 # Copyright (c) 2009-2010 by University of Queensland
4 # Earth Systems Science Computational Center (ESSCC)
5 # http://www.uq.edu.au/esscc
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 ########################################################
12
13 __copyright__="""Copyright (c) 2009-2010 by University of Queensland
14 Earth Systems Science Computational Center (ESSCC)
15 http://www.uq.edu.au/esscc
16 Primary Business: Queensland, Australia"""
17 __license__="""Licensed under the Open Software License version 3.0
18 http://www.opensource.org/licenses/osl-3.0.php"""
19 __url__="https://launchpad.net/escript-finley"
20
21 """
22 Additional routines using matplotlib for cookbook examples.
23 Author: Antony Hallam antony.hallam@uqconnect.edu.au
24 """
25
26 #Please ensure that if you need to use the agg back-end that you have chosen it before
27 #calling functions in this file
28
29 import numpy as np
30 from esys.escript import Data
31 from esys.escript.pdetools import Locator
32 from cblib import toXYTuple
33
34 # Calculate the location of quivers for a matplotlib plot
35 # quivshape :: [x,y] :: number of quivers in x and y direction
36 # lenxax :: length of model along x
37 # lenyax :: length of model along y
38 # qu :: gradient of escript solution ie grad(T)
39 def toQuivLocs(quivshape,lenxax,lenyax,qu):
40 numquiv = quivshape[0]*quivshape[1] # total number of quivers
41 dx = lenxax/quivshape[0]+1. # quiver x spacing
42 dy = lenyax/quivshape[1]+1. # quiver y spacing
43 qulocs=np.zeros([numquiv,2],float) # memory for quiver locations
44 # fill qulocs
45 for i in range(0,quivshape[0]-1):
46 for j in range(0,quivshape[1]-1):
47 qulocs[i*quivshape[0]+j,:] = [dx+dx*i,dy+dy*j]
48 # retreive values for quivers direction and shape from qu
49 quL = Locator(qu.getFunctionSpace(),qulocs.tolist())
50 qu = quL(qu) #array of dx,dy for quivers
51 qu = np.array(qu) #turn into a numpy array
52 qulocs = quL.getX() #returns actual locations from data
53 qulocs = np.array(qulocs) #turn into a numpy array
54 return qu,qulocs
55
56 def toRegGrid(grid,domain,newx,newy,width,depth):
57 import pylab as pl
58 oldspacecoords=domain.getX()
59 gridT = grid.toListOfTuples(scalarastuple=False)
60 cxy = Data(oldspacecoords, grid.getFunctionSpace())
61 cX, cY = toXYTuple(cxy)
62 xi = np.linspace(0.0,width,newx)
63 yi = np.linspace(depth,0.0,newy)
64 # grid the data.
65 zi = pl.matplotlib.mlab.griddata(cX,cY,gridT,xi,yi)
66 return xi,yi,zi
67
68 def gradtoRegGrid(grid,domain,newx,newy,width,depth,dim):
69 import pylab as pl
70 cxy = grid.getFunctionSpace().getX()
71 gridT = grid.toListOfTuples()#(scalarastuple=False)
72 #cxy = Data(oldspacecoords, grid.getFunctionSpace())
73 cX, cY = toXYTuple(cxy)
74 xi = np.linspace(0.0,width,newx)
75 yi = np.linspace(depth,0.0,newy)
76
77 gridT = np.array(gridT)
78 gridT = gridT[:,dim]
79
80 # grid the data.
81
82 zi = pl.matplotlib.mlab.griddata(cX,cY,gridT,xi,yi)
83 return xi,yi,zi

  ViewVC Help
Powered by ViewVC 1.1.26