/[escript]/trunk/doc/examples/cookbook/cblib2.py
ViewVC logotype

Contents of /trunk/doc/examples/cookbook/cblib2.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 4 months ago) by jfenwick
File MIME type: text/x-python
File size: 3246 byte(s)
Don't panic.
Updating copyright stamps

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
33 # Calculate the location of quivers for a matplotlib plot
34 # quivshape :: [x,y] :: number of quivers in x and y direction
35 # lenxax :: length of model along x
36 # lenyax :: length of model along y
37 # qu :: gradient of escript solution ie grad(T)
38 def toQuivLocs(quivshape,lenxax,lenyax,qu):
39 numquiv = quivshape[0]*quivshape[1] # total number of quivers
40 dx = lenxax/quivshape[0]+1. # quiver x spacing
41 dy = lenyax/quivshape[1]+1. # quiver y spacing
42 qulocs=np.zeros([numquiv,2],float) # memory for quiver locations
43 # fill qulocs
44 for i in range(0,quivshape[0]-1):
45 for j in range(0,quivshape[1]-1):
46 qulocs[i*quivshape[0]+j,:] = [dx+dx*i,dy+dy*j]
47 # retreive values for quivers direction and shape from qu
48 quL = Locator(qu.getFunctionSpace(),qulocs.tolist())
49 qu = quL(qu) #array of dx,dy for quivers
50 qu = np.array(qu) #turn into a numpy array
51 qulocs = quL.getX() #returns actual locations from data
52 qulocs = np.array(qulocs) #turn into a numpy array
53 return qu,qulocs
54
55
56
57
58 # Extract the X and Y coordinates of an array
59 # coords :: escript coordiantes from .getX function
60 def toXYTuple(coords):
61 coords = np.array(coords.toListOfTuples()) #convert to Tuple
62 coordX = coords[:,0]; coordY = coords[:,1] #X and Y components.
63 return coordX,coordY
64
65 def toRegGrid(grid,domain,newx,newy,width,depth):
66 import pylab as pl
67 oldspacecoords=domain.getX()
68 gridT = grid.toListOfTuples(scalarastuple=False)
69 cxy = Data(oldspacecoords, grid.getFunctionSpace())
70 cX, cY = toXYTuple(cxy)
71 xi = np.linspace(0.0,width,newx)
72 yi = np.linspace(depth,0.0,newy)
73 # grid the data.
74 zi = pl.matplotlib.mlab.griddata(cX,cY,gridT,xi,yi)
75 return xi,yi,zi
76
77 def gradtoRegGrid(grid,domain,newx,newy,width,depth,dim):
78 import pylab as pl
79 cxy = grid.getFunctionSpace().getX()
80 gridT = grid.toListOfTuples()#(scalarastuple=False)
81 #cxy = Data(oldspacecoords, grid.getFunctionSpace())
82 cX, cY = toXYTuple(cxy)
83 xi = np.linspace(0.0,width,newx)
84 yi = np.linspace(depth,0.0,newy)
85
86 gridT = np.array(gridT)
87 gridT = gridT[:,dim]
88
89 # grid the data.
90
91 zi = pl.matplotlib.mlab.griddata(cX,cY,gridT,xi,yi)
92 return xi,yi,zi

  ViewVC Help
Powered by ViewVC 1.1.26