~ubuntu-branches/ubuntu/raring/python-scipy/raring-proposed

« back to all changes in this revision

Viewing changes to Lib/sandbox/xplt/surftest4d.py~

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-07 14:12:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070107141212-mm0ebkh5b37hcpzn
* Remove build dependency on python-numpy-dev.
* python-scipy: Depend on python-numpy instead of python-numpy-dev.
* Package builds on other archs than i386. Closes: #402783.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
## Automatically adapted for scipy Oct 31, 2005 by 
 
2
 
 
3
# Copyright (c) 1996, 1997, The Regents of the University of California.
 
4
# All rights reserved.  See Legal.htm for full text and disclaimer.
 
5
 
 
6
from scipy import *
 
7
from numpy.core.umath import *
 
8
from numpy.corelinalg import rand
 
9
from surface import *
 
10
from graph3d import *
 
11
from mesh3d import *
 
12
def paws ( ) :
 
13
    i = raw_input ("Type in any string to continue; ^C to return to prompt. ")
 
14
    return
 
15
 
 
16
GraphicsError = "GraphicsError"
 
17
import os
 
18
try:
 
19
   graphics = os.environ["PYGRAPH"]
 
20
except KeyError:
 
21
   graphics = "Gist"
 
22
 
 
23
if graphics [0:3] == "Nar" :
 
24
   import NarPlotter
 
25
elif graphics == "Gist" :
 
26
   import GistPlotter
 
27
else :
 
28
   raise GraphicsError , \
 
29
      graphics + " is an unknown graphics package. Check PYGRAPH " + \
 
30
         "environment variable."
 
31
 
 
32
if graphics [0:3] == "Nar" :
 
33
   print "This is a test of the Python interface to the Limeil Lab graphics"
 
34
   print "package, Narcisse. You  need Narcisse to be running. Fire it up by"
 
35
   print "doing setenv PORT_SERVEUR 0, typing  /dist/basis/Narcisse/bin/Narcisse &,"
 
36
   print "and then do another senetv PORT_SERVEUR to the port number which"
 
37
   print "appears in the Narcisse GUI."
 
38
else :
 
39
   print "This is a test of the Python interface to the Gist graphics package."
 
40
 
 
41
print "Invoke function demo () to run."
 
42
 
 
43
def demo () :
 
44
   vsf = 0.
 
45
   c = 1
 
46
   s = 1000.
 
47
   kmax = 25
 
48
   lmax = 35
 
49
   # The following computations define an interesting 3d surface.
 
50
   xr = multiply.outer (
 
51
      arange (1, kmax + 1, typecode = Float), ones (lmax, Float))
 
52
   yr = multiply.outer (
 
53
      ones (kmax, Float), arange (1, lmax + 1, typecode = Float))
 
54
   zt = 5. + xr + .2 * rand (kmax, lmax)   # ranf (xr)
 
55
   rt = 100. + yr + .2 * rand (kmax, lmax)   # ranf (yr)
 
56
   z = s * (rt + zt)
 
57
   z = z + .02 * z * rand (kmax, lmax)   # ranf (z)
 
58
   ut = rt / sqrt (rt ** 2 + zt ** 2)
 
59
   vt = zt / sqrt (rt ** 2 + zt ** 2)
 
60
   ireg =  multiply.outer ( ones (kmax), ones (lmax))
 
61
   ireg [0:1, 0:lmax] = 0
 
62
   ireg [0:kmax, 0:1] = 0
 
63
   ireg [1:15, 7:12] = 2
 
64
   ireg [1:15, 12:lmax] = 3
 
65
   ireg [3:7, 3:7] = 0
 
66
   freg = ireg + .2 * (1. - rand (kmax, lmax))  # ranf (ireg))
 
67
   freg = array (freg, Float)
 
68
   #rt [4:6, 4:6] = -1.e8
 
69
   z [3:10, 3:12] = z [3:10, 3:12] * .9
 
