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

sandialabs / sdynpy / 22921275508

10 Mar 2026 07:47PM UTC coverage: 16.669%. Remained the same
22921275508

push

github

dprohe
Merge branch 'main' of github.com:sandialabs/sdynpy

68 of 85 new or added lines in 59 files covered. (80.0%)

4801 existing lines in 47 files now uncovered.

3503 of 21015 relevant lines covered (16.67%)

0.83 hits per line

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

17.65
/src/sdynpy/signal_processing/sdynpy_complex.py
1
# -*- coding: utf-8 -*-
2
"""
3
Functions for dealing with complex numbers
4
"""
5
"""
5✔
6
Copyright 2022 National Technology & Engineering Solutions of Sandia,
7
LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
8
Government retains certain rights in this software.
9

10
This program is free software: you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation, either version 3 of the License, or
13
(at your option) any later version.
14

15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
GNU General Public License for more details.
19

20
You should have received a copy of the GNU General Public License
21
along with this program.  If not, see <https://www.gnu.org/licenses/>.
22
"""
23

24
import numpy as np
5✔
25
import matplotlib.pyplot as plt
5✔
26

27

28
def collapse_complex_to_real(vector, axis=-1, preserve_magnitude=False, plot=False,
5✔
29
                             force_angle=None):
UNCOV
30
    x = np.real(vector)
×
31
    y = np.imag(vector)
×
32
    slope = np.sum(x * y, axis=axis, keepdims=True) / np.sum(x * x, axis=axis, keepdims=True)
×
33
    angle = np.arctan(slope)
×
34
    if force_angle is not None:
×
35
        angle[...] = force_angle
×
36
    rotated_vector = vector * np.exp(-1j * angle)
×
37
    if plot:
×
38
        plt.figure('Complex Rotation')
×
39
        shape = list(vector.shape)
×
40
        shape[axis] = 1
×
41
        for key in np.ndindex(*shape):
×
42
            print(key)
×
43
            index = list(key)
×
44
            index[axis] = slice(None)
×
45
            this_vector = vector[index]
×
46
            this_rotated_vector = rotated_vector[index]
×
47
            plt.plot(np.real(this_vector), np.imag(this_vector), 'x')
×
48
            plt.plot(np.real(this_rotated_vector), np.imag(this_rotated_vector), 'o')
×
49
    if preserve_magnitude:
×
50
        return np.sign(np.real(rotated_vector)) * np.abs(rotated_vector)
×
51
    else:
UNCOV
52
        return np.real(rotated_vector)
×
53

54
def fit_complex_angle(vector,axis=-1):
5✔
UNCOV
55
    x = np.real(vector)
×
56
    y = np.imag(vector)
×
57
    slope = np.sum(x * y, axis=axis, keepdims=True) / np.sum(x * x, axis=axis, keepdims=True)
×
58
    angle = np.arctan(slope)
×
59
    return angle
×
60

61
def rotate_vector(vector,angle):
5✔
UNCOV
62
    return vector * np.exp(1j * angle)
×
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