• 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

71.43
/pyspedas/tplot_tools/tplot_math/makegap.py
1
import pyspedas
1✔
2
from pyspedas.tplot_tools import store_data, get_data, degap, del_data
1✔
3
import numpy as np
1✔
4

5

6
def makegap(var_data, dt=None, margin=0.0, func="nan"):
1✔
7
    """
8
    Fill gaps in the data either with NaNs or the last number.  This
9
    is identical to degap, except operates directly on the data and
10
    time arrays, rather than the tplot variable. This is intended for
11
    use with the data_gap option. This version actually puts the data
12
    into a temporary tplot variable, and call degap, then extracts
13
    that data into the proper form.
14

15
    Parameters
16
    ----------
17
        var_data : named tuple
18
            The data for the tplot variable, a structure that contains at least, tags for 'y' and 'times'
19
        dt : int/float
20
            Step size of the data in seconds, default is to use the median time interval
21
        margin : int/float, optional, default is 0.0 seconds (there is no margin in the IDL tplot makegap)
22
            The maximum deviation from the step size allowed before degapping occurs.  In other words,
23
            if you'd like to fill in data every 4 seconds but occasionally the data is 4.1 seconds apart,
24
            set the margin to .1 so that a data point is not inserted there.
25
        func : str, optional
26
            Either 'nan' or 'ffill', which overrides normal interpolation with NaN
27
            substitution or forward-filled values.
28

29
    Returns
30
    -------
31
    tuple
32
        A tuple returned by calling get_data() on the degapped temp variable
33

34
    Examples
35
    --------
36

37
        >>> import pyspedas
38
        >>> time = [pyspedas.time_float("2020-01-01") + i for i in [1, 2, 3, 4, 5, 6, 9, 10, 11]]
39
        >>> y = [1, 2, 3, 4, 5, 6, 9, 10, 11]
40
        >>> pyspedas.store_data("a", data={"x": time, "y": y})
41
        >>> a = pyspedas.get_data("a")
42
        >>> print(a)
43
        >>> b = pyspedas.makegap(a)
44
        >>> print(b)
45

46
    """
47
    # vt = var_data.times
48
    # gap_size = np.diff(vt) #vt is in nanoseconds, and np.diff works over day boundaries
49
    # Default for dt is the median value of gap_size, the time interval differences
50
    # if dt == None:
51
    #    dt = np.median(gap_size)
52
    #    dt0 = dt
53
    # else:
54
    # change dt to appropriate type
55
    #    dt0 = np.timedelta64(int(dt*1e9), 'ns')
56

57
    # gap_index_locations = np.where(gap_size > dt0)
58

59
    # First create a temporary tplot variable for the data, times need to be in unix time
60
    #x = time_float(var_data.times)
61
    x = np.int64(var_data.times)/1e9
1✔
62
    if var_data.y.ndim == 1:
1✔
NEW
63
        store_data("makegap_tmp", data={"x": x, "y": var_data.y})
×
64
    else:  # multiple dimensions
65
        var_data_out = None
1✔
66
        store_data("makegap_tmp", data={"x": x, "y": var_data.y})
1✔
67
        # Check for values, v, or v1, v2, v3
68
        if len(var_data) == 2:  # No v's
1✔
NEW
69
            store_data("makegap_tmp", data={"x": x, "y": var_data.y})
×
70
        elif len(var_data) == 3:  # v or v1,needs indexing if it's 2d
1✔
71
            store_data(
1✔
72
                "makegap_tmp", data={"x": x, "y": var_data.y, "v": var_data[2]}
73
            )
NEW
74
        elif len(var_data) == 4:  # has both v1 and v2
×
NEW
75
            store_data(
×
76
                "makegap_tmp",
77
                data={"x": x, "y": var_data.y, "v1": var_data[2], "v2": var_data[3]},
78
            )
NEW
79
        elif len(var_data) == 5:  # has v1, v2, v3
×
NEW
80
            store_data(
×
81
                "makegap_tmp",
82
                data={
83
                    "x": x,
84
                    "y": var_data.y,
85
                    "v1": var_data[2],
86
                    "v2": var_data[3],
87
                    "v3": var_data[3],
88
                },
89
            )
90
    # Now, degap the variable
91
    degap("makegap_tmp", dt=dt, margin=margin, func=func)
1✔
92
    # and return the getdata result
93
    var_data_out = get_data("makegap_tmp", dt=True)
1✔
94
    del_data("makegap_tmp")
1✔
95
    return var_data_out
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