Skip to content

Simulation Import

scripts/simulationImport.py

Shared CSV loader that reads either simulated or MOJAVE data and returns a normalized list of per-source records.

Usage

from simulationImport import importCSV

data = importCSV("generated_sources.csv", filetype="Simulated")
data = importCSV("mojave_cleaned.csv", filetype="Mojave")

importCSV function

Parameters

Parameter Type Description
filepath str Path to the CSV file.
filetype str "Simulated" for generated data, "Mojave" for MOJAVE survey data.

Return format

Returns a list of lists. Each row has the structure:

Index Field Description
0 r Radial distance (norm of position vector)
1 theta Declination / polar angle
2 phi Right ascension / azimuthal angle
3 vt Observed transverse velocity
4 sigma Velocity uncertainty
5 n_x x-component of unit vector \(\hat{n}\)
6 n_y y-component of unit vector \(\hat{n}\)
7 n_z z-component of unit vector \(\hat{n}\)

Column index mapping

The two filetypes read velocity and uncertainty from different CSV columns:

Filetype Velocity column Uncertainty column
"Simulated" 3 4
"Mojave" 13 14

For simulated data, columns 0-2 provide the Cartesian direction \((n_x, n_y, n_z)\) directly. For MOJAVE data, spherical coordinates and \(\hat{n}\) are set to NaN.

!!! warning "MOJAVE n_hat" The MOJAVE branch currently returns NaN for all directional fields (indices 0-2, 5-7). The anisotropic model will not work with MOJAVE data until n_hat is derived.

API Reference

simulationImport.importCSV(filepath, filetype)

Import velocity data and directional unit vectors from CSV.

Parameters:

Name Type Description Default
filepath str

Path to the CSV file.

required
filetype str

"Simulated" for generated data or "Mojave" for the MOJAVE survey.

required

Returns:

Type Description
list of list

Each row is [r, theta, phi, vt, sigma, n_x, n_y, n_z] where: - indices 0-2: spherical coordinates (r, theta/declination, phi) - index 3: observed transverse velocity - index 4: velocity uncertainty (sigma) - indices 5-7: Cartesian unit vector n_hat (n_x, n_y, n_z)

For MOJAVE data, indices 0-2 and 5-7 are NaN (no sky-direction data in the CSV).

Source code in scripts/simulationImport.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def importCSV(filepath, filetype):
    """
    Import velocity data and directional unit vectors from CSV.

    Parameters
    ----------
    filepath : str
        Path to the CSV file.
    filetype : str
        ``"Simulated"`` for generated data or ``"Mojave"`` for the MOJAVE survey.

    Returns
    -------
    list of list
        Each row is ``[r, theta, phi, vt, sigma, n_x, n_y, n_z]`` where:
        - indices 0-2: spherical coordinates (r, theta/declination, phi)
        - index 3: observed transverse velocity
        - index 4: velocity uncertainty (sigma)
        - indices 5-7: Cartesian unit vector n_hat (n_x, n_y, n_z)

        For MOJAVE data, indices 0-2 and 5-7 are NaN (no sky-direction data
        in the CSV).
    """
    dataImport = pd.read_csv(filepath, header=None, skiprows=1)

    if filetype == "Mojave":
        vindex, dvindex = 13, 14
    elif filetype == "Simulated":
        vindex, dvindex = 3, 4

    newList = []
    for i in range(len(dataImport)):
        # Compute spherical coords and n_hat from columns 0:3
        # (only numeric for simulated data)
        if filetype == "Simulated":
            pos = dataImport.iloc[i, 0:3].astype(float)
            n_x, n_y, n_z = pos[0], pos[1], pos[2]
            r = np.linalg.norm(pos)
            phi = np.arctan2(n_y, n_x)
            theta = np.arcsin(n_z / r)
        else:
            # TODO: derive n_hat for MOJAVE data from B1950 source name (encodes RA/Dec).
            # Currently returns NaN — the anisotropic model will NOT work with MOJAVE data
            # until this is implemented.
            r, theta, phi = np.nan, np.nan, np.nan
            n_x, n_y, n_z = np.nan, np.nan, np.nan

        newList.append(
            [
                r,
                theta,
                phi,
                dataImport.iloc[i, vindex],
                dataImport.iloc[i, dvindex],
                n_x,
                n_y,
                n_z,
            ]
        )

    return newList