<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def calc_xyz2surf(surf, xyz, threshold=20, exponent=None, std=None):
 """Calculate transformation matrix from xyz values to vertices. Parameters surf : instance of wonambi.attr.Surf the surface of only one hemisphere. xyz : numpy.ndarray nChan x 3 matrix, with the locations in x, y, z. std : float distance in mm of the Gaussian kernel exponent : int inverse law (1-> direct inverse, 2-> inverse square, 3-> inverse cube) threshold : float distance in mm for a vertex to pick up electrode activity (if distance is above the threshold, one electrode does not affect a vertex). Returns ------- numpy.ndarray nVertices X xyz.shape[0] matrix Notes ----- This function is a helper when plotting onto brain surface, by creating a transformation matrix from the values in space (f.e. at each electrode) to the position of the vertices (used to show the brain surface). There are many ways to move from values to vertices. The crucial parameter is the function at which activity decreases in respect to the distance. You can have an inverse relationship by specifying 'exponent'. If 'exponent' is 2, then the activity will decrease as inverse square of the distance. The function can be a Gaussian. With std, you specify the width of the gaussian kernel in mm. For each vertex, it uses a threshold based on the distance ('threshold' value, in mm). Finally, it normalizes the contribution of all the channels to 1, so that the sum of the coefficients for each vertex is 1. You can also create your own matrix (and skip calc_xyz2surf altogether) and pass it as attribute to the main figure. Because it's a loop over all the vertices, this function is pretty slow, but if you calculate it once, you can reuse it. We take advantage of multiprocessing, which speeds it up considerably. """

    if exponent is None and std is None:
        exponent = 1

    if exponent is not None:
        lg.debug('Vertex values based on inverse-law, with exponent ' +
                 str(exponent))
        funct = partial(calc_one_vert_inverse, xyz=xyz, exponent=exponent)
    elif std is not None:
        lg.debug('Vertex values based on gaussian, with s.d. ' + str(std))
        funct = partial(calc_one_vert_gauss, xyz=xyz, std=std)

    with Pool() as p:
        xyz2surf = p.map(funct, surf.vert)

    xyz2surf = asarray(xyz2surf)

    if exponent is not None:
        threshold_value = (1 / (threshold ** exponent))
        external_threshold_value = threshold_value
    elif std is not None:
        threshold_value = gauss(threshold, std)
        external_threshold_value = gauss(std, std) # this is around 0.607
    lg.debug('Values thresholded at ' + str(threshold_value))

    xyz2surf[xyz2surf < threshold_value] = NaN

    # here we deal with vertices that are within the threshold value but far
    # from a single electrodes, so those remain empty
    sumval = nansum(xyz2surf, axis=1)
    sumval[sumval < external_threshold_value] = NaN

    # normalize by the number of electrodes
    xyz2surf /= atleast_2d(sumval).T
    xyz2surf[isnan(xyz2surf)] = 0

    return xyz2surf