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

spedas / pyspedas / 25223758709

01 May 2026 04:46PM UTC coverage: 56.446% (-34.1%) from 90.54%
25223758709

push

github

jameswilburlewis
Temporarily disabling Cluster tests due to problems at CSA

27633 of 48955 relevant lines covered (56.45%)

0.56 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
1✔
7
import copy
1✔
8

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