Ticket #11273: trac_11273_multi_web_fix-review.patch

File trac_11273_multi_web_fix-review.patch, 6.2 KB (added by kcrisman, 8 years ago)
  • sage/calculus/riemann.pyx

    # HG changeset patch
    # User Ethan Van Andel <evlutte@gmail.com>
    # Date 1380754870 25200
    # Node ID dee2120e661936686d905b898d489c7a059689c6
    # Parent  43472cb48c476134f1270c394f8201f806199ed6
    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  
    170170        sage: print "error =", m.inverse_riemann_map(m.riemann_map(x)) - x  # long time
    171171        error = (-0.000...+0.0016...j)
    172172
     173    A fun, complex region for demonstration purposes::
     174
     175        sage: f(t) = e^(I*t)
     176        sage: fp(t) = I*e^(I*t)
     177        sage: ef1(t) = .2*e^(-I*t) +.4+.4*I
     178        sage: ef1p(t) = -I*.2*e^(-I*t)
     179        sage: ef2(t) = .2*e^(-I*t) -.4+.4*I
     180        sage: ef2p(t) = -I*.2*e^(-I*t)
     181        sage: pts = [(-.5,-.15-20/1000),(-.6,-.27-10/1000),(-.45,-.45),(0,-.65+10/1000),(.45,-.45),(.6,-.27-10/1000),(.5,-.15-10/1000),(0,-.43+10/1000)]
     182        sage: pts.reverse()
     183        sage: cs = complex_cubic_spline(pts)
     184        sage: mf = lambda x:cs.value(x)
     185        sage: mfprime = lambda x: cs.derivative(x)
     186        sage: m = Riemann_Map([f,ef1,ef2,mf],[fp,ef1p,ef2p,mfprime],0,N = 400) # long time
     187        sage: p = m.plot_colored(plot_points = 400) # long time
     188
    173189    ALGORITHM:
    174190
    175191    This class computes the Riemann Map via the Szego kernel using an
     
    820836    @options(interpolation='catrom')
    821837    def plot_spiderweb(self, spokes=16, circles=4, pts=32, linescale=0.99,
    822838            rgbcolor=[0,0,0], thickness=1, plotjoined=True, withcolor = False,
    823             plot_points = 200, **options):
     839            plot_points = 200, min_mag = 0.001, **options):
    824840        """
    825841        Generates a traditional "spiderweb plot" of the Riemann map. Shows
    826842        what concentric circles and radial lines map to. The radial lines
     
    875891          Note that very large values can cause this function to run slowly.
    876892          - only for multiply connected domains
    877893
     894        - ``min_mag`` -- float (default: ``0.001``) The magnitude cutoff
     895          below which spiderweb points are not drawn. This only applies
     896          to multiply connected domains and is designed to prevent
     897          "fuzz" at the edge of the domain. Some complicated multiply
     898          connected domains (particularly those with corners) may
     899          require a larger value to look clean outside.
     900
    878901        EXAMPLES:
    879902
    880903        General usage::
     
    902925            sage: fprime(t) = I*e^(I*t)
    903926            sage: m = Riemann_Map([f], [fprime], 0, 1000)
    904927            sage: m.plot_spiderweb()
     928
     929        A multiply connected region with corners. We set ``min_mag`` higher
     930        to remove "fuzz" outside the domain::
     931
     932            sage: ps = polygon_spline([(-4,-2),(4,-2),(4,2),(-4,2)])
     933            sage: z1 = lambda t: ps.value(t); z1p = lambda t: ps.derivative(t)
     934            sage: z2(t) = -2+exp(-I*t); z2p(t) = -I*exp(-I*t)
     935            sage: z3(t) = 2+exp(-I*t); z3p(t) = -I*exp(-I*t)
     936            sage: m = Riemann_Map([z1,z2,z3],[z1p,z2p,z3p],0,ncorners=4) # long time
     937            sage: p = m.plot_spiderweb(withcolor=True,plot_points=500, thickness = 2.0, min_mag=0.1) # long time
    905938        """
    906939        cdef int k, i
    907940        if self.exterior:
     
    960993
    961994            g = Graphics()
    962995            g.add_primitive(ComplexPlot(complex_to_spiderweb(z_values,dr,dtheta,
    963                 spokes, circles, rgbcolor,thickness, withcolor),
     996                spokes, circles, rgbcolor,thickness, withcolor, min_mag),
    964997                (xmin, xmax), (ymin, ymax),options))
    965998            return g + self.plot_boundaries(thickness = thickness)
    966999
     
    11041137
    11051138cpdef complex_to_spiderweb(np.ndarray[COMPLEX_T, ndim = 2] z_values,
    11061139    np.ndarray[FLOAT_T, ndim = 2] dr, np.ndarray[FLOAT_T, ndim = 2] dtheta,
    1107     spokes, circles, rgbcolor, thickness, withcolor):
     1140    spokes, circles, rgbcolor, thickness, withcolor, min_mag):
    11081141    """
    11091142    Converts a grid of complex numbers into a matrix containing rgb data
    11101143    for the Riemann spiderweb plot.
     
    11331166    - ``withcolor`` -- boolean - If ``True`` the spiderweb will be overlaid
    11341167      on the basic color plot.
    11351168
     1169    - ``min_mag`` -- float - The magnitude cutoff below which spiderweb
     1170      points are not drawn. This only applies to multiply connected
     1171      domains and is designed to prevent "fuzz" at the edge of the
     1172      domain. Some complicated multiply connected domains (particularly
     1173      those with corners) may require a larger value to look clean
     1174      outside.
     1175
    11361176    OUTPUT:
    11371177
    11381178    An `N x M x 3` floating point Numpy array ``X``, where
     
    11441184        sage: import numpy
    11451185        sage: zval = numpy.array([[0, 1, 1000],[.2+.3j,1,-.3j],[0,0,0]],dtype = numpy.complex128)
    11461186        sage: deriv = numpy.array([[.1]],dtype = numpy.float64)
    1147         sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,False)
     1187        sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,False,0.001)
    11481188        array([[[ 1.,  1.,  1.],
    11491189                [ 1.,  1.,  1.],
    11501190                [ 1.,  1.,  1.]],
     
    11571197                [ 1.,  1.,  1.],
    11581198                [ 1.,  1.,  1.]]])
    11591199
    1160         sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,True)
     1200        sage: complex_to_spiderweb(zval, deriv,deriv, 4,4,[0,0,0],1,True,0.001)
    11611201        array([[[ 1.        ,  1.        ,  1.        ],
    11621202                [ 1.        ,  0.05558355,  0.05558355],
    11631203                [ 0.17301243,  0.        ,  0.        ]],
     
    11741214    cdef FLOAT_T x, y, mag, arg, width, target, precision, dmag, darg
    11751215    cdef COMPLEX_T z
    11761216    cdef FLOAT_T DMAX = 70 # change to adjust rate_of_change cutoff below
    1177     cdef FLOAT_T MMIN = .0001
    11781217    precision = thickness/150.0
    11791218    imax = len(z_values)
    11801219    jmax = len(z_values[0])
     
    12021241            darg = dtheta[i,j]
    12031242            #points that change too rapidly are presumed to be borders
    12041243            #points that are too small are presumed to be outside
    1205             if darg < DMAX and mag > MMIN:
     1244            if darg < DMAX and mag > min_mag:
    12061245                for target in circ_radii:
    12071246                    if abs(mag - target)/dmag < precision:
    12081247                        rgb[i+1,j+1] = rgbcolor