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

spedas / pyspedas / 16929898973

13 Aug 2025 06:52AM UTC coverage: 89.515% (+0.4%) from 89.086%
16929898973

push

github

jameswilburlewis
Fixing a few missing 'projects.mission' references

18 of 19 new or added lines in 4 files covered. (94.74%)

132 existing lines in 10 files now uncovered.

40006 of 44692 relevant lines covered (89.51%)

0.9 hits per line

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

67.57
/pyspedas/pytplot/tplot_math/join_vec.py
1
import pyspedas
1✔
2
import pandas as pd
1✔
3
import copy
1✔
4
import xarray as xr
1✔
5
import logging
1✔
6

7
from pyspedas.pytplot import convert_tplotxarray_to_pandas_dataframe
1✔
8

9

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

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

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

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

35
    Examples
36
    --------
37
    >>> import pyspedas
38
    >>> import numpy as np
39
    >>> 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]]})
40
    >>> 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]]})
41
    >>> 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]]})
42
    >>> pyspedas.join_vec(['d','e','g'],newname='deg')
43

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

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

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

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

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

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

97
    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