• 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

27.78
/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,new_tvar=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
        new_tvar : str (Deprecated)
17
            Name of new tvar for averaged data.  If not set, then the data in tvar is replaced.
18
        newname : str
19
            Name of new tvar for averaged data.  If not set, then the data in tvar is replaced.
20

21
    Returns
22
    -------
23
        None
24

25
    Note
26
    ----
27

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

32
    Examples
33
    --------
34

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

39
    """
40

41
    # new_tvar is deprecated in favor of newname
NEW
42
    if new_tvar is not None:
×
NEW
43
        logging.info("avg_res_data: The new_tvar parameter is deprecated. Please use newname instead.")
×
NEW
44
        newname = new_tvar
×
45

NEW
46
    tvar_new = pyspedas.tplot_tools.data_quants[tvar].coarsen(time=res, boundary='trim').mean()
×
NEW
47
    tvar_new.name = pyspedas.tplot_tools.data_quants[tvar].name
×
NEW
48
    tvar_new.attrs = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar].attrs)
×
49

NEW
50
    if newname is None:
×
NEW
51
        pyspedas.tplot_tools.data_quants[tvar] = newname
×
52
    else:
NEW
53
        if 'spec_bins' in pyspedas.tplot_tools.data_quants[tvar].coords:
×
NEW
54
           pyspedas.store_data(newname, data={'x': tvar_new.coords['time'].values, 'y': tvar_new.values,
×
55
                                               'v': tvar_new.coords['spec_bins'].values})
56
        else:
NEW
57
           pyspedas.store_data(newname, data={'x': tvar_new.coords['time'].values, 'y': tvar_new.values})
×
58

NEW
59
        pyspedas.tplot_tools.data_quants[newname].attrs = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar].attrs)
×
60

NEW
61
    return
×
62

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