• 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

100.0
/pyspedas/tplot_tools/tplot_math/tdeflag.py
1
"""
2
Removes NaNs and other flags.
3

4
Notes
5
----
6
Allowed wildcards are ? for a single character, * from multiple characters.
7
Similar to tdeflag.pro in IDL SPEDAS, but now a wrapper for deflag.py
8

9
"""
10
import logging
3✔
11
import pyspedas
3✔
12
from pyspedas.tplot_tools import tnames, deflag
3✔
13

14
def tdeflag(names,
3✔
15
            flag=None,
16
            method='remove_nan',
17
            newname=None,
18
            suffix=None,
19
            overwrite=None,
20
            fillval=None
21
):
22
    """
23
    Replaces FLAGs in arrays with interpolated or other values.
24

25
    Parameters
26
    ----------
27
    names: str/list of str
28
        List of tplot variables names to deflag (wildcards accepted)
29
    flag: float, int, or list
30
        Value or values to be treated as flags
31
    method: str, optional
32
        Method to apply.
33
        If None,then flagged values are replaced with NaN
34
        Other options 'repeat' (repeat last good value), 
35
        'linear' (interpolate linearly over gap).
36
        'replace' replaces flagged value with a fill value, which can be set using the 
37
                  keyword 'fillval' (default is to use NaN)
38
        Option 'remove_nan' removes time intervals with NaN values
39
        Default: 'remove_nan'
40
    newname: str/list of str, optional
41
        List of new names for tplot variables.
42
        If '', then tplot variables are replaced.
43
        Default: None. If not specified then a suffix is applied.
44
    suffix: str, optional
45
        A suffix to apply.
46
        Default: '-deflag'.
47
    overwrite: bool, optional
48
        Replace the existing tplot name.
49
        Default: None
50
    fillval: int, float (optional)
51
        Value to use as replacement if method='replace'
52

53
    Returns
54
    -------
55
    list of str
56
        List of tplot variables created or altered by tdeflag
57

58
    Examples
59
    --------
60

61
    >>> import pyspedas
62
    >>> pyspedas.store_data('d', data={'x':[2,5,8,11,14,17,21], 'y':[[1,1],[2,2],[100,4],[4,90],[5,5],[6,6],[7,7]]})
63
    >>> # Remove any instances of [100,90,7,2,57] from 'd', store in 'e'.
64
    >>> pyspedas.deflag('d',[100,90,7,2,57],newname='e')
65
    >>> d_deflagged = pyspedas.get_data('e')
66
    >>> print(d_deflagged)
67
    """
68

UNCOV
69
    old_names = tnames(names)
2✔
70

UNCOV
71
    if len(old_names) < 1:
2✔
UNCOV
72
        logging.error('tdeflag: No valid tplot names were provided.')
2✔
UNCOV
73
        return None
2✔
74

UNCOV
75
    if suffix is None:
2✔
UNCOV
76
        suffix = '-deflag'
2✔
77

UNCOV
78
    if overwrite is not None:
2✔
UNCOV
79
        n_names = old_names
2✔
UNCOV
80
    elif newname is None:
2✔
UNCOV
81
        n_names = [s + suffix for s in old_names]
1✔
82
    else:
UNCOV
83
        n_names = newname
2✔
84

UNCOV
85
    if isinstance(n_names, str):
2✔
UNCOV
86
        n_names = [n_names]
2✔
87

UNCOV
88
    if len(n_names) != len(old_names):
2✔
UNCOV
89
        n_names = [s + suffix for s in old_names]
1✔
UNCOV
90
        logging.info('input newname has incorrect number of elements')
1✔
91

UNCOV
92
    for i in range(len(old_names)):
2✔
UNCOV
93
        deflag(old_names[i], flag, newname=n_names[i], method=method, fillval=fillval)
2✔
UNCOV
94
        logging.info('tdeflag was applied to: ' + n_names[i])
2✔
95

UNCOV
96
    return n_names
2✔
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