70
   z [5, 5] = z [5, 5] * .9
 
71
   z [17:22, 15:18] = z [17:22, 15:18] * 1.2
 
72
   z [16, 16] = z [16, 16] * 1.1
 
73
    
 
74
   # Sombrero function
 
75
   x = arange (-20, 21, typecode = Float)
 
76
   y = arange (-20, 21, typecode = Float)
 
77
   z = zeros ( (41, 41), Float)
 
78
   for i in range (0, 41):
 
79
       for j in range (0, 41):
 
80
           r = sqrt (x [i] ** 2 + y [j] ** 2) + 1e-6
 
81
           z [i, j] = sin (r) / r
 
82
   s1 = Surface (z = z, opt_3d = "s3", mask = "max")
 
83
   g1 = Graph3d ( s1 , titles = "Sombrero function",
 
84
                  y_factor = 2.0) #, phi = 30., theta = 45.)
 
85
   g1.plot ( )
 
86
   paws ( )
 
87
   s1.set (opt_3d = "w3")
 
88
   g1.plot ()
 
89
   paws ( )
 
90
   foo = zeros ( (kmax, lmax), Float)
 
91
   for k in range (kmax) :
 
92
      foo [k, 0:lmax] = log (arange (1, lmax + 1, typecode = Float))
 
93
      xxx = exp (k / 5.)
 
94
      for l in range (lmax) :
 
95
         foo [k, l] = xxx * foo [k, l]
 
96
   s1.new (x = xr, y = yr, z = foo, opt_3d = "w3")
 
97
   g1.change ( titles = "Exponential surface, z logarithmic", 
 
98
            # phi = 30., theta = 45.,
 
99
            axis_scales = ["lin", "lin", "log"],
 
100
            z_contours_scale = "log", y_factor = 1.0)
 
101
   g1.plot ( )
 
102
   paws ( )
 
103
   xr = array (xr)
 
104
   yr = array (yr)
 
105
   zz = xr ** 2 + yr ** 2
 
106
   g1.change ( titles = "Exponential surface, z linear", phi = 45.,
 
107
            axis_scales = ["lin", "lin", "lin"] )
 
108
   g1.plot ( )
 
109
   paws ( )
 
110
   s1.new (z = zz, opt_3d = "w3")
 
111
   g1.change ( z_contours_scale = "lin",
 
112
            titles = "Graph of xr**2 + yr**2", phi = 35.)
 
113
   g1.plot ( )
 
114
   paws ( )
 
115
   zs = zeros ( (50, 25), Float)
 
116
   xs = zeros ( (50, 25), Float)
 
117
   ys = zeros ( (50, 25), Float)
 
118
   ctheta = zeros (50, Float)
 
119
   stheta = zeros (50, Float)
 
120
   cphi = zeros (25, Float)
 
121
   sphi = zeros (25, Float)
 
122
   pi = 3.1415926535
 
123
   for i in range (50):
 
124
      ctheta [i] = cos (2. * i / 49. * pi)
 
125
      stheta [i] = sin (2. * i / 49. * pi)
 
126
   for i in range (25):
 
127
      cphi [i] = cos (pi * i / 24.)
 
128
      sphi [i] = sin (pi * i / 24.)
 
129
   for i in range (25):
 
130
      zs [0:50, i:i + 1] = cphi [i]
 
131
      for j in range (50):
 
132
         xs [j, i] = sphi [i] * ctheta [j]
 
133
         ys [j, i] = sphi [i] * stheta [j]
 
134
   hx = xs  / 1.6
 
135
   hy = ys / 1.6
 
136
   hz = zs / 1.6
 
137
   # Plot a sphere with a random distribution of colors
 
138
   s1.new (mask = "sort", opt_3d = "s4", x = hx, y = hy, z = zs,
 
139
           c = rand (50, 25)) # ranf (zs))
 
