# HG changeset patch
# User Ethan Van Andel <evlutte@gmail.com>
# Date 1380754870 25200
# Node ID 6fbf9dd16ed9123e03a8cae3cfa65d822a72601a
# Parent 2f249b4f15186cceca466320167acaa48d74eda2
Trac 11273: Added min_mag arg to plot_spiderweb. Added 2 new doctests.
diff git a/sage/calculus/riemann.pyx b/sage/calculus/riemann.pyx
a

b


170  170  sage: print "error =", m.inverse_riemann_map(m.riemann_map(x))  x # long time 
171  171  error = (0.000...+0.0016...j) 
172  172  
 173  A fun, complex region for demonstration purposes 
 174  sage: f(t) = e^(I*t) 
 175  sage: fp(t) = I*e^(I*t) 
 176  sage: ef1(t) = .2*e^(I*t) +.4+.4*I 
 177  sage: ef1p(t) = I*.2*e^(I*t) 
 178  sage: ef2(t) = .2*e^(I*t) .4+.4*I 
 179  sage: ef2p(t) = I*.2*e^(I*t) 
 180  sage: pts = [(.5,.1520/1000),(.6,.2710/1000),(.45,.45),(0,.65+10/1000),(.45,.45),(.6,.2710/1000),(.5,.1510/1000),(0,.43+10/1000)] 
 181  sage: pts.reverse() 
 182  sage: cs = complex_cubic_spline(pts) 
 183  sage: mf = lambda x:cs.value(x) 
 184  sage: mfprime = lambda x: cs.derivative(x) 
 185  sage: m = Riemann_Map([f,ef1,ef2,mf],[fp,ef1p,ef2p,mfprime],0,N = 400) # long time 
 186  sage: p = m.plot_colored(plot_points = 400) # long time 
 187  
173  188  ALGORITHM: 
174  189  
175  190  This class computes the Riemann Map via the Szego kernel using an 
… 
… 

820  835  @options(interpolation='catrom') 
821  836  def plot_spiderweb(self, spokes=16, circles=4, pts=32, linescale=0.99, 
822  837  rgbcolor=[0,0,0], thickness=1, plotjoined=True, withcolor = False, 
823   plot_points = 200, **options): 
 838  plot_points = 200, min_mag = 0.001, **options): 
824  839  """ 
825  840  Generates a traditional "spiderweb plot" of the Riemann map. Shows 
826  841  what concentric circles and radial lines map to. The radial lines 
… 
… 

875  890  Note that very large values can cause this function to run slowly. 
876  891   only for multiply connected domains 
877  892  
 893   ``min_mag``  float (default: ``0.001``) The magnitude cutoff 
 894  below which spiderweb points are not drawn. This only applies 
 895  to multiply connected domains and is designed to prevent 
 896  "fuzz" at the edge of the domain. Some complicated multiply 
 897  connected domains (particularly those with corners) may 
 898  require a larger value to look clean outside. 
 899  
878  900  EXAMPLES: 
879  901  
880  902  General usage:: 
… 
… 

902  924  sage: fprime(t) = I*e^(I*t) 
903  925  sage: m = Riemann_Map([f], [fprime], 0, 1000) 
904  926  sage: m.plot_spiderweb() 
 927  
 928  A multiply connected region with corners. We set min_mag higher 
 929  to remove "fuzz" outside the domain. 
 930  
 931  sage: ps = polygon_spline([(4,2),(4,2),(4,2),(4,2)]) 
 932  sage: z1 = lambda t: ps.value(t); z1p = lambda t: ps.derivative(t) 
 933  sage: z2(t) = 2+exp(I*t); z2p(t) = I*exp(I*t) 
 934  sage: z3(t) = 2+exp(I*t); z3p(t) = I*exp(I*t) 
 935  sage: m = Riemann_Map([z1,z2,z3],[z1p,z2p,z3p],0,ncorners=4) # long time 
 936  sage: p = m.plot_spiderweb(withcolor=True,plot_points=500, thickness = 2.0, min_mag=0.1) # long time 
905  937  """ 
906  938  cdef int k, i 
907  939  if self.exterior: 
… 
… 

