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

spedas / pyspedas / 23099976064

15 Mar 2026 12:47AM UTC coverage: 23.685% (-4.9%) from 28.587%
23099976064

push

github

jameswilburlewis
Tweaking the ACE test_data_dir test to see why it's failing in parallel tests

2 of 2 new or added lines in 1 file covered. (100.0%)

4936 existing lines in 87 files now uncovered.

11582 of 48901 relevant lines covered (23.68%)

0.24 hits per line

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

14.29
/pyspedas/tplot_tools/tplot_math/tnormalize.py
1
import numpy as np
1✔
2
from pyspedas.tplot_tools import get_data, store_data
1✔
3

4

5
def tnormalize(variable, newname=None, return_data=False):
1✔
6
    """
7
    Normalize all the vectors stored in a tplot variable
8

9
    Parameters
10
    ----------
11
        variable: str or np.ndarray
12
            tplot variable (or numpy array) containing the vectors to be normalized
13

14
        newname: str, optional
15
            name of the output variable; If not set, output name will be variable + '_normalize'
16
            Default: None
17

18
        return_data: bool, optional
19
            If true, return the normalized vectors instead of creating a tplot variable
20
            Default: False
21
    
22
    Returns
23
    -------
24
        str or ndarray of float
25
            name of the tplot variable created or normalized vectors if return_data is set
26
    
27
    Examples
28
    ---------
29
        >>> import pyspedas
30
        >>> pyspedas.store_data('a', data={'x':[1, 2, 3], 'y':[[1,2,3],[4,5,6],[7,8,9]]})
31
        >>> pyspedas.tnormalize('a')
32

33

34
    """
UNCOV
35
    metadata_in = {}
×
UNCOV
36
    if isinstance(variable, str):
×
UNCOV
37
        data_in = get_data(variable)
×
UNCOV
38
        metadata_in = get_data(variable, metadata=True)
×
UNCOV
39
        data = data_in[1]
×
UNCOV
40
        times = data_in[0]
×
41
    else:
UNCOV
42
        data = np.atleast_2d(variable)
×
UNCOV
43
        times = np.zeros(data.shape[0])
×
44

UNCOV
45
    n = np.sqrt(np.nansum(data**2, axis=1))
×
46

47
    # to do element-wise division, the magnitude needs to be repeated for each component
UNCOV
48
    norm_reshaped = np.reshape(n, [len(times), 1])
×
UNCOV
49
    norm_mag = np.repeat(norm_reshaped, len(data[0, :]), axis=1)
×
50

UNCOV
51
    data_norm = data/norm_mag
×
52

UNCOV
53
    if return_data:
×
UNCOV
54
        return data_norm
×
55
    else:
UNCOV
56
        if newname is None:
×
57
            newname = variable + '_normalized'
×
UNCOV
58
        store_data(newname, data={'x': times, 'y': data_norm}, attr_dict=metadata_in)
×
UNCOV
59
        return newname
×
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