140
   g1.replace ( 1, s1 )
 
141
   g1.change_plot (titles = "Randomly colored sphere", send = 1)
 
142
   paws ()
 
143
   s1 = Surface (mask = "sort", opt_3d = "s4", x = hx, y = hy,
 
144
                 z = zs, c = rand (50, 25))
 
145
   ##m1 = Mesh3d (color_card = "random", opt_3d = "f4", mask = "min",
 
146
   ##             x = array ( [0.5, 1.2, 1.4, 1.05], Float),
 
147
   ##             y = array ( [1.2, 0.5, 1.4, 1.05], Float),
 
148
   ##             z = array ( [0., 0., 0., 1.2], Float),
 
149
   ##             c = array ( [0.4, 0.6, 0.6, 0.6], Float),
 
150
   ##             avs = 1, tet = [ 1, array ([[3,0,1,2]],Int) ])
 
151
   m1 = Slice (array ( [3, 3, 3, 3], Int),
 
152
               array ( [
 
153
                        [0.5, 1.2, 0.], [1.2, 0.5, 0.], [1.4, 1.4, 0.],
 
154
                        [0.5, 1.2, 0.], [1.4, 1.4, 0.], [1.05, 1.05, 1.2],
 
155
                        [0.5, 1.2, 0.], [1.05, 1.05, 1.2], [1.2, 0.5, 0.],
 
156
                        [1.2, 0.5, 0.], [1.05, 1.05, 1.2], [1.4, 1.4, 0.]
 
157
                     ] ), array ( [0.4, 0.5, 0.6, 0.7], Float))
 
158
   g1.new ([s1, m1], link = 1,
 
159
                   titles = "Randomly colored sphere and solid tetrahedron",
 
160
                   axis_limits = [[-0.62, 1.4],
 
161
                   [-0.62, 1.4], [-1.0, 1.5]],
 
162
                   send = 1, y_factor = 2.0) # phi = 55, theta = 30,
 
163
   g1.plot ( )
 
164
   #pl.set_color_card (8) #random
 
165
   #pl.set_3d_options ("f4") #flat 4d
 
166
   #pl.set_grid_type ("none") #don't redraw axes
 
167
   # Note to myself: When the mesh plotter is done, use it for the
 
168
   # following. Python should never call a plotter directly.
 
169
   #pl.plot_surface (array ( [0.5, 1.2, 1.4, 1.05], Float),
 
170
   #                 array ( [1.2, 0.5, 1.4, 1.05], Float),
 
171
   #                 array ( [0., 0., 0., 1.2], Float),
 
172
   #                 array ( [0.4, 0.6, 0.6, 0.6], Float),
 
173
   #                 array ( [3, 6, 9, 12, 1, 2, 3, 0, 2,
 
174
   #                          3, 0, 1, 3, 0, 1, 2], Int), 4)
 
175
   #pl.send_graph ()
 
176
   paws ()
 
177
   s1 = Surface ( mask = "sort", opt_3d = "s4", x = xs, y = ys,
 
178
                  z = zs + 2., c = zs)
 
179
   s2 = Surface ( mask = "sort", opt_3d = "wm", x = hx, y = hy, z = hz, c = zs)
 
180
   # g1.replace (1, s1)
 
181
   # g1.add ( s2 )
 
182
   # g1.change_plot ( link = 1 , titles = "Imploding Sphere in R3",
 
183
   #                  phi = 70.0, theta = 30.0,
 
184
   #                  axis_limits  =  [[-1., 1.], [-1., 1.], [-0.7, 3.0]])
 
185
   g1.new ( [s1, s2], link = 1 , titles = "Two Spheres in R3",
 
186
                      axis_limits  =  [[-1., 1.], [-1., 1.], [-0.7, 3.0]],
 
187
                      x_factor = 1.7)
 
188
   ##                 phi = 70.0, theta = 30.0,
 
189
   g1.plot ( )