960  992  
961  993  g = Graphics() 
962  994  g.add_primitive(ComplexPlot(complex_to_spiderweb(z_values,dr,dtheta, 
963   spokes, circles, rgbcolor,thickness, withcolor), 
 995  spokes, circles, rgbcolor,thickness, withcolor, min_mag), 
964  996  (xmin, xmax), (ymin, ymax),options)) 
965  997  return g + self.plot_boundaries(thickness = thickness) 
966  998  
… 
… 

1104  1136  
1105  1137  cpdef complex_to_spiderweb(np.ndarray[COMPLEX_T, ndim = 2] z_values, 
1106  1138  np.ndarray[FLOAT_T, ndim = 2] dr, np.ndarray[FLOAT_T, ndim = 2] dtheta, 
1107   spokes, circles, rgbcolor, thickness, withcolor): 
 1139  spokes, circles, rgbcolor, thickness, withcolor, min_mag): 
1108  1140  """ 
1109  1141  Converts a grid of complex numbers into a matrix containing rgb data 
1110  1142  for the Riemann spiderweb plot. 
… 
… 

1133  1165   ``withcolor``  boolean  If ``True`` the spiderweb will be overlaid 
1134  1166  on the basic color plot. 
1135  1167  
 1168   ``min_mag``  float  The magnitude cutoff below which spiderweb 
 1169  points are not drawn. This only applies to multiply connected 
 1170  domains and is designed to prevent "fuzz" at the edge of the 
 1171  domain. Some complicated multiply connected domains (particularly 
 1172  those with corners) may require a larger value to look clean 
 1173  outside. 
 1174  
1136  1175  OUTPUT: 
1137  1176  
1138  1177  An `N x M x 3` floating point Numpy array ``X``, where 
… 
… 

1144  1183  sage: import numpy 
1145  1184  sage: zval = numpy.array([[0, 1, 1000],[.2+.3j,1,.3j],[0,0,0]],dtype = numpy.complex128) 
1146  1185  sage: deriv = numpy.array([[.1]],dtype = numpy.float64) 
1147   sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,False) 
 1186  sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,False,0.001) 
1148  1187  array([[[ 1., 1., 1.], 
1149  1188  [ 1., 1., 1.], 
1150  1189  [ 1., 1., 1.]], 
… 
… 

1157  1196  [ 1., 1., 1.], 
1158  1197  [ 1., 1., 1.]]]) 
1159  1198  
1160   sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,True) 
 1199  sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,True,0.001) 
1161  1200  array([[[ 1. , 1. , 1. ], 
1162  1201  [ 1. , 0.05558355, 0.05558355], 
1163  1202  [ 0.17301243, 0. , 0. ]], 
… 
… 

1174  1213  cdef FLOAT_T x, y, mag, arg, width, target, precision, dmag, darg 
1175  1214  cdef COMPLEX_T z 
1176  1215  cdef FLOAT_T DMAX = 70 # change to adjust rate_of_change cutoff below 
1177   cdef FLOAT_T MMIN = .0001 
1178  1216  precision = thickness/150.0 
1179  1217  imax = len(z_values) 
1180  1218  jmax = len(z_values[0]) 
… 
… 

1202  1240  darg = dtheta[i,j] 
1203  1241  #points that change too rapidly are presumed to be borders 
1204  1242  #points that are too small are presumed to be outside 
1205   if darg < DMAX and mag > MMIN: 
 1243  if darg < DMAX and mag > min_mag: 
1206  1244  for target in circ_radii: 
1207  1245  if abs(mag  target)/dmag < precision: 
1208  1246  rgb[i+1,j+1] = rgbcolor 