• 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/add.py
1
# Copyright 2018 Regents of the University of Colorado. All Rights Reserved.
2
# Released under the MIT license.
3
# This software was developed at the University of Colorado's Laboratory for Atmospheric and Space Physics.
4
# Verify current version before use at: https://github.com/MAVENSDC/Pytplot
5

6
import pyspedas
1✔
7
import copy
1✔
8
import logging
1✔
9
from pyspedas.tplot_tools import store_data, tinterp
1✔
10

11
def add(tvar1,tvar2,newname=None, new_tvar=None):
1✔
12
    """
13
    Adds two tplot variables together.  Will interpolate if the two are not on the same time cadence.
14

15
    Parameters:
16
        tvar1 : str
17
            Name of first tplot variable.
18
        tvar2 : int/float
19
            Name of second tplot variable
20
        newname : str
21
            Name of new tvar for added data.  If not set, then the data in tvar1 is replaced.
22
        new_tvar : str (Deprecated)
23
            Name of new tvar for added data.  If not set, then the data in tvar1 is replaced.
24

25
    Returns:
26
        None
27

28
    Examples
29
    --------
30

31
        >>> pyspedas.store_data('a', data={'x':[0,4,8,12,16], 'y':[1,2,3,4,5]})
32
        >>> pyspedas.store_data('c', data={'x':[0,4,8,12,16,19,21], 'y':[1,4,1,7,1,9,1]})
33
        >>> pyspedas.add('a','c',newname='a+c')
34
        >>> pyspedas.get_data('a+c')
35
    """
36

37
    # new_tvar is deprecated in favor of newname
38
    if new_tvar is not None:
1✔
NEW
39
        logging.info("add: The new_tvar parameter is deprecated. Please use newname instead.")
×
NEW
40
        newname = new_tvar
×
41

42
    # interpolate tvars
43
    tv2 = tinterp(tvar1, tvar2)
1✔
44

45
    # separate and subtract data
46
    data1 = pyspedas.tplot_tools.data_quants[tvar1].values
1✔
47
    data2 = pyspedas.tplot_tools.data_quants[tv2].values
1✔
48
    data = data1 + data2
1✔
49

50
    # store subtracted data
51
    if newname is None:
1✔
NEW
52
        pyspedas.tplot_tools.data_quants[tvar1].values = data
×
NEW
53
        return tvar1
×
54

55
    if 'spec_bins' in pyspedas.tplot_tools.data_quants[tvar1].coords:
1✔
NEW
56
        store_data(newname, data={'x': pyspedas.tplot_tools.data_quants[tvar1].coords['time'].values, 'y': data,
×
57
                                           'v': pyspedas.tplot_tools.data_quants[tvar1].coords['spec_bins'].values})
NEW
58
        pyspedas.tplot_tools.data_quants[newname].attrs = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar1].attrs)
×
59
    else:
60
       store_data(newname, data={'x': pyspedas.tplot_tools.data_quants[tvar1].coords['time'].values, 'y': data})
1✔
61
       pyspedas.tplot_tools.data_quants[newname].attrs = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar1].attrs)
1✔
62

63
    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