• 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

10.71
/pyspedas/tplot_tools/tplot_math/crop.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
3✔
7
import copy
3✔
8

9
def crop(tvar1,tvar2, replace=True):
3✔
10
    """
11
    Crops both tplot variable so that their times are the same.  This is done automatically by other processing routines if times do not match up.
12

13
    Parameters
14
    -----------
15
        tvar1 : str
16
            Name of the first tplot variable
17
        tvar2 : str
18
            Name of the second tplot variable
19
        replace : bool, optional
20
            If true, the data in the original tplot variables are replaced.  Otherwise, new variables are created.
21

22
    Returns
23
    -------
24
        None
25

26

27
    Examples
28
    --------
29

30
        >>> pyspedas.store_data('a', data={'x':[0,4,8,12,16], 'y':[1,2,3,4,5]})
31
        >>> pyspedas.store_data('b', data={'x':[2,5,8,11,14,17,20], 'y':[[1,1,1,1,1,1],[2,2,5,4,1,1],[100,100,3,50,1,1],[4,4,8,58,1,1],[5,5,9,21,1,1],[6,6,2,2,1,1],[7,7,1,6,1,1]]})
32
        >>> pyspedas.crop('a','b')
33

34

35
    """
36

37
    # grab time and data arrays
UNCOV
38
    tv1 = pyspedas.tplot_tools.data_quants[tvar1].copy()
×
UNCOV
39
    tv2 = pyspedas.tplot_tools.data_quants[tvar2].copy()
×
40
    # find first and last time indices
UNCOV
41
    t0_1 = tv1.coords['time'][0]
×
UNCOV
42
    t0_2 = tv2.coords['time'][0]
×
UNCOV
43
    tx_1 = tv1.coords['time'][-1]
×
UNCOV
44
    tx_2 = tv2.coords['time'][-1]
×
45
    # find cut locations
UNCOV
46
    cut1 = max([t0_1, t0_2])
×
UNCOV
47
    cut2 = min([tx_1, tx_2])
×
48
    # trim data
UNCOV
49
    tv1 = tv1.sel(time=slice(cut1, cut2))
×
UNCOV
50
    tv1.attrs = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar1].attrs)
×
UNCOV
51
    tv2 = tv2.sel(time=slice(cut1, cut2))
×
UNCOV
52
    tv2.attrs = copy.deepcopy(pyspedas.tplot_tools.data_quants[tvar2].attrs)
×
53
    # Replace the variables if specified
UNCOV
54
    if replace:
×
UNCOV
55
        pyspedas.tplot_tools.data_quants[tvar1] = tv1
×
UNCOV
56
        pyspedas.tplot_tools.data_quants[tvar1].name = tvar1
×
UNCOV
57
        pyspedas.tplot_tools.data_quants[tvar2] = tv2
×
UNCOV
58
        pyspedas.tplot_tools.data_quants[tvar2].name = tvar2
×
UNCOV
59
        return
×
60
    else:
UNCOV
61
       pyspedas.tplot_tools.data_quants[tvar1 + '_cropped'] = copy.deepcopy(tv1)
×
UNCOV
62
       pyspedas.tplot_tools.data_quants[tvar1 + '_cropped'].attrs = copy.deepcopy(tv1.attrs)
×
UNCOV
63
       pyspedas.tplot_tools.data_quants[tvar1 + '_cropped'].name = tvar1+ '_cropped'
×
UNCOV
64
       pyspedas.tplot_tools.data_quants[tvar2 + '_cropped'] = copy.deepcopy(tv2)
×
UNCOV
65
       pyspedas.tplot_tools.data_quants[tvar2 + '_cropped'].attrs = copy.deepcopy(tv2.attrs)
×
UNCOV
66
       pyspedas.tplot_tools.data_quants[tvar2 + '_cropped'].name = tvar2 + '_cropped'
×
UNCOV
67
    return tvar2 + '_cropped'
×
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