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

spedas / pyspedas / 17001196665

15 Aug 2025 11:12PM UTC coverage: 89.516% (+0.7%) from 88.849%
17001196665

push

github

web-flow
Merge branch 'pyspedas_2_0_dev' into master

5072 of 6199 new or added lines in 413 files covered. (81.82%)

8 existing lines in 2 files now uncovered.

40061 of 44753 relevant lines covered (89.52%)

0.9 hits per line

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

68.42
/pyspedas/tplot_tools/tplot_math/join_vec.py
1
import pyspedas
1✔
2
from pyspedas.tplot_tools import store_data
1✔
3
import pandas as pd
1✔
4
import copy
1✔
5
import xarray as xr
1✔
6
import logging
1✔
7

8
from pyspedas.tplot_tools import convert_tplotxarray_to_pandas_dataframe
1✔
9

10

11
# JOIN TVARS
12
# join TVars into single TVar with multiple columns
13
def join_vec(tvars, newname=None, new_tvar=None, merge=False):
1✔
14
    """
15
    Joins 1D tplot variables into one tplot variable.
16

17
    .. note::
18
        This analysis routine assumes the data is no more than 2 dimensions. If there are more, they may become flattened!
19

20
    Parameters
21
    ----------
22
    tvars : list of str
23
        Name of tplot variables to join together.
24
    newname : str, optional
25
        The name of the new tplot variable. If not specified (the default), a name will be assigned.
26
    new_tvar : str, optional (Deprecated)
27
        The name of the new tplot variable. If not specified, a name will be assigned.
28
    merge : bool, optional
29
        Whether or not to merge the created variable into an older variable.
30
        Default is False.
31

32
    Returns
33
    -------
34
    None
35

36
    Examples
37
    --------
38
    >>> import pyspedas
39
    >>> import numpy as np
40
    >>> pyspedas.store_data('d', data={'x':[2,5,8,11,14,17,21], 'y':[[1,1,50],[2,2,3],[100,4,47],[4,90,5],[5,5,99],[6,6,25],[7,7,-5]]})
41
    >>> pyspedas.store_data('e', data={'x':[2,5,8,11,14,17,21], 'y':[[np.nan,1,1],[np.nan,2,3],[4,np.nan,47],[4,np.nan,5],[5,5,99],[6,6,25],[7,np.nan,-5]]})
42
    >>> pyspedas.store_data('g', data={'x':[0,4,8,12,16,19,21], 'y':[[8,1,1],[100,2,3],[4,2,47],[4,39,5],[5,5,99],[6,6,25],[7,-2,-5]]})
43
    >>> pyspedas.join_vec(['d','e','g'],newname='deg')
44

45
    """
46
    # new_tvar is deprecated in favor of newname
47
    if new_tvar is not None:
1✔
NEW
48
        logging.info(
×
49
            "join_vec: The new_tvar parameter is deprecated. Please use newname instead."
50
        )
NEW
51
        newname = new_tvar
×
52

53
    if not isinstance(tvars, list):
1✔
NEW
54
        tvars = [tvars]
×
55
    if newname is None:
1✔
56
        newname = "-".join(tvars) + "_joined"
1✔
57

58
    to_merge = False
1✔
59
    if newname in pyspedas.tplot_tools.data_quants.keys() and merge:
1✔
NEW
60
        prev_data_quant = pyspedas.tplot_tools.data_quants[newname]
×
NEW
61
        to_merge = True
×
62

63
    for i, val in enumerate(tvars):
1✔
64
        if i == 0:
1✔
65
            if "spec_bins" in pyspedas.tplot_tools.data_quants[tvars[i]].coords:
1✔
NEW
66
                df, s = convert_tplotxarray_to_pandas_dataframe(
×
67
                    tvars[i]
68
                )
69
            else:
70
                df = convert_tplotxarray_to_pandas_dataframe(
1✔
71
                    tvars[i], no_spec_bins=True
72
                )
73
                s = None
1✔
74
        else:
75
            if "spec_bins" in pyspedas.tplot_tools.data_quants[tvars[i]].coords:
1✔
NEW
76
                d = convert_tplotxarray_to_pandas_dataframe(
×
77
                    tvars[i], no_spec_bins=True
78
                )
79
            else:
80
                d = convert_tplotxarray_to_pandas_dataframe(
1✔
81
                    tvars[i], no_spec_bins=True
82
                )
83
            df = pd.concat([df, d], axis=1)
1✔
84

85
    if s is None:
1✔
86
        store_data(newname, data={"x": df.index, "y": df.values})
1✔
87
    else:
NEW
88
        store_data(newname, data={"x": df.index, "y": df.values, "v": s.values})
×
89

90
    if to_merge is True:
1✔
NEW
91
        cur_data_quant = pyspedas.tplot_tools.data_quants[newname]
×
NEW
92
        plot_options = copy.deepcopy(pyspedas.tplot_tools.data_quants[newname].attrs)
×
NEW
93
        pyspedas.tplot_tools.data_quants[newname] = xr.concat(
×
94
            [prev_data_quant, cur_data_quant], dim="time"
95
        ).sortby("time")
NEW
96
        pyspedas.tplot_tools.data_quants[newname].attrs = plot_options
×
97

98
    return newname
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