Skip to content

Commit 8114b56

Browse files
committed
black
1 parent f999a74 commit 8114b56

9 files changed

+622
-412
lines changed

docs/source/conf.py

+21-15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#
1515
import os
1616
import sys
17+
1718
sys.path.insert(0, os.path.abspath('.'))
1819
sys.path.insert(0, os.path.abspath('../..'))
1920

@@ -43,7 +44,7 @@
4344
'sphinx.ext.autodoc',
4445
'sphinx.ext.viewcode',
4546
# Add support for the Google docstring format
46-
'sphinx.ext.napoleon',
47+
'sphinx.ext.napoleon',
4748
]
4849

4950
# Add any paths that contain templates here, relative to this directory.
@@ -90,7 +91,7 @@
9091
# Add any paths that contain custom static files (such as style sheets) here,
9192
# relative to this directory. They are copied after the builtin static files,
9293
# so a file named "default.css" will overwrite the builtin "default.css".
93-
#html_static_path = ['_static']
94+
# html_static_path = ['_static']
9495

9596
# Custom sidebar templates, must be a dictionary that maps document names
9697
# to template names.
@@ -115,15 +116,12 @@
115116
# The paper size ('letterpaper' or 'a4paper').
116117
#
117118
# 'papersize': 'letterpaper',
118-
119119
# The font size ('10pt', '11pt' or '12pt').
120120
#
121121
# 'pointsize': '10pt',
122-
123122
# Additional stuff for the LaTeX preamble.
124123
#
125124
# 'preamble': '',
126-
127125
# Latex figure (float) alignment
128126
#
129127
# 'figure_align': 'htbp',
@@ -133,19 +131,21 @@
133131
# (source start file, target name, title,
134132
# author, documentclass [howto, manual, or own class]).
135133
latex_documents = [
136-
(master_doc, 'pyexsi.tex', 'pyExSi project Documentation',
137-
'Aleš Zorman, Domen Gorjup, Janko Slavič', 'manual'),
134+
(
135+
master_doc,
136+
'pyexsi.tex',
137+
'pyExSi project Documentation',
138+
'Aleš Zorman, Domen Gorjup, Janko Slavič',
139+
'manual',
140+
),
138141
]
139142

140143

141144
# -- Options for manual page output ------------------------------------------
142145

143146
# One entry per manual page. List of tuples
144147
# (source start file, name, description, authors, manual section).
145-
man_pages = [
146-
(master_doc, 'pyExSi_project', 'pyExSi Documentation',
147-
[author], 1)
148-
]
148+
man_pages = [(master_doc, 'pyExSi_project', 'pyExSi Documentation', [author], 1)]
149149

150150

151151
# -- Options for Texinfo output ----------------------------------------------
@@ -154,9 +154,15 @@
154154
# (source start file, target name, title, author,
155155
# dir menu entry, description, category)
156156
texinfo_documents = [
157-
(master_doc, 'pyExSi', 'pyExSi Documentation',
158-
author, 'pyExSi', 'Excitation signals as used in structural dynamics and vibration fatigue',
159-
'Miscellaneous'),
157+
(
158+
master_doc,
159+
'pyExSi',
160+
'pyExSi Documentation',
161+
author,
162+
'pyExSi',
163+
'Excitation signals as used in structural dynamics and vibration fatigue',
164+
'Miscellaneous',
165+
),
160166
]
161167

162168

@@ -178,4 +184,4 @@
178184
epub_exclude_files = ['search.html']
179185

180186

181-
# -- Extension configuration -------------------------------------------------
187+
# -- Extension configuration -------------------------------------------------

example/example_nonstationarity.py

+79-48
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys, os
2+
23
my_path = os.path.dirname(os.path.abspath(__file__))
34
sys.path.insert(0, my_path + '/../')
45

@@ -9,76 +10,102 @@
910
import pyExSi as es
1011

1112

12-
N = 2**16 # number of data points of time signal
13-
fs = 1024 # sampling frequency [Hz]
14-
t = np.arange(0,N)/fs # time vector
13+
N = 2 ** 16 # number of data points of time signal
14+
fs = 1024 # sampling frequency [Hz]
15+
t = np.arange(0, N) / fs # time vector
1516

