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

spedas / pyspedas / 23369877357

21 Mar 2026 02:13AM UTC coverage: 90.512% (+0.02%) from 90.497%
23369877357

push

github

web-flow
Merge pull request #1342 from spedas/t_1341

Adds support to load USGS Variometer data, adds test cases for loading variometer data.

13 of 48 new or added lines in 3 files covered. (27.08%)

10491 existing lines in 260 files now uncovered.

44303 of 48947 relevant lines covered (90.51%)

1.6 hits per line

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

100.0
/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
2✔
7
import copy
2✔
8

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