• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

spedas / pyspedas / 25391193746

05 May 2026 05:15PM UTC coverage: 76.027% (+19.6%) from 56.446%
25391193746

push

github

jameswilburlewis
Restore Cluster tests -- CSA seems to be back online

37244 of 48988 relevant lines covered (76.03%)

2.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/pyspedas/tplot_tools/tplot_math/tcrossp.py
1
import numpy as np
4✔
2
from pyspedas.tplot_tools import get_data, store_data
4✔
3

4

5
def tcrossp(
4✔
6
        v1,
7
        v2,
8
        newname=None,
9
        return_data=False
10
):
11
    """
12
    Calculates the cross product of two tplot variables
13

14
    Parameters
15
    ----------
16
    v1: str
17
        First tplot variable
18
    v2: str
19
        Second tplot variable
20
    newname: str, optional
21
        Name of the output variable
22
        Default: v1_cross_v2
23
    return_data: bool
24
        Returns the data as an ndarray instead of creating a tplot variable
25
        Default: False
26

27
    Returns
28
    --------
29
    str
30
        Name of the tplot variable created
31

32
    Examples
33
    --------
34

35
        >>> # Compute the cross product of two time series
36
        >>> import pyspedas
37
        >>> x1 = [0, 4, 8]
38
        >>> x2 = [0, 4, 8]
39
        >>> time1 = [pyspedas.time_float("2020-01-01") + i for i in x1]
40
        >>> time2 = [pyspedas.time_float("2020-01-01") + i for i in x2]
41
        >>> pyspedas.store_data("a", data={"x": time1, "y": [[1, 2, 3],[2, 3, 4],[3, 4, 5]]})
42
        >>> pyspedas.store_data("c", data={"x": time2, "y": [[1, 4, 1],[2, 5, 2],[3, 5, 3]]})
43
        >>> n = pyspedas.tcrossp("a", "c", newname="a_cross_c")
44
        >>> print('new tplot variable:', n)
45
        >>> ac = pyspedas.get_data(n)
46
        >>> print(ac)
47

48
    """
49

50
    v1_data = None
4✔
51
    v2_data = None
4✔
52

53
    if not isinstance(v1, np.ndarray) and isinstance(v1, str):
4✔
54
        v1_data = get_data(v1)
4✔
55
        v1_name = v1
4✔
56

57
        if v1_data is not None:
4✔
58
            data1 = v1_data[1]
4✔
59
    else:
60
        v1_name = 'var1'
4✔
61
        data1 = v1
4✔
62

63
    if not isinstance(v2, np.ndarray) and isinstance(v2, str):
4✔
64
        v2_data = get_data(v2)
4✔
65
        v2_name = v2
4✔
66

67
        if v2_data is not None:
4✔
68
            data2 = v2_data[1]
4✔
69
    else:
70
        v2_name = 'var2'
4✔
71
        data2 = v2
4✔
72

73
    if newname is None:
4✔
74
        newname = v1_name + '_cross_' + v2_name
4✔
75

76
    cp = np.cross(data1, data2)
4✔
77

78
    if return_data:
4✔
79
        return cp
4✔
80
    else:
81
        out = cp
3✔
82
        if v2_data is None:
3✔
83
            if len(cp.shape) == 1:
3✔
84
                out = np.atleast_2d(cp)
3✔
85
            times = np.zeros(out.shape[0])
3✔
86
        else:
87
            times = v2_data[0]
3✔
88
        store_data(newname, data={'x': times, 'y': out})
3✔
89
        return newname
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc