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

spedas / pyspedas / 16972251084

14 Aug 2025 05:28PM UTC coverage: 89.527% (+0.01%) from 89.515%
16972251084

push

github

jameswilburlewis
Tweaked wording and formatting for readthedocs

40100 of 44791 relevant lines covered (89.53%)

0.9 hits per line

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

80.95
/pyspedas/pytplot/tplot_math/subtract.py
1
# Copyright 2020 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
from pyspedas.pytplot import store_data, tinterp
1✔
8
import copy
1✔
9
import logging
1✔
10

11
def subtract(
1✔
12
        tvar1,
13
        tvar2,
14
        newname=None,
15
        new_tvar=None
16
):
17
    """
18
    Subtracts two tplot variables.  Will interpolate if the two are not on the same time cadence.
19

20
    Parameters
21
    ----------
22
        tvar1 : str
23
            Name of first tplot variable.
24
        tvar2 : int/float
25
            Name of second tplot variable
26
        newname : str
27
            Name of new tvar for added data.
28
            Default: None. If not set, then the data in tvar1 is replaced.
29
        new_tvar : str (Deprecated)
30
            Name of new tvar for added data.  If not set, then the data in tvar1 is replaced.
31

32
    Returns
33
    -------
34
        None
35

36
    Examples
37
    --------
38
        >>> pyspedas.store_data('a', data={'x':[0,4,8,12,16], 'y':[1,2,3,4,5]})
39
        >>> pyspedas.store_data('c', data={'x':[0,4,8,12,16,19,21], 'y':[1,4,1,7,1,9,1]})
40
        >>> pyspedas.subtract('a','c',new_tvar='a-c')
41

42
    """
43

44
    # new_tvar is deprecated in favor of newname
45
    if new_tvar is not None:
1✔
46
        logging.info("subtract: The new_tvar parameter is deprecated. Please use newname instead.")
×
47
        newname = new_tvar
×
48

49
    #interpolate tvars
50
    tv2 = tinterp(tvar1,tvar2)
1✔
51

52
    #separate and subtract data
53
    data1 = pyspedas.pytplot.data_quants[tvar1].values
1✔
54
    data2 = pyspedas.pytplot.data_quants[tv2].values
1✔
55
    data = data1 - data2
1✔
56

57
    #store subtracted data
58
    if newname is None:
1✔
59
        pyspedas.pytplot.data_quants[tvar1].values = data
×
60
        return tvar1
×
61

62
    if 'spec_bins' in pyspedas.pytplot.data_quants[tvar1].coords:
1✔
63
        store_data(newname, data={'x': pyspedas.pytplot.data_quants[tvar1].coords['time'].values, 'y': data, 'v':pyspedas.pytplot.data_quants[tvar1].coords['spec_bins'].values})
1✔
64
        pyspedas.pytplot.data_quants[newname].attrs = copy.deepcopy(pyspedas.pytplot.data_quants[tvar1].attrs)
1✔
65
    else:
66
        store_data(newname,data={'x': pyspedas.pytplot.data_quants[tvar1].coords['time'].values, 'y': data})
1✔
67
        pyspedas.pytplot.data_quants[newname].attrs = copy.deepcopy(pyspedas.pytplot.data_quants[tvar1].attrs)
1✔
68

69
    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