def retinotopy_mesh_field(mesh, mdl,<EOL>polar_angle=None, eccentricity=None, weight=None,<EOL>weight_min=<NUM_LIT:0>, scale=<NUM_LIT:1>, sigma=None, shape=<NUM_LIT:2>, suffix=None,<EOL>max_eccentricity=Ellipsis,<EOL>max_polar_angle=<NUM_LIT>,<EOL>angle_type='<STR_LIT>',<EOL>exclusion_threshold=None):
<EOL>if pimms.is_str(mdl):<EOL><INDENT>mdl = retinotopy_model(mdl)<EOL><DEDENT>if not isinstance(mdl, RetinotopyMeshModel):<EOL><INDENT>if isinstance(mdl, RegisteredRetinotopyModel):<EOL><INDENT>mdl = mdl.model<EOL><DEDENT>if not isinstance(mdl, RetinotopyMeshModel):<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT><DEDENT>if not hasattr(mdl, '<STR_LIT:data>') or '<STR_LIT>' not in mdl.data or '<STR_LIT>' not in mdl.data:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if not isinstance(mesh, CorticalMesh):<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>n = mesh.vertex_count<EOL>X = mesh.coordinates.T<EOL>if weight_min is None: weight_min = <NUM_LIT:0><EOL>(polar_angle, eccentricity, weight) = [<EOL>extract_retinotopy_argument(mesh, name, arg, default='<STR_LIT>')<EOL>for (name, arg) in [<EOL>('<STR_LIT>', polar_angle),<EOL>('<STR_LIT>', eccentricity),<EOL>('<STR_LIT>', [weight for i in range(n)]if isinstance(weight, Number) or np.issubdtype(type(weight), np.float)else weight)]]<EOL>(polar_angle, eccentricity, weight) = _retinotopy_vectors_to_float(<EOL>polar_angle, eccentricity, weight,<EOL>weight_min=weight_min)<EOL>if np.sum(weight > <NUM_LIT:0>) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>idcs = [i for (i,w) in enumerate(weight) if w > <NUM_LIT:0>]<EOL>mdl_1s = np.ones(mdl.forward.coordinates.shape[<NUM_LIT:0>])<EOL>mdl_coords = np.dot(mdl.transform, np.vstack((mdl.forward.coordinates.T, mdl_1s)))[:<NUM_LIT:2>].T<EOL>mdl_faces  = mdl.forward.triangles<EOL>mdl_data   = np.asarray([mdl.data['<STR_LIT>'], mdl.data['<STR_LIT>']])<EOL>wgts = weight[idcs] * (<NUM_LIT:1> if scale is None else scale)<EOL>msh_data = np.asarray([polar_angle, eccentricity])[:,idcs]<EOL>shape = np.full((len(idcs)), float(shape), dtype=np.float32)<EOL>if max_eccentricity is Ellipsis: max_eccentricity = np.max(msh_data[<NUM_LIT:1>])<EOL>if max_polar_angle  is Ellipsis: max_polar_angle  = <NUM_LIT><EOL>if max_polar_angle is not None:<EOL><INDENT>msh_data[<NUM_LIT:0>] /= max_polar_angle<EOL>mdl_data[<NUM_LIT:0>] /= max_polar_angle<EOL><DEDENT>if max_eccentricity is not None:<EOL><INDENT>msh_data[<NUM_LIT:1>] /= max_eccentricity<EOL>mdl_data[<NUM_LIT:1>] /= max_eccentricity<EOL><DEDENT>if angle_type is not None:<EOL><INDENT>angle_type = angle_type.lower()<EOL>if angle_type != '<STR_LIT>' and angle_type != '<STR_LIT:all>':<EOL><INDENT>convert = {'<STR_LIT>':'<STR_LIT>', '<STR_LIT>':'<STR_LIT>', '<STR_LIT>':'<STR_LIT>',<EOL>'<STR_LIT>':'<STR_LIT>', '<STR_LIT>': '<STR_LIT>', '<STR_LIT>': '<STR_LIT>'}<EOL>angle_type = convert[angle_type]<EOL>mdl_data = [mdl_data[<NUM_LIT:0> if angle_type == '<STR_LIT>' else <NUM_LIT:1>]]<EOL>msh_data = [msh_data[<NUM_LIT:0> if angle_type == '<STR_LIT>' else <NUM_LIT:1>]]<EOL><DEDENT><DEDENT>if sigma is None:<EOL><INDENT>field_desc = ['<STR_LIT>', '<STR_LIT>', mdl_coords, mdl_faces, mdl_data, idcs, msh_data,<EOL>'<STR_LIT>', wgts, '<STR_LIT>', shape]<EOL><DEDENT>else:<EOL><INDENT>if not hasattr(sigma, '<STR_LIT>'): sigma = [sigma for _ in wgts]<EOL>field_desc = ['<STR_LIT>', '<STR_LIT>', mdl_coords, mdl_faces, mdl_data, idcs, msh_data,<EOL>'<STR_LIT>', wgts, '<STR_LIT>', shape, '<STR_LIT>', sigma]<EOL><DEDENT>if suffix is not None: field_desc += suffix<EOL>if exclusion_threshold is not None:<EOL><INDENT>jpe = java_potential_term(mesh, field_desc)<EOL>jcrds = to_java_doubles(mesh.coordinates)<EOL>jgrad = to_java_doubles(np.zeros(mesh.coordinates.shape))<EOL>jpe.calculate(jcrds,jgrad)<EOL>gnorms = np.sum((np.asarray([[x for x in row] for row in jgrad])[:, idcs])**<NUM_LIT:2>, axis=<NUM_LIT:0>)<EOL>gnorms_pos = gnorms[gnorms > <NUM_LIT:0>]<EOL>mdn = np.median(gnorms_pos)<EOL>std = np.std(gnorms_pos)<EOL>gn_idcs = np.where(gnorms > mdn + std*<NUM_LIT>)[<NUM_LIT:0>]<EOL>for i in gn_idcs: wgts[i] = <NUM_LIT:0>;<EOL><DEDENT>return field_desc<EOL>
retinotopy_mesh_field(mesh, model) yields a list that can be used with mesh_register as a
  potential term. This should generally be used in a similar fashion to retinotopy_anchors.

