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

spedas / pyspedas / 25391193746

05 May 2026 05:15PM UTC coverage: 76.027% (+19.6%) from 56.446%
25391193746

push

github

jameswilburlewis
Restore Cluster tests -- CSA seems to be back online

37244 of 48988 relevant lines covered (76.03%)

2.41 hits per line

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

75.0
/pyspedas/tplot_tools/tplot_math/clip.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
4✔
7
from pyspedas.tplot_tools import store_data, tnames
4✔
8
import numpy as np
4✔
9
import copy
4✔
10
import logging
4✔
11

12
def clip(tvar,ymin,ymax,newname=None):
4✔
13
    """
14
    Change out-of-bounds data to NaN.
15

16
    Parameters
17
    ----------
18
        tvar : str or list[str]
19
            tplot variable names to clip (wildcards accepted)
20
        ymin : int/float
21
            Minimum value to keep (inclusive)
22
        ymax : int/float
23
            Maximum value to keep (inclusive)
24
        newname : str
25
            Name of new tvar for clipped data storage.  If not specified, tvar will be replaced
26
            THIS is not an option for multiple variable input, for multiple or pseudo variables, the data is overwritten.
27

28
    Returns
29
    -------
30
        None
31

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

35
        >>> Make any values below 2 and above 6 equal to NaN.
36
        >>> pyspedas.store_data('d', data={'x':[2,5,8,11,14,17,21], 'y':[[1,1],[2,2],[100,100],[4,4],[5,5],[6,6],[7,7]]})
37
        >>> pyspedas.clip('d',2,6,'e')
38

39
    """
40

41
    #check for globbed or array input, and call recursively
42
    tn = tnames(tvar)
4✔
43
    if len(tn) == 0:
4✔
44
        return
×
45
    elif len(tn) > 1:
4✔
46
        for j in range(len(tn)):
×
47
            clip(tn[j],ymin,ymax)
×
48
        return
×
49

50

51
    a = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar].where(pyspedas.tplot_tools.data_quants[tvar] >= ymin))
4✔
52
    a = copy.deepcopy(a.where(a <= ymax))
4✔
53

54
    if newname is None:
4✔
55
        a.name = tvar
4✔
56
        pyspedas.tplot_tools.data_quants[tvar] = a
4✔
57
    else:
58
        if 'spec_bins' in a.coords:
2✔
59
            store_data(newname, data={'x': a.coords['time'], 'y': a.values, 'v': a.coords['spec_bins']})
×
60
            pyspedas.tplot_tools.data_quants[newname].attrs = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar].attrs)
×
61
        else:
62
            store_data(newname, data={'x': a.coords['time'], 'y': a.values})
2✔
63
            pyspedas.tplot_tools.data_quants[newname].attrs = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar].attrs)
2✔
64

65
    return
4✔
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