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

spedas / pyspedas / 17192022881

24 Aug 2025 06:00PM UTC coverage: 89.279% (+0.09%) from 89.194%
17192022881

push

github

jameswilburlewis
Remove references to obsolete 'new_tvar' parameter

11 of 11 new or added lines in 10 files covered. (100.0%)

29 existing lines in 6 files now uncovered.

40356 of 45202 relevant lines covered (89.28%)

0.89 hits per line

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

33.33
/pyspedas/tplot_tools/tplot_math/avg_res_data.py
1
import pyspedas
1✔
2
import numpy as np
1✔
3
import copy
1✔
4
import logging
1✔
5

6
def avg_res_data(tvar,res,newname=None):
1✔
7
    """
8
    Averages the variable over a specified period of time.
9

10
    Parameters
11
    ----------
12
        tvar : str
13
            Name of tplot variable.
14
        res : int/float
15
            The new data resolution
16
        newname : str
17
            Name of new tvar for averaged data.  If not set, then the data in tvar is replaced.
18

19
    Returns
20
    -------
21
        None
22

23
    Note
24
    ----
25

26
    This routine uses the xarray coarsen() method to reduce the time resolution.  It will only work if the
27
    data is evenly gridded, and the res parameter evenly divides the number of samples.
28
    For most purposes, it is more appropriate to use pyspedas.avg_data() instead.
29

30
    Examples
31
    --------
32

33
        >>> #Average the data over every two seconds
34
        >>> 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]]})
35
        >>> pyspedas.avg_res_data('d',2,'d2res')
36

37
    """
38

UNCOV
39
    tvar_new = pyspedas.tplot_tools.data_quants[tvar].coarsen(time=res, boundary='trim').mean()
×
40
    tvar_new.name = pyspedas.tplot_tools.data_quants[tvar].name
×
41
    tvar_new.attrs = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar].attrs)
×
42

43
    if newname is None:
×
44
        pyspedas.tplot_tools.data_quants[tvar] = newname
×
45
    else:
46
        if 'spec_bins' in pyspedas.tplot_tools.data_quants[tvar].coords:
×
47
           pyspedas.store_data(newname, data={'x': tvar_new.coords['time'].values, 'y': tvar_new.values,
×
48
                                               'v': tvar_new.coords['spec_bins'].values})
49
        else:
50
           pyspedas.store_data(newname, data={'x': tvar_new.coords['time'].values, 'y': tvar_new.values})
×
51

52
        pyspedas.tplot_tools.data_quants[newname].attrs = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar].attrs)
×
53

54
    return
×
55

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