def FindNearestElectrode(x, y, z, electrodes={}):
    """
    finds the nearest electrode in the dictionary electrodes
    (x,y,z) is the coordinates of a proposed electrode
    :param x: x coordinate of electrode
    :param y: y coordinate of electrode
    :param z: x coordinate of electrode
    :param electrodes: dictionary of defined electrodes: electrodes[ide]=X=(xe, ye, ze)
    :return: id of nearest electrode and distance and distance to 
    
    """
    distmin=1e88
    idemin=None
    for ide in electrodes:
        X=electrodes[ide]
        dist=((X[0]-x)**2 + (X[1]-y)**2 + (X[2]-z)**2)**0.5
        if dist < distmin :
           distmin=dist
           idemin=ide
    if not idemin is None:
        return int(idemin), distmin
    else:
        return idemin, distmin