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

spedas / pyspedas / 25194239086

26 Apr 2026 08:07PM UTC coverage: 61.697% (-28.8%) from 90.54%
25194239086

push

github

jameswilburlewis
Added test for loading Cluster CODIF differential energy flux

0 of 7 new or added lines in 1 file covered. (0.0%)

19460 existing lines in 418 files now uncovered.

30204 of 48955 relevant lines covered (61.7%)

1.44 hits per line

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

11.54
/pyspedas/tplot_tools/tplot_math/add_across.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
3✔
7
import numpy as np
3✔
8
import copy
3✔
9
import logging
3✔
10
from pyspedas.tplot_tools import convert_tplotxarray_to_pandas_dataframe, store_data
3✔
11

12
def add_across(tvar,column_range=None,newname=None):
3✔
13
    """
14
    Adds across columns in the tplot variable
15

16
    .. note::
17
        This analysis routine assumes the data is no more than 2 dimensions.  If there are more, they may become flattened!
18

19
    Parameters
20
    ----------
21
        tvar : str
22
            Name of tplot variable.
23
        column_range: list of ints
24
            The columns to add together.  For example, if [1,4] is given here, columns 1, 2, 3, and 4 will be added together.
25
            If not set, then every column is added.
26
        newname : str
27
            Name of new tvar for averaged data.  If not set, then the variable is replaced
28

29
    Returns
30
    -------
31
        None
32

33
    Examples
34
    --------
35

36
        >>> #Add across every column in the data
37
        >>> pyspedas.store_data('d', data={'x':[2,5,8,11,14,17,21], 'y':[[1,1,50],[2,2,3],[100,4,47],[4,90,5],[5,5,99],[6,6,25],[7,7,-5]]})
38
        >>> pyspedas.add_across('d',newname='d_aa')
39

40

41
        >>> #Add across specific columns in the data
42
        >>> pyspedas.store_data('b', data={'x':[2,5,8,11,14,17,20], 'y':[[1,1,1,1,1,1],[2,2,5,4,1,1],[100,100,3,50,1,1],[4,4,8,58,1,1],[5,5,9,21,1,1],[6,6,2,2,1,1],[7,7,1,6,1,1]]})
43
        >>> pyspedas.add_across('b',column_range=[[1,2],[3,4]],newname='b_aap')
44

45
    """
46

47
    # separate and add data
48

UNCOV
49
    if 'spec_bins' in pyspedas.tplot_tools.data_quants[tvar].coords:
×
50
        d, s = convert_tplotxarray_to_pandas_dataframe(tvar)
×
51
    else:
UNCOV
52
        d = convert_tplotxarray_to_pandas_dataframe(tvar, no_spec_bins=True)
×
UNCOV
53
        s = None
×
54

UNCOV
55
    time = d.index.copy()
×
UNCOV
56
    data1 = d.copy()
×
UNCOV
57
    if s is not None:
×
58
        data2 = s.copy()
×
59
    else:
UNCOV
60
        data2=None
×
UNCOV
61
    data = []
×
UNCOV
62
    spec_data = []
×
63

UNCOV
64
    if column_range is None:
×
UNCOV
65
        column_range = [0, len(d.columns)-1]
×
66

67
    #grab column data
UNCOV
68
    if len(column_range)==2 and isinstance(column_range[0],int):
×
UNCOV
69
        range_start = column_range[0]
×
UNCOV
70
        range_end = column_range[1]
×
UNCOV
71
        add_col = list(range(range_start,range_end+1))
×
UNCOV
72
        datasum = data1[add_col].sum(axis=1)
×
UNCOV
73
        data = data + [list(datasum)]
×
74
    else:
UNCOV
75
        for i in column_range:
×
76
            #if not a list
UNCOV
77
            if type(i) == int:
×
78
                data = data + [list(data1[i])]
×
79
            #sum across listed column range
80
            else:
UNCOV
81
                range_start = i[0]
×
UNCOV
82
                range_end = i[1]
×
UNCOV
83
                add_col = list(range(range_start,range_end+1))
×
UNCOV
84
                datasum = data1[add_col].sum(axis=1)
×
UNCOV
85
                data = data + [list(datasum)]
×
86

UNCOV
87
    if data2 is not None:
×
88
        if len(column_range) == 2 and isinstance(column_range[0], int):
×
89
            range_start = column_range[0]
×
90
            range_end = column_range[1]
×
91
            add_col = list(range(range_start, range_end + 1))
×
92
            datasum = data2[add_col].mean(axis=1)
×
93
            spec_data = spec_data + [list(datasum)]
×
94
        else:
95
            for i in column_range:
×
96
                # if not a list
97
                if type(i) == int:
×
98
                    spec_data = spec_data + [list(data2[i])]
×
99
                # sum across listed column range
100
                else:
101
                    range_start = i[0]
×
102
                    range_end = i[1]
×
103
                    add_col = list(range(range_start, range_end + 1))
×
104
                    datasum = data2[add_col].mean(axis=1)
×
105
                    spec_data = spec_data + [list(datasum)]
×
106

107
    #store added data
UNCOV
108
    if s is None:
×
UNCOV
109
        store_data(newname,data={'x':time, 'y':np.transpose(data)})
×
110
    else:
111
        store_data(newname, data={'x': time, 'y':np.transpose(data), 'v': np.transpose(spec_data)})
×
112

113
    #pyspedas.tplot_tools.data_quants[newname].attrs = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar].attrs)
114

UNCOV
115
    return
×
116

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