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

sandialabs / sdynpy / 17045898067

18 Aug 2025 04:03PM UTC coverage: 17.141% (+1.5%) from 15.675%
17045898067

Pull #18

github

web-flow
Merge c04c9ac8d into 92b11b3be
Pull Request #18: update to v0.18.2

277 of 2402 new or added lines in 25 files covered. (11.53%)

13 existing lines in 6 files now uncovered.

3231 of 18850 relevant lines covered (17.14%)

0.68 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
"""
1✔
3
Functions for dealing with complex numbers
4

5
Copyright 2022 National Technology & Engineering Solutions of Sandia,
6
LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
7
Government retains certain rights in this software.
8

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

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

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

23
import numpy as np
4✔
24
import matplotlib.pyplot as plt
4✔
25

26

27
def collapse_complex_to_real(vector, axis=-1, preserve_magnitude=False, plot=False,
4✔
28
                             force_angle=None):
29
    x = np.real(vector)
×
30
    y = np.imag(vector)
×
31
    slope = np.sum(x * y, axis=axis, keepdims=True) / np.sum(x * x, axis=axis, keepdims=True)
×
32
    angle = np.arctan(slope)
×
33
    if force_angle is not None:
×
34
        angle[...] = force_angle
×
35
    rotated_vector = vector * np.exp(-1j * angle)
×
36
    if plot:
×
37
        plt.figure('Complex Rotation')
×
38
        shape = list(vector.shape)
×
39
        shape[axis] = 1
×
40
        for key in np.ndindex(*shape):
×
41
            print(key)
×
42
            index = list(key)
×
43
            index[axis] = slice(None)
×
44
            this_vector = vector[index]
×
45
            this_rotated_vector = rotated_vector[index]
×
46
            plt.plot(np.real(this_vector), np.imag(this_vector), 'x')
×
47
            plt.plot(np.real(this_rotated_vector), np.imag(this_rotated_vector), 'o')
×
48
    if preserve_magnitude:
×
49
        return np.sign(np.real(rotated_vector)) * np.abs(rotated_vector)
×
50
    else:
51
        return np.real(rotated_vector)
×
52
    
53
def fit_complex_angle(vector,axis=-1):
4✔
NEW
54
    x = np.real(vector)
×
NEW
55
    y = np.imag(vector)
×
NEW
56
    slope = np.sum(x * y, axis=axis, keepdims=True) / np.sum(x * x, axis=axis, keepdims=True)
×
NEW
57
    angle = np.arctan(slope)
×
NEW
58
    return angle
×
59
    
60
def rotate_vector(vector,angle):
4✔
NEW
61
    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