Ticket #11273: trac_11273-reviewer.patch

File trac_11273-reviewer.patch, 31.2 KB (added by kcrisman, 8 years ago)
  • sage/calculus/riemann.pyx

    # HG changeset patch
    # User Karl-Dieter Crisman <kcrisman@gmail.com>
    # Date 1337993071 14400
    # Node ID 4253cee9001cbd6d8476d6a6293a12a98d6ccc3b
    # Parent  1f9aeedfb653ac789d45ce55c14704d8ae97e3e9
    Trac 11273 reviewer patch
    
    Lots of whitespace removal and fixing documentation issues
    
    diff --git a/sage/calculus/riemann.pyx b/sage/calculus/riemann.pyx
    a b  
    7272
    7373cdef class Riemann_Map:
    7474    """
    75    
    76     The ``Riemann_Map`` class computes an interior or exterior Riemann map, 
    77     or an Ahlfors map of a region given by the supplied boundary curve(s) 
    78     and center ' point. The class also provides various methods to
     75
     76    The ``Riemann_Map`` class computes an interior or exterior Riemann map,
     77    or an Ahlfors map of a region given by the supplied boundary curve(s)
     78    and center point. The class also provides various methods to
    7979    evaluate, visualize, or extract data from the map.
    80    
     80
    8181    A Riemann map conformally maps a simply connected region in
    8282    the complex plane to the unit disc. The Ahlfors map does the same thing
    8383    for multiply connected regions.
    84    
    85     Note that all the methods are numerical. As a result all answers have 
    86     some imprecision. Moreover, maps computed with small number of 
    87     collocation points, or for unusually shaped regions may be very
    88     inaccurate. Error computations for the ellipse can be found in the 
    89     documentation for ``analytic_boundary()`` and ``analytic_interior()``.
    90    
    91     [BSV] provides an overview of the Riemann map and discusses the research
     84
     85    Note that all the methods are numerical. As a result all answers have
     86    some imprecision. Moreover, maps computed with small number of
     87    collocation points, or for unusually shaped regions, may be very
     88    inaccurate. Error computations for the ellipse can be found in the
     89    documentation for :meth:`analytic_boundary` and :meth:`analytic_interior`.
     90
     91    [BSV]_ provides an overview of the Riemann map and discusses the research
    9292    that lead to the creation of this module.
    9393
    9494    INPUT:
     
    111111    - ``N`` -- integer (default: ``500``), the number of collocation points
    112112      used to compute the map. More points will give more accurate results,
    113113      especially near the boundaries, but will take longer to compute.
    114    
     114
    115115    - ``exterior`` -- boolean (default: ``False``), if set to ``True``, the
    116116      exterior map will be computed, mapping the exterior of the region to the
    117117      exterior of the unit circle.
    118    
    119     The following inputs may be passed as named parameters in unusual 
     118
     119    The following inputs may be passed as named parameters in unusual
    120120    circumstances:
    121    
     121
    122122    - ``ncorners`` -- integer (default: ``4``), if mapping a figure with
    123       (equally t-spaced) corners--corners that make a significant change in
    124       the direction of the boundary, better results may be sometimes obtained by
     123      (equally t-spaced) corners -- corners that make a significant change in
     124      the direction of the boundary -- better results may be sometimes obtained by
    125125      accurately giving this parameter. Used to add the proper constant to
    126126      the theta correspondence function.
    127127
    128128    - ``opp`` -- boolean (default: ``False``), set to ``True`` in very rare
    129129      cases where the theta correspondence function is off by ``pi``, that
    130130      is, if red is mapped left of the origin in the color plot.
    131      
     131
    132132
    133133    EXAMPLES:
    134134
     
    145145        sage: hf(t) = 0.5*e^(-I*t)
    146146        sage: hfprime(t) = 0.5*-I*e^(-I*t)
    147147        sage: m = Riemann_Map([f, hf], [fprime, hfprime], 0.5 + 0.5*I)
     148        sage: m.plot_colored() + m.plot_spiderweb()  # long time
    148149
    149150    A square::
    150151
    151         sage: ps = polygon_spline([(-1, -1), (1, -1), (1, 1), (-1, 1)])  # long time
    152         sage: f = lambda t: ps.value(real(t))  # long time
    153         sage: fprime = lambda t: ps.derivative(real(t))  # long time
    154         sage: m = Riemann_Map([f], [fprime], 0.25, ncorners=4)  # long time
     152        sage: ps = polygon_spline([(-1, -1), (1, -1), (1, 1), (-1, 1)])
     153        sage: f = lambda t: ps.value(real(t))
     154        sage: fprime = lambda t: ps.derivative(real(t))
     155        sage: m = Riemann_Map([f], [fprime], 0.25, ncorners=4)
    155156        sage: m.plot_colored() + m.plot_spiderweb()  # long time
    156157
    157158    Compute rough error for this map::
     
    170171    .. [KT] N. Kerzman and M. R. Trummer. "Numerical Conformal Mapping via
    171172      the Szego kernel". Journal of Computational and Applied Mathematics,
    172173      14(1-2): 111--123, 1986.
    173    
    174     .. [BSV] M. Bolt, S. Snoeyink, E. Van Andel. "Visual representation of 
    175       the Riemann map and Ahlfors map via the Kerzman-Stein equation". 
     174
     175    .. [BSV] M. Bolt, S. Snoeyink, E. Van Andel. "Visual representation of
     176      the Riemann map and Ahlfors map via the Kerzman-Stein equation".
    176177      Involve 3-4 (2010), 405-420.
     178
    177179    """
    178180    cdef int N, B, ncorners
    179181    cdef f
     
    185187    cdef x_range, y_range
    186188    cdef exterior
    187189
    188     def __init__(self, fs, fprimes, COMPLEX_T a, int N=500, int ncorners=4, 
     190    def __init__(self, fs, fprimes, COMPLEX_T a, int N=500, int ncorners=4,
    189191        opp=False, exterior = False):
    190        
     192
    191193        """
    192         Initializes the ``Riemann_Map`` class. See the class ``Riemann_Map``
     194        Initializes the ``Riemann_Map`` class. See the class :class:`Riemann_Map`
    193195        for full documentation on the input of this initialization method.
    194196
    195197        TESTS::
     
    226228        if exterior and (self.B > 1):
    227229            raise ValueError(
    228230                "The exterior map is undefined for multiply connected domains")
    229         cdef np.ndarray[COMPLEX_T,ndim=2] cps = np.zeros([self.B, N], 
     231        cdef np.ndarray[COMPLEX_T,ndim=2] cps = np.zeros([self.B, N],
    230232            dtype=COMPLEX)
    231         cdef np.ndarray[COMPLEX_T,ndim=2] dps = np.zeros([self.B, N], 
     233        cdef np.ndarray[COMPLEX_T,ndim=2] dps = np.zeros([self.B, N],
    232234            dtype=COMPLEX)
    233235        # Find the points on the boundaries and their derivatives.
    234236        if self.exterior:
     
    266268
    267269    def _repr_(self):
    268270        """
    269         Return a string representation of this ``Riemann_Map`` object.
     271        Return a string representation of this :class:`Riemann_Map` object.
    270272
    271273        TESTS::
    272            
     274
    273275            sage: f(t) = e^(I*t) - 0.5*e^(-I*t)
    274276            sage: fprime(t) = I*e^(I*t) + 0.5*I*e^(-I*t)
    275277            sage: isinstance(Riemann_Map([f], [fprime], 0, N = 10)._repr_(), str)  # long time
    276278            True
    277279        """
    278         return "A Riemann or Alfohrs mapping of a figure to the unit circle."
     280        return "A Riemann or Ahlfors mapping of a figure to the unit circle."
    279281
    280282    cdef _generate_theta_array(self):
    281283        """
     
    317319        for i in xrange(NB):
    318320            K[i, i] = 1
    319321        # Nystrom Method for solving 2nd kind integrals
    320         phi = np.linalg.solve(K, g) / NB * TWOPI  # Nystrom Method for solving 2nd kind integrals
     322        phi = np.linalg.solve(K, g) / NB * TWOPI
    321323        # the all-important Szego kernel
    322324        szego = np.array(phi.flatten() / np.sqrt(dp), dtype=COMPLEX)
    323325        self.szego = szego.reshape([B, N])
     
    370372        The following inputs must all be passed in as named parameters:
    371373
    372374        - ``boundary`` -- integer (default: ``-1``) if < 0,
    373           ``get_theta_points()`` will return the points for all boundaries.
    374           If >= 0, ``get_theta_points()`` will return only the points for
     375          :meth:`get_theta_points` will return the points for all boundaries.
     376          If >= 0, :meth:`get_theta_points` will return only the points for
    375377          the boundary specified.
    376378
    377379        - ``absolute_value`` -- boolean (default: ``False``) if ``True``, will
     
    437439        Returns an array of points of the form
    438440        ``[t value, theta in e^(I*theta)]``, that is, a discretized version
    439441        of the theta/boundary correspondence function. In other words, a point
    440         in this array [t1, t2] represents that the boundary point given by f(t1) 
     442        in this array [t1, t2] represents that the boundary point given by f(t1)
    441443        is mapped to a point on the boundary of the unit circle given by e^(I*t2).
    442        
    443         For multiply connected domains, ``get_theta_points`` will list the 
     444
     445        For multiply connected domains, ``get_theta_points`` will list the
    444446        points for each boundary in the order that they were supplied.
    445447
    446448        INPUT:
     
    470472        Extending the points by a spline::
    471473
    472474            sage: s = spline(points)
    473             sage: s(3*pi / 4) 
     475            sage: s(3*pi / 4)
    474476            1.627660...
    475477
    476478        The unit circle with a small hole::
     
    498500
    499501    cdef _generate_interior_mapper(self):
    500502        """
    501         Generates the data necessary to use the ``riemann_map`` function.
    502         As much setup as possible is done here to minimize the computation 
     503        Generates the data necessary to use the :meth:`riemann_map` function.
     504        As much setup as possible is done here to minimize the computation
    503505        that must be done in ``riemann_map``.
    504506
    505507        TESTS::
    506508
    507509            sage: f(t) = e^(I*t) - 0.5*e^(-I*t)
    508510            sage: fprime(t) = I*e^(I*t) + 0.5*I*e^(-I*t)
    509             sage: m = Riemann_Map([f], [fprime], 0, N = 10)
     511            sage: m = Riemann_Map([f], [fprime], 0, N = 10) # indirect doctest
    510512        """
    511513        cdef int N = self.N
    512514        cdef double complex coeff = 3*I / (8*N)
     
    556558        the point on the unit disk that ``pt`` maps to. Note that this
    557559        method only works for interior points; accuracy breaks down very close
    558560        to the boundary. To get boundary corrospondance, use
    559         ``get_theta_points()``.
     561        :meth:`get_theta_points`.
    560562
    561563        INPUT:
    562564
     
    577579            sage: m = Riemann_Map([f], [fprime], 0)
    578580            sage: m.riemann_map(0.25 + sqrt(-0.5))
    579581            (0.137514...+0.876696...j)
     582            sage: I = CDF.gen()
    580583            sage: m.riemann_map(1.3*I)
    581584            (-1.56...e-05+0.989694...j)
    582             sage: I = CDF.gen()
    583585            sage: m.riemann_map(0.4)
    584586            (0.73324...+3.2...e-06j)
    585587            sage: import numpy as np
    586588            sage: m.riemann_map(np.complex(-3, 0.0001))
    587589            (1.405757...e-05+8.06...e-10j)
    588590        """
    589    
     591
    590592        cdef COMPLEX_T pt1
    591593        cdef np.ndarray[COMPLEX_T, ndim=1] q_vector
    592594        if self.exterior:
     
    603605    cdef _generate_inverse_mapper(self):
    604606        """
    605607        Generates the data necessary to use the
    606         ``inverse_riemann_map()`` function. As much setup as possible is
    607         done here to minimize the computation that must be done in 
    608         ``inverse_riemann_map()``.
     608        :meth:`inverse_riemann_map` function. As much setup as possible is
     609        done here to minimize the computation that must be done in
     610        ``inverse_riemann_map``.
    609611
    610612        TESTS::
    611613
    612614            sage: f(t) = e^(I*t) - 0.5*e^(-I*t)
    613615            sage: fprime(t) = I*e^(I*t) + 0.5*I*e^(-I*t)
    614             sage: m = Riemann_Map([f], [fprime], 0, N = 10)
     616            sage: m = Riemann_Map([f], [fprime], 0, N = 10) # indirect doctest
    615617        """
    616618        cdef int N = self.N
    617619        cdef int B = self.B
     
    640642    cpdef inverse_riemann_map(self, COMPLEX_T pt):
    641643        """
    642644        Returns the inverse Riemann mapping of a point. That is, given ``pt``
    643         on the interior of the unit disc, ``inverse_riemann_map()`` will 
    644         return the point on the original region that would be Riemann 
    645         mapped to ``pt``. Note that this method does not work for multiply 
     645        on the interior of the unit disc, ``inverse_riemann_map()`` will
     646        return the point on the original region that would be Riemann
     647        mapped to ``pt``. Note that this method does not work for multiply
    646648        connected domains.
    647649
    648650        INPUT:
     
    729731        """
    730732        plots = range(self.B)
    731733        for k in xrange(self.B):
    732             # This conditional should be eliminated when the thickness/pointsize 
     734            # This conditional should be eliminated when the thickness/pointsize
    733735            # issue is resolved later. Same for the others in plot_spiderweb().
    734736            if plotjoined:
    735737                plots[k] = list_plot(
     
    740742                    comp_pt(self.cps[k], 1), rgbcolor=rgbcolor,
    741743                    pointsize=thickness)
    742744        return sum(plots)
    743        
    744    
     745
     746
    745747    cpdef compute_on_grid(self, plot_range, int x_points):
    746748        """
    747749        Computes the riemann map on a grid of points. Note that these points
    748750        are complex of the form z = x + y*i.
    749        
     751
    750752        INPUT:
    751        
    752         - ``plot_range`` -- a tuple of the form [xmin, xmax, ymin, ymax].
    753           If the value is ``[]``, the default plotting window of the map will 
     753
     754        - ``plot_range`` -- a tuple of the form ``[xmin, xmax, ymin, ymax]``.
     755          If the value is ``[]``, the default plotting window of the map will
    754756          be used.
    755          
     757
    756758        - ``x_points`` -- int, the size of the grid in the x direction
    757759          The number of points in the y_direction is scaled accordingly
    758        
     760
    759761        OUTPUT:
    760        
    761         - a tuple containing [z_values, xmin, xmax, ymin, ymax] where z_values
    762           is the evaluation of the map on the specified grid.
    763            
     762
     763        - a tuple containing ``[z_values, xmin, xmax, ymin, ymax]``
     764          where ``z_values`` is the evaluation of the map on the specified grid.
     765
    764766        EXAMPLES:
    765767
    766768        General usage::
     
    804806                    pt = xmin + 0.5*xstep + i*xstep + I*(ymin + 0.5*ystep + j*ystep)
    805807                    z_values[j, i] = -np.dot(p_vector,1/(pre_q_vector - pt))
    806808        return z_values, xmin, xmax, ymin, ymax
    807        
    808        
     809
     810
    809811    @options(interpolation='catrom')
    810812    def plot_spiderweb(self, spokes=16, circles=4, pts=32, linescale=0.99,
    811813            rgbcolor=[0,0,0], thickness=1, plotjoined=True, withcolor = False,
    812814            plot_points = 200, **options):
    813815        """
    814         Generates a traditional "spiderweb plot" of the Riemann map. Shows 
    815         what concentric circles and radial lines map to. The radial lines 
    816         may exhibit erratic behavior near the boundary, if this occurs,
     816        Generates a traditional "spiderweb plot" of the Riemann map. Shows
     817        what concentric circles and radial lines map to. The radial lines
     818        may exhibit erratic behavior near the boundary; if this occurs,
    817819        decreasing ``linescale`` may mitigate the problem.
    818        
    819         Note that this method requires significantly more computation for 
     820
     821        Note that this method requires significantly more computation for
    820822        multiply connected domains.
    821823
    822824        INPUT:
     
    852854
    853855        - ``withcolor`` -- boolean (default: ``False``) If ``True``,
    854856          The spiderweb will be overlaid on the basic color plot.
    855          
     857
    856858        - ``plot_points`` -- integer (default: ``200``) the size of the grid in the x direction
    857           The number of points in the y_direction is scaled accordingly. 
     859          The number of points in the y_direction is scaled accordingly.
    858860          Note that very large values can cause this function to run slowly.
    859861          - only for multiply connected domains
     862
    860863        EXAMPLES:
    861864
    862865        General usage::
     
    886889            sage: m.plot_spiderweb()
    887890        """
    888891        cdef int k, i
    889         if self.B == 1: #The efficient simply connected 
    890             edge = self.plot_boundaries(plotjoined=plotjoined, 
     892        if self.B == 1: #The efficient simply connected
     893            edge = self.plot_boundaries(plotjoined=plotjoined,
    891894                rgbcolor=rgbcolor, thickness=thickness)
    892895            circle_list = range(circles)
    893896            theta_array = self.theta_array[0]
     
    900903                    temp[i] = self.inverse_riemann_map(
    901904                        (k + 1) / (circles + 1.0) * exp(I*i * TWOPI / (2*pts)))
    902905                if plotjoined:
    903                     circle_list[k] = list_plot(comp_pt(temp, 1), 
     906                    circle_list[k] = list_plot(comp_pt(temp, 1),
    904907                        rgbcolor=rgbcolor, thickness=thickness, plotjoined=True)
    905908                else:
    906                     circle_list[k] = list_plot(comp_pt(temp, 1), 
     909                    circle_list[k] = list_plot(comp_pt(temp, 1),
    907910                        rgbcolor=rgbcolor, pointsize=thickness)
    908911            line_list = range(spokes)
    909912            for k in xrange(spokes):
     
    931934            else:
    932935                return edge + sum(circle_list) + sum(line_list)
    933936        else: # The more difficult multiply connected
    934             z_values, xmin, xmax, ymin, ymax = self.compute_on_grid([], 
     937            z_values, xmin, xmax, ymin, ymax = self.compute_on_grid([],
    935938                plot_points)
    936939            xstep = (xmax-xmin)/plot_points
    937940            ystep = (ymax-ymin)/plot_points
    938941            dr, dtheta= get_derivatives(z_values, xstep, ystep) # clean later
    939            
     942
    940943            g = Graphics()
    941             g.add_primitive(ComplexPlot(complex_to_spiderweb(z_values,dr,dtheta, 
    942                 spokes, circles, rgbcolor,thickness, withcolor), 
     944            g.add_primitive(ComplexPlot(complex_to_spiderweb(z_values,dr,dtheta,
     945                spokes, circles, rgbcolor,thickness, withcolor),
    943946                (xmin, xmax), (ymin, ymax),options))
    944947            return g + self.plot_boundaries(thickness = thickness)
    945            
     948
    946949
    947950    @options(interpolation='catrom')
    948951    def plot_colored(self, plot_range=[], int plot_points=100, **options):
     
    958961          ``(xmin, xmax, ymin, ymax)``. Declare if you do not want the plot
    959962          to use the default range for the figure.
    960963
    961         - ``plot_points`` -- integer (default: ``100``), number of points to 
    962           plot in the x direction. Points in the y direction are scaled 
    963           accordingly. Note that very large values can cause this function to 
     964        - ``plot_points`` -- integer (default: ``100``), number of points to
     965          plot in the x direction. Points in the y direction are scaled
     966          accordingly. Note that very large values can cause this function to
    964967          run slowly.
    965          
     968
    966969
    967970        EXAMPLES:
    968971
     
    983986
    984987        To generate the unit circle map, it's helpful to see what the
    985988        colors correspond to::
    986        
     989
    987990            sage: f(t) = e^(I*t)
    988991            sage: fprime(t) = I*e^(I*t)
    989992            sage: m = Riemann_Map([f], [fprime], 0, 1000)
    990993            sage: m.plot_colored()
    991994        """
    992         z_values, xmin, xmax, ymin, ymax = self.compute_on_grid(plot_range, 
     995        z_values, xmin, xmax, ymin, ymax = self.compute_on_grid(plot_range,
    993996            plot_points)
    994997        g = Graphics()
    995         g.add_primitive(ComplexPlot(complex_to_rgb(z_values), (xmin, xmax), 
     998        g.add_primitive(ComplexPlot(complex_to_rgb(z_values), (xmin, xmax),
    996999            (ymin, ymax),options))
    9971000        return g
    9981001
    9991002cdef comp_pt(clist, loop=True):
    10001003    """
    1001     Converts a list of complex numbers xderivs = get_derivatives(z_values, xstep, ystep)[0]to the plottable
     1004    Utility function to convert the list of complex numbers
     1005    ``xderivs = get_derivatives(z_values, xstep, ystep)[0]`` to the plottable
    10021006    `(x,y)` form. If ``loop=True``, then the first point will be
    10031007    added as the last, i.e. to plot a closed circle.
    10041008
     
    10241028    if loop:
    10251029        list2[len(clist)] = list2[0]
    10261030    return list2
    1027    
    1028 cpdef get_derivatives(np.ndarray[COMPLEX_T, ndim=2]z_values, FLOAT_T xstep,
     1031
     1032cpdef get_derivatives(np.ndarray[COMPLEX_T, ndim=2] z_values, FLOAT_T xstep,
    10291033    FLOAT_T ystep):
    10301034    """
    1031     Computes the r*e^(I*theta) form derivatives from the grid of points. The
    1032     derivatives are computed using quick-and-dirty taylor expansion and 
    1033     assuming analyticy. As such ``get_derivatives`` is primarily intended
    1034     to be used for comparisions in ``plot_spiderweb`` and not for 
     1035    Computes the r*e^(I*theta) form of derivatives from the grid of points. The
     1036    derivatives are computed using quick-and-dirty taylor expansion and
     1037    assuming analyticity. As such ``get_derivatives`` is primarily intended
     1038    to be used for comparisions in ``plot_spiderweb`` and not for
    10351039    applications that require great precision.
    1036    
     1040
    10371041    INPUT:
    1038     - ``z_values`` -- The values for a complex function evaluated on a grid
    1039       in the complexplane, usually from ``compute_on_grid``.
    1040      
     1042
     1043    - ``z_values`` -- The values for a complex function evaluated on a grid
     1044      in the complex plane, usually from ``compute_on_grid``.
     1045
    10411046    - ``xstep`` -- float, the spacing of the grid points in the real direction
    1042    
     1047
    10431048    OUTPUT:
    1044    
    1045     - A tuple of arrays, [``dr``, ``dtheta``], each array is 2 less in both
     1049
     1050    - A tuple of arrays, [``dr``, ``dtheta``], with each array 2 less in both
    10461051      dimensions than ``z_values``
    1047       ``dr`` - the abs of the derivative of the function in the +r direction
    1048       ``dtheta`` - the rate of accumulation of angle in the +theta direction
    1049      
     1052
     1053      - ``dr`` - the abs of the derivative of the function in the +r direction
     1054      - ``dtheta`` - the rate of accumulation of angle in the +theta direction
     1055
    10501056    EXAMPLES:
    1051        
    1052         Standard usage with compute_on_grid::
    1053        
    1054             sage: from sage.calculus.riemann import get_derivatives
    1055             sage: f(t) = e^(I*t) - 0.5*e^(-I*t)
    1056             sage: fprime(t) = I*e^(I*t) + 0.5*I*e^(-I*t)
    1057             sage: m = Riemann_Map([f], [fprime], 0)
    1058             sage: data = m.compute_on_grid([],19)
    1059             sage: xstep = (data[2]-data[1])/19
    1060             sage: ystep = (data[4]-data[3])/19
    1061             sage: dr, dtheta = get_derivatives(data[0],xstep,ystep)
    1062             sage: dr[8,8]
    1063             0.241...
    1064             sage: dtheta[5,5]
    1065             5.907...
    1066      """
     1057
     1058    Standard usage with compute_on_grid::
     1059
     1060        sage: from sage.calculus.riemann import get_derivatives
     1061        sage: f(t) = e^(I*t) - 0.5*e^(-I*t)
     1062        sage: fprime(t) = I*e^(I*t) + 0.5*I*e^(-I*t)
     1063        sage: m = Riemann_Map([f], [fprime], 0)
     1064        sage: data = m.compute_on_grid([],19)
     1065        sage: xstep = (data[2]-data[1])/19
     1066        sage: ystep = (data[4]-data[3])/19
     1067        sage: dr, dtheta = get_derivatives(data[0],xstep,ystep)
     1068        sage: dr[8,8]
     1069        0.241...
     1070        sage: dtheta[5,5]
     1071        5.907...
     1072    """
    10671073    cdef np.ndarray[COMPLEX_T, ndim=2] xderiv
    10681074    cdef np.ndarray[FLOAT_T, ndim = 2] dr, dtheta, zabs
    10691075    imax = len(z_values)-2
    10701076    jmax = len(z_values[0])-2
    10711077    #(f(x+delta)-f(x-delta))/2delta
    1072     xderiv = (z_values[1:-1,2:]-z_values[1:-1,:-2])/(2*xstep) 
    1073     #b/c the function is analytic, we know it's abs(derivative) is equal
     1078    xderiv = (z_values[1:-1,2:]-z_values[1:-1,:-2])/(2*xstep)
     1079    #b/c the function is analytic, we know its abs(derivative) is equal
    10741080    #in all directions
    10751081    dr = np.abs(xderiv)
    10761082    # the abs(derivative) scaled by distance from origin
     
    10781084    dtheta = np.divide(dr,zabs)
    10791085    return dr, dtheta
    10801086
    1081 cpdef complex_to_spiderweb(np.ndarray[COMPLEX_T, ndim = 2]z_values,
    1082     np.ndarray[FLOAT_T, ndim = 2] dr, np.ndarray[FLOAT_T, ndim = 2] dtheta, 
     1087cpdef complex_to_spiderweb(np.ndarray[COMPLEX_T, ndim = 2] z_values,
     1088    np.ndarray[FLOAT_T, ndim = 2] dr, np.ndarray[FLOAT_T, ndim = 2] dtheta,
    10831089    spokes, circles, rgbcolor, thickness, withcolor):
    10841090    """
    1085     Converts a grid of complex numbers into a matrix containing rgb data 
     1091    Converts a grid of complex numbers into a matrix containing rgb data
    10861092    for the Riemann spiderweb plot.
    1087    
    1088      INPUT:
     1093
     1094    INPUT:
    10891095
    10901096    - ``z_values`` -- A grid of complex numbers, as a list of lists.
    1091    
    1092     - ``dr`` -- grid of floats, the r derivative of ``z_values``. 
     1097
     1098    - ``dr`` -- grid of floats, the r derivative of ``z_values``.
    10931099      Used to determine precision.
    1094    
    1095     - ``dtheta`` -- grid of floats, the theta derivative of ``z_values``. 
     1100
     1101    - ``dtheta`` -- grid of floats, the theta derivative of ``z_values``.
    10961102      Used to determine precision.
    1097      
     1103
    10981104    - ``spokes`` -- integer - the number of equally spaced radial lines to plot.
    10991105
    11001106    - ``circles`` -- integer - the number of equally spaced circles about the
     
    11051111
    11061112    - ``thickness`` -- positive float - the thickness of the lines or points
    11071113      in the spiderweb.
    1108      
     1114
    11091115    - ``withcolor`` -- boolean - If ``True`` the spiderweb will be overlaid
    11101116      on the basic color plot.
    11111117
    1112      OUTPUT:
    1113  
     1118    OUTPUT:
     1119
    11141120    An `N x M x 3` floating point Numpy array ``X``, where
    11151121    ``X[i,j]`` is an (r,g,b) tuple.
    1116    
     1122
    11171123    EXAMPLES::
    11181124
    11191125        sage: from sage.calculus.riemann import complex_to_spiderweb
     
    11541160    precision = thickness/150.0
    11551161    imax = len(z_values)
    11561162    jmax = len(z_values[0])
    1157     cdef np.ndarray[FLOAT_T, ndim=3, mode="c"] rgb 
    1158     if withcolor: 
     1163    cdef np.ndarray[FLOAT_T, ndim=3, mode="c"] rgb
     1164    if withcolor:
    11591165        rgb = complex_to_rgb(z_values)
    11601166    else:
    11611167        rgb = np.zeros(dtype=FLOAT, shape=(imax, jmax, 3))
     
    11661172        circ_radii = []
    11671173    if spokes != 0:
    11681174        # both -pi and pi are included
    1169         spoke_angles = srange(-PI,PI+TWOPI/spokes,TWOPI/spokes) 
     1175        spoke_angles = srange(-PI,PI+TWOPI/spokes,TWOPI/spokes)
    11701176    else:
    11711177        spoke_angles = []
    11721178    for i in xrange(imax-2): # the d arrays are 1 smaller on each side
     
    11781184            darg = dtheta[i,j]
    11791185            #points that change too rapidly are presumed to be borders
    11801186            #points that are too small are presumed to be outside
    1181             if darg < DMAX and mag > MMIN: 
     1187            if darg < DMAX and mag > MMIN:
    11821188                for target in circ_radii:
    11831189                    if abs(mag - target)/dmag < precision:
    11841190                        rgb[i+1,j+1] = rgbcolor
    11851191                        break
    11861192                for target in spoke_angles:
    1187                     if abs(arg - target)/darg < precision: 
     1193                    if abs(arg - target)/darg < precision:
    11881194                        rgb[i+1,j+1] = rgbcolor
    11891195                        break
    11901196    return rgb
    1191    
     1197
    11921198
    11931199cpdef complex_to_rgb(np.ndarray[COMPLEX_T, ndim = 2] z_values):
    11941200    r"""
     
    12941300            rgb[i, j, 2] = b
    12951301    sig_off()
    12961302    return rgb
    1297    
     1303
    12981304cpdef analytic_boundary(FLOAT_T t, int n):
    12991305    """
    1300     Provides an exact (for n = infinity) riemann boundary
    1301     correspondence for the ellipse with axes 1 + epsilon and 1 - epsilon. The 
    1302     boundary is therefore given by e^(I*t)+epsilon*e^(-I*t). It is primarily 
    1303     useful for testing the accuracy of the numerical Riemann Map.
    1304    
     1306    Provides an exact (for n = infinity) Riemann boundary
     1307    correspondence for the ellipse with axes 1 + epsilon and 1 - epsilon. The
     1308    boundary is therefore given by e^(I*t)+epsilon*e^(-I*t). It is primarily
     1309    useful for testing the accuracy of the numerical :class:`Riemann_Map`.
     1310
    13051311    INPUT:
    1306    
    1307     - ``t`` -- The boundary parameter, from 0 to two*pi
    1308    
    1309     - ``n`` -- Integer, The number of terms to include. 10 is fairly accurate,
    1310         20 is very accurate.
    1311        
     1312
     1313    - ``t`` -- The boundary parameter, from 0 to 2*pi
     1314
     1315    - ``n`` -- integer - the number of terms to include.
     1316      10 is fairly accurate, 20 is very accurate.
     1317
    13121318    OUTPUT:
    1313    
    1314     A theta value from 0 to 2*pi, corresponding to the point on the 
     1319
     1320    A theta value from 0 to 2*pi, corresponding to the point on the
    13151321    circle e^(I*theta)
    1316    
     1322
    13171323    TESTS:
    1318    
    1319     Checking the accuracy for different n values::
    1320    
     1324
     1325    Checking the accuracy of this function for different n values::
     1326
    13211327        sage: from sage.calculus.riemann import analytic_boundary
    13221328        sage: t100 = analytic_boundary(pi/2,100)
    13231329        sage: abs(analytic_boundary(pi/2,10) - t100) < 10^-8
    13241330        True
    13251331        sage: abs(analytic_boundary(pi/2,20) - t100) < 10^-15
    13261332        True
    1327        
     1333
    13281334    Using this to check the accuracy of the Riemann_Map boundary::
    1329    
     1335
    13301336        sage: f(t) = e^(I*t)+.3*e^(-I*t)
    13311337        sage: fp(t) = I*e^(I*t)-I*.3*e^(-I*t)
    13321338        sage: m = Riemann_Map([f], [fp],0,200)
     
    13411347        result += (2*(-1)**i/i)*(.3**i/(1+.3**(2*i)))*sin(2*i*t)
    13421348    return result
    13431349
    1344    
     1350
    13451351
    13461352cpdef cauchy_kernel(t, args):
    13471353    """
    1348     Intermediate function for the integration in ``analytic_interior``.
    1349    
     1354    Intermediate function for the integration in :meth:`~Riemann_Map.analytic_interior`.
     1355
    13501356    INPUT:
    1351    
     1357
    13521358    - ``t`` -- The boundary parameter, meant to be integrated over
    1353    
     1359
    13541360    - ``args`` -- a tuple containing:
    1355    
    1356         - ``z`` -- Complex, the point to be mapped.
    1357        
    1358         - ``n`` -- Integer, The number of terms to include. 10 is fairly
    1359           accurate, 20 is very accurate.
    1360            
    1361         - ``part`` -- will return the real ('r'), imaginary ('i') or
    1362           complex ('c') value of the kernel
    1363    
     1361
     1362      - ``z`` -- complex - the point to be mapped.
     1363
     1364      - ``n`` -- integer - the number of terms to include.
     1365        10 is fairly accurate, 20 is very accurate.
     1366
     1367      - ``part`` -- will return the real ('r'), imaginary ('i') or
     1368        complex ('c') value of the kernel
     1369
    13641370    TESTS:
    1365         Primarily tested implicitly by analytic_interior
    1366        
    1367         Simple test::
    1368        
     1371
     1372    This is primarily tested implicitly by :meth:`~Riemann_Map.analytic_interior`.
     1373    Here is a simple test::
     1374
    13691375        sage: from sage.calculus.riemann import cauchy_kernel
    13701376        sage: cauchy_kernel(.5,(.1+.2*I, 10,'c'))
    13711377        (-0.584136405997...+0.5948650858950...j)
    1372 
    1373 
    13741378    """
    1375     cdef COMPLEX_T result 
     1379    cdef COMPLEX_T result
    13761380    cdef COMPLEX_T z = args[0]
    13771381    cdef int n = args[1]
    13781382    part = args[2]
     
    13851389    elif part == 'i':
    13861390        return result.imag
    13871391    else: return None
    1388    
     1392
    13891393cpdef analytic_interior(COMPLEX_T z, int n):
    13901394    """
    1391     Provides a nearly exact compuation of the Riemann Map of an interior 
    1392     point of the ellipse with axes 1 + epsilon and 1 - epsilon. It is 
     1395    Provides a nearly exact compuation of the Riemann Map of an interior
     1396    point of the ellipse with axes 1 + epsilon and 1 - epsilon. It is
    13931397    primarily useful for testing the accuracy of the numerical Riemann Map.
    1394    
     1398
    13951399    INPUT:
    1396    
    1397     - ``z`` -- Complex, the point to be mapped.
    1398    
    1399     - ``n`` -- Integer, The number of terms to include. 10 is fairly accurate,
    1400         20 is very accurate.
     1400
     1401    - ``z`` -- complex - the point to be mapped.
     1402
     1403    - ``n`` -- integer - the number of terms to include.
     1404      10 is fairly accurate, 20 is very accurate.
    14011405
    14021406    TESTS:
    1403    
    1404         Testing the accuracy of Riemann_Map::
    1405        
     1407
     1408    Testing the accuracy of :class:`Riemann_Map`::
     1409
    14061410        sage: from sage.calculus.riemann import analytic_interior
    14071411        sage: f(t) = e^(I*t)+.3*e^(-I*t)
    14081412        sage: fp(t) = I*e^(I*t)-I*.3*e^(-I*t)
     
    14151419    """
    14161420    # evaluates the cauchy integral of the boundary, split into the real
    14171421    # and imaginary results because numerical_integral can't handle complex data.
    1418     rp = 1/(TWOPI)*numerical_integral(cauchy_kernel,0,2*pi, 
     1422    rp = 1/(TWOPI)*numerical_integral(cauchy_kernel,0,2*pi,
    14191423        params = [z,n,'i'])[0]
    1420     ip = 1/(TWOPI*I)*numerical_integral(cauchy_kernel,0,2*pi, 
     1424    ip = 1/(TWOPI*I)*numerical_integral(cauchy_kernel,0,2*pi,
    14211425        params = [z,n,'r'])[0]
    14221426    return rp + ip