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

spedas / pyspedas / 16972251084

14 Aug 2025 05:28PM UTC coverage: 89.527% (+0.01%) from 89.515%
16972251084

push

github

jameswilburlewis
Tweaked wording and formatting for readthedocs

40100 of 44791 relevant lines covered (89.53%)

0.9 hits per line

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

70.37
/pyspedas/pytplot/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
1✔
7
from pyspedas.pytplot import store_data, tnames
1✔
8
import numpy as np
1✔
9
import copy
1✔
10
import logging
1✔
11

12
def clip(tvar,ymin,ymax,newname=None,new_tvar=None):
1✔
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
        new_tvar : str (Deprecated)
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
        newname : str
28
            Name of new tvar for clipped data storage.  If not specified, tvar will be replaced
29
            THIS is not an option for multiple variable input, for multiple or pseudo variables, the data is overwritten.
30

31
    Returns
32
    -------
33
        None
34

35
    Examples
36
    --------
37

38
        >>> Make any values below 2 and above 6 equal to NaN.
39
        >>> 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]]})
40
        >>> pyspedas.clip('d',2,6,'e')
41

42
    """
43

44
    # new_tvar is deprecated in favor of newname
45
    if new_tvar is not None:
1✔
46
        logging.info("clip: The new_tvar parameter is deprecated. Please use newname instead.")
×
47
        newname = new_tvar
×
48

49
    #check for globbed or array input, and call recursively
50
    tn = tnames(tvar)
1✔
51
    if len(tn) == 0:
1✔
52
        return
×
53
    elif len(tn) > 1:
1✔
54
        for j in range(len(tn)):
×
55
            clip(tn[j],ymin,ymax)
×
56
        return
×
57

58

59
    a = copy.deepcopy(pyspedas.pytplot.data_quants[tvar].where(pyspedas.pytplot.data_quants[tvar] >= ymin))
1✔
60
    a = copy.deepcopy(a.where(a <= ymax))
1✔
61

62
    if newname is None:
1✔
63
        a.name = tvar
1✔
64
        pyspedas.pytplot.data_quants[tvar] = a
1✔
65
    else:
66
        if 'spec_bins' in a.coords:
1✔
67
            store_data(newname, data={'x': a.coords['time'], 'y': a.values, 'v': a.coords['spec_bins']})
×
68
            pyspedas.pytplot.data_quants[newname].attrs = copy.deepcopy(pyspedas.pytplot.data_quants[tvar].attrs)
×
69
        else:
70
            store_data(newname, data={'x': a.coords['time'], 'y': a.values})
1✔
71
            pyspedas.pytplot.data_quants[newname].attrs = copy.deepcopy(pyspedas.pytplot.data_quants[tvar].attrs)
1✔
72

73
    return
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