1617
# define frequency vector and one-sided flat-shaped PSD
17-
M = N // 2 + 1 # number of data points of frequency vector
18-
f = np.arange(0, M, 1) * fs / N # frequency vector
19-
f_min = 50 # PSD upper frequency limit [Hz]
20-
f_max = 100 # PSD lower frequency limit [Hz]
21-
PSD = es.get_psd(f, f_min, f_max) # one-sided flat-shaped PSD
22-
plt.plot(f,PSD)
18+
M = N // 2 + 1 # number of data points of frequency vector
19+
f = np.arange(0, M, 1) * fs / N # frequency vector
20+
f_min = 50 # PSD upper frequency limit [Hz]
21+
f_max = 100 # PSD lower frequency limit [Hz]
22+
PSD = es.get_psd(f, f_min, f_max) # one-sided flat-shaped PSD
23+
plt.plot(f, PSD)
2324
plt.xlabel('Frequency [Hz]')
2425
plt.ylabel('PSD [Unit**2/Hz]')
25-
plt.xlim(0,200)
26+
plt.xlim(0, 200)
2627
plt.show()
2728

2829

29-
#Random Generator seed
30+
# Random Generator seed
3031
seed = 1234
31-
rg = np.random.default_rng(seed) #or rng = np.random.default_rng(seed)
32+
rg = np.random.default_rng(seed) # or rng = np.random.default_rng(seed)
3233

33-
#get gaussian stationary signal
34+
# get gaussian stationary signal
3435
gaussian_signal = es.random_gaussian(N, PSD, fs, rg=rg)
35-
#calculate kurtosis
36+
# calculate kurtosis
3637
k_u_stationary = es.get_kurtosis(gaussian_signal)
3738

38-
#get non-gaussian stationary signal, with kurtosis k_u=10
39+
# get non-gaussian stationary signal, with kurtosis k_u=10
3940
k_u_target = 10
4041
rng = np.random.default_rng(seed)
4142
nongaussian_signal = es.stationary_nongaussian_signal(N, PSD, fs, k_u=k_u_target, rg=rg)
42-
#calculate kurtosis
43+
# calculate kurtosis
4344
k_u_stationary_nongaussian = es.get_kurtosis(nongaussian_signal)
4445

45-
#get non-gaussian non-stationary signal, with kurtosis k_u=10
46-
#a) amplitude modulation, modulating signal defined by PSD
46+
# get non-gaussian non-stationary signal, with kurtosis k_u=10
47+
# a) amplitude modulation, modulating signal defined by PSD
4748
rng = np.random.default_rng(seed)
48-
PSD_modulating = es.get_psd(f, f_low=1, f_high=k_u_target)
49-
plt.plot(f,PSD, label='PSD, carrier signal')
50-
plt.plot(f,PSD_modulating, label='PSD, modulating signal')
49+
PSD_modulating = es.get_psd(f, f_low=1, f_high=k_u_target)
50+
plt.plot(f, PSD, label='PSD, carrier signal')
51+
plt.plot(f, PSD_modulating, label='PSD, modulating signal')
5152
plt.xlabel('Frequency [Hz]')
5253
plt.ylabel('PSD [Unit**2/Hz]')
53-
plt.xlim(0,200)
54+
plt.xlim(0, 200)
5455
plt.legend()
5556
plt.show()
56-
#define array of parameters delta_m and p
57-
delta_m_list = np.arange(.1,2.1,.5)
58-
p_list = np.arange(.1,2.1,.5)
59-
#get signal
60-
nongaussian_nonstationary_signal_psd = es.nonstationary_signal(N,PSD,fs,k_u=k_u_target,modulating_signal=('PSD',PSD_modulating),
61-
param1_list=delta_m_list,param2_list=p_list,seed=seed)
62-
#calculate kurtosis
63-
k_u_nonstationary_nongaussian_psd = es.get_kurtosis(nongaussian_nonstationary_signal_psd)
57+
# define array of parameters delta_m and p
58+
delta_m_list = np.arange(0.1, 2.1, 0.5)
59+
p_list = np.arange(0.1, 2.1, 0.5)
60+
# get signal
61+
nongaussian_nonstationary_signal_psd = es.nonstationary_signal(
62+
N,
63+
PSD,
64+
fs,
65+
k_u=k_u_target,
66+
modulating_signal=('PSD', PSD_modulating),
67+
param1_list=delta_m_list,
68+
param2_list=p_list,
69+
seed=seed,
70+
)
71+
# calculate kurtosis
72+
k_u_nonstationary_nongaussian_psd = es.get_kurtosis(
73+
nongaussian_nonstationary_signal_psd
74+
)
6475