Options:
  * polar_angle (default None) specifies that the given data should be used in place of the
    'polar_angle' or 'PRF_polar_angle'  property values. The given argument must be numeric and
    the same length as the the number of vertices in the mesh. If None is given, then the
    property value of the mesh is used; if a list is given and any element is None, then the
    weight for that vertex is treated as a zero. If the option is a string, then the property
    value with the same name isused as the polar_angle data.
  * eccentricity (default None) specifies that the given data should be used in places of the
    'eccentricity' or 'PRF_eccentricity' property values. The eccentricity option is handled 
    virtually identically to the polar_angle option.
  * weight (default None) specifies that the weight or scale of the data; this is handled
    generally like the polar_angle and eccentricity options, but may also be 1, indicating that
    all vertices with polar_angle and eccentricity values defined will be given a weight of 1.
    If weight is left as None, then the function will check for 'weight',
    'variance_explained', 'PRF_variance_explained', and 'retinotopy_weight' values and will use
    the first found (in that order). If none of these is found, then a value of 1 is assumed.
  * weight_min (default 0) specifies that the weight must be higher than the given value inn
    order to be included in the fit; vertices with weights below this value have their weights
    truncated to 0.
  * scale (default 1) specifies a constant by which to multiply all weights for all anchors; the
    value None is interpreted as 1.
  * shape (default 2.0) specifies the exponent in the harmonic function.
  * sigma (default None) specifies, if given as a number, the sigma parameter of the Gaussian
    potential function; if sigma is None, however, the potential function is harmonic.
  * suffix (default None) specifies any additional arguments that should be appended to the 
    potential function description list that is produced by this function; i.e., the 
    retinotopy_anchors function produces a list, and the contents of suffix, if given and not
    None, are appended to that list (see mesh_register).
  * max_eccentricity (default Ellipsis) specifies how the eccentricity portion of the potential
    field should be normalized. Specifically, in order to ensure that polar angle and
    eccentricity contribute roughly equally to the potential, this should be approximately the
    max eccentricity appearing in the data on the mesh. If the argument is the default then the
    actual max eccentricity will be used.
  * max_polar_angle (default: 180) is used the same way as the max_eccentricity function, but if
    Ellipsis is given, the value 180 is always assumed regardless of measured data.
  * exclusion_threshold (default None) specifies that if the initial norm of a vertex's gradient
    is greater than exclusion_threshold * std + median (where std and median are calculated over
    the vertices with non-zero gradients) then its weight is set to 0 and it is not kept as part
    of the potential field.
  * angle_type (default: None) specifies that only one type of angle should be included in the
    mesh; this may be one of 'polar', 'eccen', 'eccentricity', 'angle', or 'polar_angle'. If
    None, then both polar angle and eccentricity are included.

Example:
 # The retinotopy_anchors function is intended for use with mesh_register, as follows:
 # Define our Schira Model:
 model = neuropythy.retinotopy_model()
 # Make sure our mesh has polar angle, eccentricity, and weight data:
 mesh.prop('polar_angle',  polar_angle_vertex_data);
 mesh.prop('eccentricity', eccentricity_vertex_data);
 mesh.prop('weight',       variance_explained_vertex_data);
 # register the mesh using the retinotopy and model:
 registered_mesh = neuropythy.registration.mesh_register(
    mesh,
    ['mesh', retinotopy_mesh_field(mesh, model)],
    max_step_size=0.05,
    max_steps=2000)