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

spedas / pyspedas / 17001196665

15 Aug 2025 11:12PM UTC coverage: 89.516% (+0.7%) from 88.849%
17001196665

push

github

web-flow
Merge branch 'pyspedas_2_0_dev' into master

5072 of 6199 new or added lines in 413 files covered. (81.82%)

8 existing lines in 2 files now uncovered.

40061 of 44753 relevant lines covered (89.52%)

0.9 hits per line

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

71.43
/pyspedas/tplot_tools/tplot_math/multiply.py
1
import pyspedas
1✔
2
from pyspedas.tplot_tools import store_data, tinterp
1✔
3
import copy
1✔
4
import logging
1✔
5

6

7
def multiply(tvar1, tvar2, newname=None, new_tvar=None):
1✔
8
    """
9
    Multiplies two tplot variables.  Will interpolate if the two are not on the same time cadence.
10

11
    Parameters
12
    ----------
13
        tvar1 : str
14
            Name of first tplot variable.
15
        tvar2 : int/float
16
            Name of second tplot variable.
17
        newname : str
18
            Name of new tplot variable.  If not set, then the data in tvar1 is replaced.
19
        new_tvar : str (Deprecated)
20
            Name of new tplot variable.  If not set, then the data in tvar1 is replaced.
21

22
    Returns
23
    -------
24
        None
25

26
    Examples
27
    --------
28
        >>> x1 = [0, 4, 8, 12, 16]
29
        >>> x2 = [0, 4, 8, 12, 16, 19, 21]
30
        >>> time1 = [pyspedas.time_float("2020-01-01") + i for i in x1]
31
        >>> time2 = [pyspedas.time_float("2020-01-01") + i for i in x2]
32
        >>> pyspedas.store_data("a", data={"x": time1, "y": [1, 2, 3, 4, 5]})
33
        >>> pyspedas.store_data("c", data={"x": time2, "y": [1, 4, 1, 7, 1, 9, 1]})
34
        >>> n = pyspedas.multiply("a", "c", newname="a_x_c")
35
        >>> print('new tplot variable:', n)
36
        >>> ac = pyspedas.get_data(n)
37
        >>> print(ac)
38
    """
39
    # new_tvar is deprecated in favor of newname
40
    if new_tvar is not None:
1✔
NEW
41
        logging.info(
×
42
            "multiply: The new_tvar parameter is deprecated. Please use newname instead."
43
        )
NEW
44
        newname = new_tvar
×
45

46
    # interpolate tvars
47
    tv2 = tinterp(tvar1, tvar2)
1✔
48
    # separate and multiply data
49
    data1 = pyspedas.tplot_tools.data_quants[tvar1].values
1✔
50
    data2 = pyspedas.tplot_tools.data_quants[tv2].values
1✔
51
    data = data1 * data2
1✔
52

53
    if newname is None:
1✔
NEW
54
        pyspedas.tplot_tools.data_quants[tvar1].values = data
×
NEW
55
        return tvar1
×
56

57
    if "spec_bins" in pyspedas.tplot_tools.data_quants[tvar1].coords:
1✔
NEW
58
        store_data(
×
59
            newname,
60
            data={
61
                "x": pyspedas.tplot_tools.data_quants[tvar1].coords["time"].values,
62
                "y": data,
63
                "v": pyspedas.tplot_tools.data_quants[tvar1].coords["spec_bins"].values,
64
            },
65
        )
NEW
66
        pyspedas.tplot_tools.data_quants[newname].attrs = copy.deepcopy(
×
67
            pyspedas.tplot_tools.data_quants[tvar1].attrs
68
        )
69
    else:
70
       store_data(
1✔
71
            newname,
72
            data={"x": pyspedas.tplot_tools.data_quants[tvar1].coords["time"].values, "y": data},
73
        )
74
       pyspedas.tplot_tools.data_quants[newname].attrs = copy.deepcopy(
1✔
75
            pyspedas.tplot_tools.data_quants[tvar1].attrs
76
        )
77
    return newname
1✔
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