65-
#b) amplitude modulation, modulating signal defined by cubis spline intepolation. Points are based on beta distribution
66-
#Points are separated by delta_n = 2**8 samples (at fs=2**10)
67-
delta_n = 2**10
68-
#define array of parameters alpha and beta
69-
alpha_list = np.arange(1,10,1)
70-
beta_list = np.arange(1,10,1)
71-
#get signal
72-
nongaussian_nonstationary_signal_beta = es.nonstationary_signal(N,PSD,fs,k_u=k_u_target,modulating_signal=('CSI',delta_n),
73-
param1_list=alpha_list,param2_list=beta_list,seed=seed)
74-
#calculate kurtosis
75-
k_u_nonstationary_nongaussian_beta = es.get_kurtosis(nongaussian_nonstationary_signal_beta)
76+
# b) amplitude modulation, modulating signal defined by cubis spline intepolation. Points are based on beta distribution
77+
# Points are separated by delta_n = 2**8 samples (at fs=2**10)
78+
delta_n = 2 ** 10
79+
# define array of parameters alpha and beta
80+
alpha_list = np.arange(1, 10, 1)
81+
beta_list = np.arange(1, 10, 1)
82+
# get signal
83+
nongaussian_nonstationary_signal_beta = es.nonstationary_signal(
84+
N,
85+
PSD,
86+
fs,
87+
k_u=k_u_target,
88+
modulating_signal=('CSI', delta_n),
89+
param1_list=alpha_list,
90+
param2_list=beta_list,
91+
seed=seed,
92+
)
93+
# calculate kurtosis
94+
k_u_nonstationary_nongaussian_beta = es.get_kurtosis(
95+
nongaussian_nonstationary_signal_beta
96+
)
7697

77-
#Plot
78-
plt.plot(gaussian_signal[:200], label = 'Gaussian')
79-
plt.plot(nongaussian_signal[:200], label = 'non-Gaussian stationary')
80-
plt.plot(nongaussian_nonstationary_signal_psd[:200], label = 'non-Gaussian non-stationary (PSD)')
81-
plt.plot(nongaussian_nonstationary_signal_beta[:200], label = 'non-Gaussian non-stationary (CSI)')
98+
# Plot
99+
plt.plot(gaussian_signal[:200], label='Gaussian')
100+
plt.plot(nongaussian_signal[:200], label='non-Gaussian stationary')
101+
plt.plot(
102+
nongaussian_nonstationary_signal_psd[:200],
103+
label='non-Gaussian non-stationary (PSD)',
104+
)
105+
plt.plot(
106+
nongaussian_nonstationary_signal_beta[:200],
107+
label='non-Gaussian non-stationary (CSI)',
108+
)
82109
plt.xlabel('Sample [n]')
83110
plt.ylabel('Signal [Unit]')
84111
plt.legend()
@@ -87,5 +114,9 @@
87114
print(f'kurtosis of stationary Gaussian signal:{k_u_stationary:.3f}')
88115
print(f'Desired kurtosis of non-Gaussian signals:{k_u_target:.3f}')
89116
print(f'kurtosis of stationary non-Gaussian signal:{k_u_stationary_nongaussian:.3f}')
90-
print(f'kurtosis of non-stationary non-Gaussian signal (psd):{k_u_nonstationary_nongaussian_psd:.3f}')
91-
print(f'kurtosis of non-stationary non-Gaussian signal (beta):{k_u_nonstationary_nongaussian_beta:.3f}')
117+
print(
118+
f'kurtosis of non-stationary non-Gaussian signal (psd):{k_u_nonstationary_nongaussian_psd:.3f}'
119+
)
120+
print(
121+
f'kurtosis of non-stationary non-Gaussian signal (beta):{k_u_nonstationary_nongaussian_beta:.3f}'
122+
)

example/example_signals.py

+40-23
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,57 @@
11
import sys, os
2+
23
my_path = os.path.dirname(os.path.abspath(__file__))
34
sys.path.insert(0, my_path + '/../')
45

56
import numpy as np
67
import matplotlib.pyplot as plt
78
import pyExSi as es
89

