<commit_before>from dipsim import visuals
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import vispy

def normalize(x):
    """ 
    Returns a normalized vector. Returns zero vector if input is zero.
    """
    len_x = np.linalg.norm(x)
    if len_x == 0:
        return x
    else:
        return x/len_x

def rot_mat(theta, u):
    """
    Returns the rotation matrix that performs a right handed rotation by 
    angle theta about the vector u.

    Reference: https://en.wikipedia.org/wiki/Rodrigues'_rotation_formula
    """
    u = u/np.linalg.norm(u)
    K = np.array([[0, -u[2], u[1]], [u[2], 0, -u[0]], [-u[1], u[0], 0]])
    return np.identity(3) + K*np.sin(theta) + np.dot(K, K)*(1 - np.cos(theta))

def orthonormal_basis(v0):
    """
    Returns two orthonormal vectors that are orthogonal to v0.
    """
    if np.dot(v0, [0, 0, 1]) == 0:
        v1 = np.array([0, 0, 1])                
    else:
        v1 = np.array([1, 0, -v0[0]/v0[2]])
    v1 = v1/np.linalg.norm(v1)
    v2 = np.cross(v1, v0)
    v2 = v2/np.linalg.norm(v2)
    return v1, v2

def my_orthonormal_basis(v0):
    """
    Returns two orthonormal vectors that are orthogonal to v0.
    """
    if np.dot(v0, [0, 0, 1]) == 1:
        v1 = np.array([1, 0, 0])                
    else:
        v1 = np.array([-v0[1], v0[0], 0])
    v1 = v1/np.linalg.norm(v1)
    v2 = np.cross(v0, v1)
    v2 = v2/np.linalg.norm(v2)
    return v1, v2

def fibonacci_sphere(n):
    # Returns "equally" spaced points on a unit sphere in spherical coordinates.
    # http://stackoverflow.com/a/26127012/5854689
    z = np.linspace(1 - 1/n, -1 + 1/n, num=n) 
    theta = np.arccos(z)
    phi = np.mod((np.pi*(3.0 - np.sqrt(5.0)))*np.arange(n), 2*np.pi)
    return np.vstack((theta, phi)).T

# Three coordinate conversion functions. Use R to use theta-phi coordinates that
# are measured from axes other than the typical z and x axes.
def tp2xyz(tp, R=np.eye(3,3)):
    xyz = [np.sin(tp[0])*np.cos(tp[1]), np.sin(tp[0])*np.sin(tp[1]), np.cos(tp[0])]
    return np.dot(R, xyz)

def xyz2tp(xyz, R=np.eye(3,3)):
    xyz_prime = np.dot(np.linalg.inv(R), xyz)
    return np.array([np.arccos(xyz_prime[2]/np.linalg.norm(xyz_prime)),
                     np.arctan2(xyz_prime[1], xyz_prime[0])])

def tp2tp_prime(tp, R=np.eye(3,3)):
    xyz = tp2xyz(tp)
    return xyz2tp(xyz, R)

# Plotting functions
def plot_sphere(filename, directions=None, data=None, interact=False,
                color_norm='linear', color_min=0, color_max=4*np.pi,
                gamma=0.25, color_map='coolwarm',<commit_msg>Fix tp2tp so that normal coordinates are returned immediately.<commit_after>from dipsim import visuals
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import vispy

def normalize(x):
    """ 
    Returns a normalized vector. Returns zero vector if input is zero.
    """
    len_x = np.linalg.norm(x)
    if len_x == 0:
        return x
    else:
        return x/len_x

def rot_mat(theta, u):
    """
    Returns the rotation matrix that performs a right handed rotation by 
    angle theta about the vector u.

    Reference: https://en.wikipedia.org/wiki/Rodrigues'_rotation_formula
    """
    u = u/np.linalg.norm(u)
    K = np.array([[0, -u[2], u[1]], [u[2], 0, -u[0]], [-u[1], u[0], 0]])
    return np.identity(3) + K*np.sin(theta) + np.dot(K, K)*(1 - np.cos(theta))

def orthonormal_basis(v0):
    """
    Returns two orthonormal vectors that are orthogonal to v0.
    """
    if np.dot(v0, [0, 0, 1]) == 0:
        v1 = np.array([0, 0, 1])                
    else:
        v1 = np.array([1, 0, -v0[0]/v0[2]])
    v1 = v1/np.linalg.norm(v1)
    v2 = np.cross(v1, v0)
    v2 = v2/np.linalg.norm(v2)
    return v1, v2

def my_orthonormal_basis(v0):
    """
    Returns two orthonormal vectors that are orthogonal to v0.
    """
    if np.dot(v0, [0, 0, 1]) == 1:
        v1 = np.array([1, 0, 0])                
    else:
        v1 = np.array([-v0[1], v0[0], 0])
    v1 = v1/np.linalg.norm(v1)
    v2 = np.cross(v0, v1)
    v2 = v2/np.linalg.norm(v2)
    return v1, v2

def fibonacci_sphere(n):
    # Returns "equally" spaced points on a unit sphere in spherical coordinates.
    # http://stackoverflow.com/a/26127012/5854689
    z = np.linspace(1 - 1/n, -1 + 1/n, num=n) 
    theta = np.arccos(z)
    phi = np.mod((np.pi*(3.0 - np.sqrt(5.0)))*np.arange(n), 2*np.pi)
    return np.vstack((theta, phi)).T

# Three coordinate conversion functions. Use R to use theta-phi coordinates that
# are measured from axes other than the typical z and x axes.
def tp2xyz(tp, R=np.eye(3,3)):
    xyz = [np.sin(tp[0])*np.cos(tp[1]), np.sin(tp[0])*np.sin(tp[1]), np.cos(tp[0])]
    return np.dot(R, xyz)

def xyz2tp(xyz, R=np.eye(3,3)):
    xyz_prime = np.dot(np.linalg.inv(R), xyz)
    return np.array([np.arccos(xyz_prime[2]/np.linalg.norm(xyz_prime)),
                     np.arctan2(xyz_prime[1], xyz_prime[0])])

def tp2tp_prime(tp, R=np.eye(3,3)):
    if np.array_equal(R, np.eye(3,3)):
        return tp
    else:
        xyz = tp2xyz(tp)
        return xyz2tp(xyz, R)

# Plotting functions
def plot_sphere(filename, directions=None, data=None, interact=False,
                color_norm='linear', color_min=0, color_max=4*np.pi,
                gamma=0.25, color_map='coolwarm',
{'fraction_non_alphanumeric': 0.15942835931700075, 'fraction_numerical': 0.0447290274684484, 'mean_word_length': 2.706327372764787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3571208', 'n_tokens_mistral': 2303, 'n_tokens_neox': 2149, 'n_words': 507}