9-
#impact pulse
10-
width = 300
11-
N = 2*width
10+
# impact pulse
11+
width = 300
12+
N = 2 * width
1213
n_start = 90
1314
amplitude = 3
14-
#pulse_sine = es.impulse(N=N, n_start=n_start, width=width, amplitude=amplitude, window='sine')
15-
pulse_sine = es.impulse(N=N, n_start=n_start, width=width, amplitude=amplitude, window='sine')
16-
pulse_rectangular = es.impulse(N=N, n_start=n_start, width=width, amplitude=amplitude, window='boxcar')
17-
pulse_triangular = es.impulse(N=N, n_start=n_start, width=width, amplitude=amplitude, window='triang')
18-
pulse_exponential = es.impulse(N=N, n_start=n_start, width=width, amplitude=amplitude, window=('exponential',None,10))
19-
pulse_sawtooth = es.impulse(N=N, n_start=n_start, width=width, amplitude=amplitude, window='sawtooth')
15+
# pulse_sine = es.impulse(N=N, n_start=n_start, width=width, amplitude=amplitude, window='sine')
16+
pulse_sine = es.impulse(
17+
N=N, n_start=n_start, width=width, amplitude=amplitude, window='sine'
18+
)
19+
pulse_rectangular = es.impulse(
20+
N=N, n_start=n_start, width=width, amplitude=amplitude, window='boxcar'
21+
)
22+
pulse_triangular = es.impulse(
23+
N=N, n_start=n_start, width=width, amplitude=amplitude, window='triang'
24+
)
25+
pulse_exponential = es.impulse(
26+
N=N,
27+
n_start=n_start,
28+
width=width,
29+
amplitude=amplitude,
30+
window=('exponential', None, 10),
31+
)
32+
pulse_sawtooth = es.impulse(
33+
N=N, n_start=n_start, width=width, amplitude=amplitude, window='sawtooth'
34+
)
2035
plt.plot(pulse_sine, '-', label='sine')
2136
plt.plot(pulse_rectangular, '-', label='rectangular')
22-
plt.plot(pulse_triangular, '-', label = 'triangular')
23-
plt.plot(pulse_exponential, '-', label = 'exponential')
24-
plt.plot(pulse_sawtooth, '-', label = 'sawtooth')
37+
plt.plot(pulse_triangular, '-', label='triangular')
38+
plt.plot(pulse_exponential, '-', label='exponential')
39+
plt.plot(pulse_sawtooth, '-', label='sawtooth')
2540
plt.xlabel('Sample [n]')
2641
plt.ylabel('Impact pulse [Unit]')
2742
plt.legend(loc='upper right')
2843
plt.show()
2944

3045

31-
#Random Generator
46+
# Random Generator
3247
seed = 1234
33-
rg = np.random.default_rng(seed) #or rng = np.random.default_rng(seed)
48+
rg = np.random.default_rng(seed) # or rng = np.random.default_rng(seed)
3449

35-
#uniform random, normal random and pseudo random
50+
# uniform random, normal random and pseudo random
3651
N = 1000
37-
uniform_random = es.uniform_random(N=N,rg=rg)
38-
normal_random = es.normal_random(N=N,rg=rg)
39-
pseudo_random = es.pseudo_random(N=N,rg=rg)
52+
uniform_random = es.uniform_random(N=N, rg=rg)
53+
normal_random = es.normal_random(N=N, rg=rg)
54+
pseudo_random = es.pseudo_random(N=N, rg=rg)
4055
plt.plot(uniform_random, label='uniform random')
4156
plt.plot(normal_random, label='normal random')
4257
plt.plot(pseudo_random, label='pseudo random')
@@ -47,20 +62,22 @@
4762
print(uniform_random[:5])
4863

4964

50-
#burst random
65+
# burst random
5166
N = 1000
5267
amplitude = 5
53-
burst_random = es.burst_random(N, A=amplitude, ratio=0.1, distribution='normal', n_bursts=3, rg=rg)
68+
burst_random = es.burst_random(
69+
N, A=amplitude, ratio=0.1, distribution='normal', n_bursts=3, rg=rg
70+
)
5471
plt.plot(burst_random)
5572
plt.xlabel('Sample [n]')
5673
plt.ylabel('Burst [Unit]')
5774
plt.show()
5875

5976

60-
#sweep
61-
t = np.linspace(0,10,1000)
77+
# sweep
78+
t = np.linspace(0, 10, 1000)
6279
sweep = es.sine_sweep(time=t, f_start=0, f_stop=5)
6380
plt.plot(t, sweep)
6481
plt.xlabel('Time [s]')
6582
plt.ylabel('Sine sweep [Unit]')
66-
plt.show()
83+
plt.show()

pyExSi/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__version__ = '0.1'
2-
from .signals import *
2+
from .signals import *

0 commit comments

Comments
 (0)