pyExSi 0.43.3__tar.gz → 0.44.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyexsi-0.43.3 → pyexsi-0.44.0}/.github/workflows/python-package.yml +1 -1
- pyexsi-0.44.0/.github/workflows/release-and-publish-to-pypi.yml +53 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/PKG-INFO +34 -15
- pyexsi-0.44.0/docs/requirements.txt +5 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/docs/source/index.rst +3 -0
- pyexsi-0.44.0/pyExSi/__init__.py +16 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/pyproject.toml +10 -9
- {pyexsi-0.43.3 → pyexsi-0.44.0}/readme.rst +23 -5
- {pyexsi-0.43.3 → pyexsi-0.44.0}/readthedocs.yaml +1 -1
- pyexsi-0.44.0/requirements.txt +2 -0
- pyexsi-0.44.0/tests/test_port.py +26 -0
- pyexsi-0.43.3/.github/workflows/release-and-publish-to-pypi.yml +0 -28
- pyexsi-0.43.3/docs/requirements.txt +0 -3
- pyexsi-0.43.3/pyExSi/__init__.py +0 -2
- pyexsi-0.43.3/pyExSi/signals.py +0 -854
- pyexsi-0.43.3/requirements.txt +0 -2
- {pyexsi-0.43.3 → pyexsi-0.44.0}/.gitignore +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/CONTRIBUTING.rst +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/LICENSE +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/Showcase.ipynb +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/docs/Makefile +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/docs/make.bat +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/docs/source/code.rst +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/docs/source/conf.py +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/docs/source/examples/example_nonstationarity.rst +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/docs/source/examples/example_signals.rst +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/docs/source/examples.rst +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/docs/source/getting_started.rst +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/example/example_nonstationarity.py +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/example/example_signals.py +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/requirements.dev.txt +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/setup.py +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/tests/generate_freezed_data.py +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/tests/test_basic.py +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/tests/test_data_nonstationarity.pkl +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/tests/test_data_signals.pkl +0 -0
- {pyexsi-0.43.3 → pyexsi-0.44.0}/tests/test_scipy_chirp.py +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: Release and Publish to PyPI
|
|
2
|
+
|
|
3
|
+
# Creating a GitHub Release (or pushing a tag vX.Y.Z) runs the tests, checks
|
|
4
|
+
# that the tag matches the version in pyproject.toml,
|
|
5
|
+
# builds the package and publishes it to PyPI through trusted publishing
|
|
6
|
+
# (no API token: PyPI trusts this workflow's OIDC token, see
|
|
7
|
+
# https://docs.pypi.org/trusted-publishers/).
|
|
8
|
+
|
|
9
|
+
on:
|
|
10
|
+
push:
|
|
11
|
+
tags:
|
|
12
|
+
- 'v*'
|
|
13
|
+
|
|
14
|
+
permissions:
|
|
15
|
+
id-token: write
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
publish:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
steps:
|
|
22
|
+
- name: Checkout code
|
|
23
|
+
uses: actions/checkout@v7
|
|
24
|
+
|
|
25
|
+
- name: Set up Python
|
|
26
|
+
uses: actions/setup-python@v7
|
|
27
|
+
with:
|
|
28
|
+
python-version: '3.13'
|
|
29
|
+
|
|
30
|
+
- name: Check that the tag matches the package version
|
|
31
|
+
run: |
|
|
32
|
+
tag="${GITHUB_REF#refs/tags/v}"
|
|
33
|
+
version=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
|
|
34
|
+
if [ "$tag" != "$version" ]; then
|
|
35
|
+
echo "tag v$tag and pyproject.toml $version do not agree" >&2
|
|
36
|
+
exit 1
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
- name: Install dependencies
|
|
40
|
+
run: pip install -U build twine pytest
|
|
41
|
+
|
|
42
|
+
- name: Run tests
|
|
43
|
+
run: |
|
|
44
|
+
pip install .
|
|
45
|
+
pytest
|
|
46
|
+
|
|
47
|
+
- name: Build package
|
|
48
|
+
run: |
|
|
49
|
+
python -m build
|
|
50
|
+
python -m twine check dist/*
|
|
51
|
+
|
|
52
|
+
- name: Publish to PyPI
|
|
53
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: pyExSi
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Excitation signals as used in structural dynamics and vibration fatigue.
|
|
3
|
+
Version: 0.44.0
|
|
4
|
+
Summary: Excitation signals as used in structural dynamics and vibration fatigue (port of sdypy-excitation).
|
|
5
5
|
Project-URL: homepage, https://github.com/ladisk/pyExSi
|
|
6
6
|
Project-URL: documentation, https://pyexsi.readthedocs.io/en/latest/index.html
|
|
7
|
-
Project-URL: source, https://github.com/sdypy/
|
|
7
|
+
Project-URL: source, https://github.com/sdypy/sdypy-excitation
|
|
8
|
+
Project-URL: issues, https://github.com/sdypy/sdypy-excitation/issues
|
|
8
9
|
Author-email: "Aleš Zorman, Domen Gorjup, Janko Slavič" <janko.slavic@fs.uni-lj.si>
|
|
9
10
|
Maintainer-email: "Janko Slavič, Domen Gorjup, Aleš Zorman" <janko.slavic@fs.uni-lj.si>
|
|
10
11
|
License-Expression: MIT
|
|
@@ -13,17 +14,17 @@ Keywords: dynamic testing,excitation signal,structural dynamics
|
|
|
13
14
|
Classifier: Development Status :: 3 - Alpha
|
|
14
15
|
Classifier: Intended Audience :: Developers
|
|
15
16
|
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
17
20
|
Classifier: Topic :: Scientific/Engineering
|
|
18
|
-
Requires-Python: >=3.
|
|
19
|
-
Requires-Dist:
|
|
20
|
-
Requires-Dist: pylint
|
|
21
|
-
Requires-Dist: pytest
|
|
22
|
-
Requires-Dist: scipy
|
|
21
|
+
Requires-Python: >=3.13
|
|
22
|
+
Requires-Dist: sdypy-excitation==0.44.0
|
|
23
23
|
Provides-Extra: dev
|
|
24
24
|
Requires-Dist: black; extra == 'dev'
|
|
25
25
|
Requires-Dist: build; extra == 'dev'
|
|
26
26
|
Requires-Dist: matplotlib; extra == 'dev'
|
|
27
|
+
Requires-Dist: pylint; extra == 'dev'
|
|
27
28
|
Requires-Dist: pytest; extra == 'dev'
|
|
28
29
|
Requires-Dist: sphinx; extra == 'dev'
|
|
29
30
|
Requires-Dist: sphinx-copybutton>=0.5.2; extra == 'dev'
|
|
@@ -32,10 +33,26 @@ Requires-Dist: twine; extra == 'dev'
|
|
|
32
33
|
Requires-Dist: wheel; extra == 'dev'
|
|
33
34
|
Description-Content-Type: text/x-rst
|
|
34
35
|
|
|
35
|
-
|DOI| |
|
|
36
|
+
|DOI| |pytest| |Docs Status|
|
|
36
37
|
|
|
37
38
|
pyExSi - Excitation signals as used in structural dynamics and vibration fatigue
|
|
38
39
|
--------------------------------------------------------------------------------
|
|
40
|
+
``pyExSi`` is a port of `sdypy-excitation`_, which is part of the `SDyPy`_ project. The code is
|
|
41
|
+
maintained in ``sdypy-excitation``; this package makes the same code available under the
|
|
42
|
+
``pyExSi`` name, so that existing code keeps working.
|
|
43
|
+
|
|
44
|
+
**Please report issues and open pull requests at** `sdypy-excitation`_.
|
|
45
|
+
|
|
46
|
+
Installing ``pyExSi`` also installs ``sdypy-excitation``. For new code, use it directly:
|
|
47
|
+
|
|
48
|
+
.. code:: cmd
|
|
49
|
+
|
|
50
|
+
pip install sdypy-excitation
|
|
51
|
+
|
|
52
|
+
.. code:: python
|
|
53
|
+
|
|
54
|
+
from sdypy.excitation import random_gaussian
|
|
55
|
+
|
|
39
56
|
Supported excitation signals are:
|
|
40
57
|
|
|
41
58
|
- pulse (e.g. half-sine)
|
|
@@ -78,7 +95,7 @@ A simple example on how to generate random signals on PSD basis:
|
|
|
78
95
|
PSD = es.get_psd(freq, freq_lower, freq_upper) # one-sided flat-shaped PSD
|
|
79
96
|
|
|
80
97
|
#get gaussian stationary signal
|
|
81
|
-
gausian_signal = es.random_gaussian(
|
|
98
|
+
gausian_signal = es.random_gaussian(N, PSD, fs)
|
|
82
99
|
|
|
83
100
|
#get non-gaussian non-stationary signal, with kurtosis k_u=10
|
|
84
101
|
#amplitude modulation, modulating signal defined by PSD
|
|
@@ -91,9 +108,11 @@ A simple example on how to generate random signals on PSD basis:
|
|
|
91
108
|
|
|
92
109
|
.. |Docs Status| image:: https://readthedocs.org/projects/pyexsi/badge/
|
|
93
110
|
:target: https://pyexsi.readthedocs.io
|
|
94
|
-
|
|
95
|
-
..
|
|
96
|
-
|
|
111
|
+
|
|
112
|
+
.. _sdypy-excitation: https://github.com/sdypy/sdypy-excitation
|
|
113
|
+
.. _SDyPy: https://github.com/sdypy
|
|
114
|
+
.. |pytest| image:: https://github.com/ladisk/pyExSi/actions/workflows/python-package.yml/badge.svg
|
|
115
|
+
:target: https://github.com/ladisk/pyExSi/actions
|
|
97
116
|
|
|
98
117
|
.. |DOI| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.4431844.svg
|
|
99
118
|
:target: https://doi.org/10.5281/zenodo.4431844
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
Welcome to the pyExSi project's documentation!
|
|
7
7
|
===============================================================
|
|
8
8
|
|
|
9
|
+
pyExSi is a port of `sdypy-excitation <https://github.com/sdypy/sdypy-excitation>`_,
|
|
10
|
+
where the code is maintained.
|
|
11
|
+
|
|
9
12
|
.. toctree::
|
|
10
13
|
:maxdepth: 2
|
|
11
14
|
:caption: Contents:
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Excitation signals as used in structural dynamics and vibration fatigue.
|
|
2
|
+
|
|
3
|
+
pyExSi is a port of sdypy-excitation (https://github.com/sdypy/sdypy-excitation),
|
|
4
|
+
where the code is maintained. This package re-exports sdypy.excitation.signals
|
|
5
|
+
under the pyExSi name.
|
|
6
|
+
"""
|
|
7
|
+
__version__ = '0.44.0'
|
|
8
|
+
|
|
9
|
+
import sys as _sys
|
|
10
|
+
|
|
11
|
+
from sdypy.excitation import signals
|
|
12
|
+
from sdypy.excitation.signals import *
|
|
13
|
+
|
|
14
|
+
# Register the submodule under the pyExSi name, so that `import pyExSi.signals`
|
|
15
|
+
# returns sdypy.excitation.signals instead of looking for a file in this package.
|
|
16
|
+
_sys.modules[f"{__name__}.signals"] = signals
|
|
@@ -4,25 +4,24 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pyExSi"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.44.0"
|
|
8
8
|
authors = [{name = "Aleš Zorman, Domen Gorjup, Janko Slavič", email = "janko.slavic@fs.uni-lj.si"}]
|
|
9
9
|
maintainers = [{name = "Janko Slavič, Domen Gorjup, Aleš Zorman", email = "janko.slavic@fs.uni-lj.si"}]
|
|
10
10
|
license = "MIT"
|
|
11
|
-
description = "Excitation signals as used in structural dynamics and vibration fatigue."
|
|
11
|
+
description = "Excitation signals as used in structural dynamics and vibration fatigue (port of sdypy-excitation)."
|
|
12
12
|
readme = "readme.rst"
|
|
13
13
|
keywords = ["excitation signal", "structural dynamics", "dynamic testing"]
|
|
14
|
-
requires-python = ">=3.
|
|
14
|
+
requires-python = ">=3.13"
|
|
15
15
|
dependencies = [
|
|
16
|
-
"
|
|
17
|
-
"scipy",
|
|
18
|
-
"pylint",
|
|
19
|
-
"pytest",
|
|
16
|
+
"sdypy-excitation==0.44.0",
|
|
20
17
|
]
|
|
21
18
|
classifiers = [
|
|
22
19
|
'Development Status :: 3 - Alpha',
|
|
23
20
|
'Intended Audience :: Developers',
|
|
24
21
|
'Topic :: Scientific/Engineering',
|
|
25
|
-
'Programming Language :: Python :: 3.
|
|
22
|
+
'Programming Language :: Python :: 3.13',
|
|
23
|
+
'Programming Language :: Python :: 3.14',
|
|
24
|
+
'Programming Language :: Python :: 3.15',
|
|
26
25
|
"License :: OSI Approved :: MIT License",
|
|
27
26
|
]
|
|
28
27
|
|
|
@@ -37,9 +36,11 @@ dev = [
|
|
|
37
36
|
"matplotlib",
|
|
38
37
|
"sphinx-copybutton>=0.5.2",
|
|
39
38
|
"black",
|
|
39
|
+
"pylint",
|
|
40
40
|
]
|
|
41
41
|
|
|
42
42
|
[project.urls]
|
|
43
43
|
homepage = "https://github.com/ladisk/pyExSi"
|
|
44
44
|
documentation = "https://pyexsi.readthedocs.io/en/latest/index.html"
|
|
45
|
-
source = "https://github.com/sdypy/
|
|
45
|
+
source = "https://github.com/sdypy/sdypy-excitation"
|
|
46
|
+
issues = "https://github.com/sdypy/sdypy-excitation/issues"
|
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
|DOI| |
|
|
1
|
+
|DOI| |pytest| |Docs Status|
|
|
2
2
|
|
|
3
3
|
pyExSi - Excitation signals as used in structural dynamics and vibration fatigue
|
|
4
4
|
--------------------------------------------------------------------------------
|
|
5
|
+
``pyExSi`` is a port of `sdypy-excitation`_, which is part of the `SDyPy`_ project. The code is
|
|
6
|
+
maintained in ``sdypy-excitation``; this package makes the same code available under the
|
|
7
|
+
``pyExSi`` name, so that existing code keeps working.
|
|
8
|
+
|
|
9
|
+
**Please report issues and open pull requests at** `sdypy-excitation`_.
|
|
10
|
+
|
|
11
|
+
Installing ``pyExSi`` also installs ``sdypy-excitation``. For new code, use it directly:
|
|
12
|
+
|
|
13
|
+
.. code:: cmd
|
|
14
|
+
|
|
15
|
+
pip install sdypy-excitation
|
|
16
|
+
|
|
17
|
+
.. code:: python
|
|
18
|
+
|
|
19
|
+
from sdypy.excitation import random_gaussian
|
|
20
|
+
|
|
5
21
|
Supported excitation signals are:
|
|
6
22
|
|
|
7
23
|
- pulse (e.g. half-sine)
|
|
@@ -44,7 +60,7 @@ A simple example on how to generate random signals on PSD basis:
|
|
|
44
60
|
PSD = es.get_psd(freq, freq_lower, freq_upper) # one-sided flat-shaped PSD
|
|
45
61
|
|
|
46
62
|
#get gaussian stationary signal
|
|
47
|
-
gausian_signal = es.random_gaussian(
|
|
63
|
+
gausian_signal = es.random_gaussian(N, PSD, fs)
|
|
48
64
|
|
|
49
65
|
#get non-gaussian non-stationary signal, with kurtosis k_u=10
|
|
50
66
|
#amplitude modulation, modulating signal defined by PSD
|
|
@@ -57,9 +73,11 @@ A simple example on how to generate random signals on PSD basis:
|
|
|
57
73
|
|
|
58
74
|
.. |Docs Status| image:: https://readthedocs.org/projects/pyexsi/badge/
|
|
59
75
|
:target: https://pyexsi.readthedocs.io
|
|
60
|
-
|
|
61
|
-
..
|
|
62
|
-
|
|
76
|
+
|
|
77
|
+
.. _sdypy-excitation: https://github.com/sdypy/sdypy-excitation
|
|
78
|
+
.. _SDyPy: https://github.com/sdypy
|
|
79
|
+
.. |pytest| image:: https://github.com/ladisk/pyExSi/actions/workflows/python-package.yml/badge.svg
|
|
80
|
+
:target: https://github.com/ladisk/pyExSi/actions
|
|
63
81
|
|
|
64
82
|
.. |DOI| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.4431844.svg
|
|
65
83
|
:target: https://doi.org/10.5281/zenodo.4431844
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Check that pyExSi exposes exactly the sdypy-excitation code."""
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
import sdypy.excitation
|
|
5
|
+
import sdypy.excitation.signals
|
|
6
|
+
import pyExSi
|
|
7
|
+
|
|
8
|
+
NAMES = [n for n in dir(sdypy.excitation.signals) if not n.startswith('_')]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.mark.parametrize("name", NAMES)
|
|
12
|
+
def test_names(name):
|
|
13
|
+
assert getattr(pyExSi, name) is getattr(sdypy.excitation.signals, name)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.mark.parametrize("name", sdypy.excitation.__all__)
|
|
17
|
+
def test_public_names(name):
|
|
18
|
+
assert getattr(pyExSi, name) is getattr(sdypy.excitation, name)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_signals_module():
|
|
22
|
+
import pyExSi.signals
|
|
23
|
+
from pyExSi.signals import random_gaussian
|
|
24
|
+
|
|
25
|
+
assert pyExSi.signals is sdypy.excitation.signals
|
|
26
|
+
assert random_gaussian is sdypy.excitation.random_gaussian
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
name: Release and Publish to PyPI
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
tags:
|
|
5
|
-
- 'v*'
|
|
6
|
-
jobs:
|
|
7
|
-
publish:
|
|
8
|
-
runs-on: ubuntu-latest
|
|
9
|
-
steps:
|
|
10
|
-
- name: Checkout code
|
|
11
|
-
uses: actions/checkout@v2
|
|
12
|
-
|
|
13
|
-
- name: Set up Python
|
|
14
|
-
uses: actions/setup-python@v2
|
|
15
|
-
with:
|
|
16
|
-
python-version: '3.11'
|
|
17
|
-
|
|
18
|
-
- name: Install dependencies
|
|
19
|
-
run: pip install -U build
|
|
20
|
-
|
|
21
|
-
- name: Build package
|
|
22
|
-
run: python -m build
|
|
23
|
-
|
|
24
|
-
- name: Publish to PyPI
|
|
25
|
-
uses: pypa/gh-action-pypi-publish@v1.4.2
|
|
26
|
-
with:
|
|
27
|
-
user: __token__
|
|
28
|
-
password: ${{ secrets.PYPI_API_TOKEN }}
|
pyexsi-0.43.3/pyExSi/__init__.py
DELETED
pyexsi-0.43.3/pyExSi/signals.py
DELETED
|
@@ -1,854 +0,0 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
from scipy.stats import moment, beta
|
|
3
|
-
from scipy.interpolate import CubicSpline
|
|
4
|
-
from scipy import signal
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def uniform_random(N, rg=None):
|
|
8
|
-
"""
|
|
9
|
-
Uniform random distribution
|
|
10
|
-
|
|
11
|
-
:param N: Number of points.
|
|
12
|
-
:type N: int
|
|
13
|
-
:param rg: Initialized Generator object
|
|
14
|
-
:type rg: numpy.random._generator.Generator
|
|
15
|
-
:returns: Random samples from a “uniform” distribution
|
|
16
|
-
|
|
17
|
-
Example
|
|
18
|
-
--------
|
|
19
|
-
>>> import numpy as np
|
|
20
|
-
>>> import matplotlib.pyplot as plt
|
|
21
|
-
>>> import pyExSi as es
|
|
22
|
-
|
|
23
|
-
>>> N = 100
|
|
24
|
-
>>> x = es.uniform_random(N=N)
|
|
25
|
-
>>> plt.plot(x)
|
|
26
|
-
>>> plt.show()
|
|
27
|
-
"""
|
|
28
|
-
if rg == None:
|
|
29
|
-
rg = np.random.default_rng()
|
|
30
|
-
if isinstance(rg, np.random._generator.Generator):
|
|
31
|
-
burst = rg.uniform(size=N) - 0.5
|
|
32
|
-
else:
|
|
33
|
-
raise ValueError(
|
|
34
|
-
'`rg` must be initialized Generator object (numpy.random._generator.Generator)!'
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
return burst / np.max(np.abs(burst))
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def normal_random(N, rg=None):
|
|
41
|
-
"""
|
|
42
|
-
Normal random distribution.
|
|
43
|
-
|
|
44
|
-
:param N: Number of points.
|
|
45
|
-
:type N: int
|
|
46
|
-
:param rg: Initialized Generator object
|
|
47
|
-
:type rg: numpy.random._generator.Generator
|
|
48
|
-
:returns: Random samples from the “standard normal” distribution
|
|
49
|
-
|
|
50
|
-
Example
|
|
51
|
-
--------
|
|
52
|
-
>>> import numpy as np
|
|
53
|
-
>>> import matplotlib.pyplot as plt
|
|
54
|
-
>>> import pyExSi as es
|
|
55
|
-
|
|
56
|
-
>>> N = 100
|
|
57
|
-
>>> x = es.uniform_random(N=N)
|
|
58
|
-
>>> plt.plot(x)
|
|
59
|
-
>>> plt.show()
|
|
60
|
-
"""
|
|
61
|
-
if rg == None:
|
|
62
|
-
rg = np.random.default_rng()
|
|
63
|
-
if isinstance(rg, np.random._generator.Generator):
|
|
64
|
-
burst = rg.standard_normal(size=N)
|
|
65
|
-
else:
|
|
66
|
-
raise ValueError(
|
|
67
|
-
'`rg` must be initialized Generator object (numpy.random._generator.Generator)!'
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
return burst / np.max(np.abs(burst))
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def pseudo_random(N, rg=None):
|
|
74
|
-
"""
|
|
75
|
-
Pseudorandom distribution.
|
|
76
|
-
|
|
77
|
-
Generated random data has amplitude spectrum of magnuted 1 and
|
|
78
|
-
uniformly distributed phase.
|
|
79
|
-
|
|
80
|
-
:param N: Number of points.
|
|
81
|
-
:type N: int
|
|
82
|
-
:param rg: Initialized Generator object
|
|
83
|
-
:type rg: numpy.random._generator.Generator
|
|
84
|
-
:returns: Random samples with amplitude spectrum of magnuted 1 and
|
|
85
|
-
uniformly distributed phase.
|
|
86
|
-
|
|
87
|
-
Example
|
|
88
|
-
--------
|
|
89
|
-
>>> import numpy as np
|
|
90
|
-
>>> import matplotlib.pyplot as plt
|
|
91
|
-
>>> import pyExSi as es
|
|
92
|
-
|
|
93
|
-
>>> N = 100
|
|
94
|
-
>>> x = es.pseudo_random(N=N)
|
|
95
|
-
>>> plt.plot(x)
|
|
96
|
-
>>> plt.show()
|
|
97
|
-
"""
|
|
98
|
-
R = np.ones(N // 2 + 1, complex)
|
|
99
|
-
|
|
100
|
-
if rg == None:
|
|
101
|
-
rg = np.random.default_rng()
|
|
102
|
-
if isinstance(rg, np.random._generator.Generator):
|
|
103
|
-
R_prand = R * np.exp(1j * rg.uniform(size=len(R)) * 2 * np.pi)
|
|
104
|
-
else:
|
|
105
|
-
raise ValueError(
|
|
106
|
-
'`rg` must be initialized Generator object (numpy.random._generator.Generator)!'
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
burst = np.fft.irfft(R_prand, n=N)
|
|
110
|
-
return burst / np.max(np.abs(burst))
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def burst_random(
|
|
114
|
-
N,
|
|
115
|
-
A=1.0,
|
|
116
|
-
ratio=0.5,
|
|
117
|
-
distribution='uniform',
|
|
118
|
-
n_bursts=1,
|
|
119
|
-
periodic_bursts=True,
|
|
120
|
-
rg=None,
|
|
121
|
-
):
|
|
122
|
-
"""
|
|
123
|
-
Generate a zero-mean burst random excitation signal time series.
|
|
124
|
-
|
|
125
|
-
:param N: Number of time points.
|
|
126
|
-
:param A: Amplitude of the random signal. For 'uniform' distribution, this
|
|
127
|
-
is the peak-to-peak amplitude, for 'normal' distribution this is the RMS.
|
|
128
|
-
:param ratio: The ratio of burst legth ot the total legth of the time series.
|
|
129
|
-
:param distribution: 'uniform', 'normal' or 'pseudorandom'. Defaults to 'uniform'.
|
|
130
|
-
:param n_bursts: Number of burst repetition. The output time series will
|
|
131
|
-
have `N*n_bursts` points. Defaults to 1.
|
|
132
|
-
:param periodic_bursts: If True, bursts are periodically repeated `n_bursts` times,
|
|
133
|
-
otherwise a uniquely random burst is generated for each repetition.
|
|
134
|
-
Defaults to True.
|
|
135
|
-
:param rg: Initialized Generator object
|
|
136
|
-
:type rg: numpy.random._generator.Generator
|
|
137
|
-
:returns: Burst random signal time series.
|
|
138
|
-
|
|
139
|
-
Example
|
|
140
|
-
--------
|
|
141
|
-
>>> import numpy as np
|
|
142
|
-
>>> import matplotlib.pyplot as plt
|
|
143
|
-
>>> import pyExSi as es
|
|
144
|
-
|
|
145
|
-
>>> N = 1000
|
|
146
|
-
>>> amplitude = 5
|
|
147
|
-
>>> x = es.burst_random(N, A=amplitude, ratio=0.1, distribution='normal', n_bursts=3)
|
|
148
|
-
>>> plt.plot(x)
|
|
149
|
-
>>> plt.show()
|
|
150
|
-
"""
|
|
151
|
-
if not isinstance(n_bursts, int) or n_bursts < 1:
|
|
152
|
-
raise ValueError('`n_bursts` must be a positive integer!')
|
|
153
|
-
|
|
154
|
-
bursts = []
|
|
155
|
-
|
|
156
|
-
if not periodic_bursts:
|
|
157
|
-
n = n_bursts
|
|
158
|
-
else:
|
|
159
|
-
n = 1
|
|
160
|
-
|
|
161
|
-
for _ in range(n):
|
|
162
|
-
if distribution == 'uniform':
|
|
163
|
-
br = uniform_random(N, rg=rg) * A
|
|
164
|
-
elif distribution == 'normal':
|
|
165
|
-
br = normal_random(N, rg=rg) * A
|
|
166
|
-
elif distribution == 'pseudorandom':
|
|
167
|
-
br = pseudo_random(N, rg=rg) * A
|
|
168
|
-
else:
|
|
169
|
-
raise ValueError(
|
|
170
|
-
"Set `distribution` either to 'normal', 'uniform' or 'periodic'."
|
|
171
|
-
)
|
|
172
|
-
|
|
173
|
-
if ratio != 1.0:
|
|
174
|
-
N_zero = int(np.floor(N * (1 - ratio)))
|
|
175
|
-
br[-N_zero:] = 0.0
|
|
176
|
-
|
|
177
|
-
bursts.append(br)
|
|
178
|
-
bursts = np.asarray(bursts).flatten()
|
|
179
|
-
|
|
180
|
-
if periodic_bursts:
|
|
181
|
-
if n_bursts > 1:
|
|
182
|
-
bursts = np.tile(bursts, n_bursts)
|
|
183
|
-
|
|
184
|
-
return bursts
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
def sine_sweep(
|
|
188
|
-
time, phi=0, freq_start=1, sweep_rate=None, freq_stop=None,
|
|
189
|
-
mode='linear', phi_end=False, freq_return=False
|
|
190
|
-
):
|
|
191
|
-
"""
|
|
192
|
-
Generate a sine sweep signal time series.
|
|
193
|
-
|
|
194
|
-
:param time: array of shape (N,), time vector.
|
|
195
|
-
:param phi: float, initial phase of the sine signal in radians.
|
|
196
|
-
Defaults to 0.
|
|
197
|
-
:param freq_start: float, initial frequency in Hz.
|
|
198
|
-
:param sweep_rate: float, the rate of sweep. In Hz/s for a linear sweep,
|
|
199
|
-
in octaves/minute for a logarithmic sweep. If not given it is
|
|
200
|
-
calculated from `time`, `freq_start` and `freq_stop`.
|
|
201
|
-
:param freq_stop: float, final frequency in Hz.
|
|
202
|
-
:param mode: 'linear' or 'logarithmic', type of sweep, optional.
|
|
203
|
-
Defaults to 'linear'.
|
|
204
|
-
:param phi_end: If True, return (`sweep_sine`, `phi_end`), where
|
|
205
|
-
`phi_end` is the end phase which can be used as `phi` if this
|
|
206
|
-
function is called for another sweep.
|
|
207
|
-
Defaults to False.
|
|
208
|
-
:param freq_return: If True, return (`sweep_sine`, `phi_end`, `freq`), where
|
|
209
|
-
`freq` is the frequency array.
|
|
210
|
-
Defaults to False.
|
|
211
|
-
:returns: array of shape (N,), the generated sine sweep signal
|
|
212
|
-
|
|
213
|
-
Example
|
|
214
|
-
--------
|
|
215
|
-
>>> import numpy as np
|
|
216
|
-
>>> import matplotlib.pyplot as plt
|
|
217
|
-
>>> import pyExSi as es
|
|
218
|
-
|
|
219
|
-
>>> t = np.linspace(0,10,1000)
|
|
220
|
-
>>> x = es.sine_sweep(time=t, freq_start=0, freq_stop=5)
|
|
221
|
-
>>> plt.plot(t, x)
|
|
222
|
-
>>> plt.show()
|
|
223
|
-
"""
|
|
224
|
-
if sweep_rate is None:
|
|
225
|
-
if not freq_stop is None:
|
|
226
|
-
T = time[-1] - time[0]
|
|
227
|
-
sweep_rate = _sweep_rate(T, freq_start, freq_stop, mode)
|
|
228
|
-
else:
|
|
229
|
-
raise ValueError('`sweep_rate` is not given, please supply `freq_stop`.')
|
|
230
|
-
if phi_end or freq_return:
|
|
231
|
-
# prepare time
|
|
232
|
-
time_ = np.zeros(len(time) + 1)
|
|
233
|
-
time_[: len(time)] = time
|
|
234
|
-
time_[-1] = time[-1] + (time[-1] - time[-2])
|
|
235
|
-
else:
|
|
236
|
-
time_ = time
|
|
237
|
-
|
|
238
|
-
if mode == 'linear':
|
|
239
|
-
phase_t = 2 * np.pi * (sweep_rate * 0.5 * time_ ** 2 + freq_start * time_)
|
|
240
|
-
elif mode == 'logarithmic':
|
|
241
|
-
phase_t = (
|
|
242
|
-
2
|
|
243
|
-
* np.pi
|
|
244
|
-
* 60
|
|
245
|
-
* freq_start
|
|
246
|
-
/ (sweep_rate * np.log(2))
|
|
247
|
-
* (2 ** (sweep_rate * time_ / 60) - 1)
|
|
248
|
-
)
|
|
249
|
-
else:
|
|
250
|
-
raise ValueError(f"Invalid sweep mode `mode`='{mode}'.")
|
|
251
|
-
|
|
252
|
-
if freq_return:
|
|
253
|
-
if mode == 'linear':
|
|
254
|
-
freq = (sweep_rate * 0.5 * time_ * 2 + freq_start)
|
|
255
|
-
elif mode == 'logarithmic':
|
|
256
|
-
freq = (
|
|
257
|
-
60
|
|
258
|
-
* freq_start
|
|
259
|
-
/ (sweep_rate * np.log(2))
|
|
260
|
-
* (2 ** (sweep_rate * time_ / 60) * (sweep_rate / 60) * np.log(2))
|
|
261
|
-
)
|
|
262
|
-
else:
|
|
263
|
-
raise ValueError(f"Invalid sweep mode `mode`='{mode}'.")
|
|
264
|
-
|
|
265
|
-
s = np.sin(phase_t + phi)
|
|
266
|
-
if freq_return:
|
|
267
|
-
return s[:-1], phase_t[-1], freq[:-1]
|
|
268
|
-
elif phi_end:
|
|
269
|
-
return s[:-1], phase_t[-1]
|
|
270
|
-
else:
|
|
271
|
-
return s
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
def _sweep_rate(T, freq_start, freq_stop, mode='linear'):
|
|
275
|
-
"""
|
|
276
|
-
Calculate the sweep rate given the time difference, initial and end
|
|
277
|
-
frequency values and sweep mode. For internal use by `sweep`.
|
|
278
|
-
"""
|
|
279
|
-
if mode == 'linear':
|
|
280
|
-
sweep_rate = (freq_stop - freq_start) / T # Hz/s
|
|
281
|
-
elif mode == 'logarithmic':
|
|
282
|
-
sweep_rate = (60 / T / np.log(2)) * np.log(freq_stop / freq_start) # octaves/min
|
|
283
|
-
else:
|
|
284
|
-
raise ValueError('Invalid sweep mode `{mode}`.')
|
|
285
|
-
return sweep_rate
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
def impulse(N, n_start=0, width=None, amplitude=1.0, window='sine'):
|
|
289
|
-
"""
|
|
290
|
-
Impact impulse of the shape defined with the parameter window.
|
|
291
|
-
|
|
292
|
-
:param N: Number of points in time signal.
|
|
293
|
-
:type N: int
|
|
294
|
-
:param width: Number of points for pulse width, `None` results in width=N
|
|
295
|
-
:type width: int
|
|
296
|
-
:param amplitude: Amplitude of pulse.
|
|
297
|
-
:type amplitude: float
|
|
298
|
-
:param window: The type of window to create. See scipy.signal.windows for more details.
|
|
299
|
-
:type window: string, float, or tuple
|
|
300
|
-
:returns: impact pulse.
|
|
301
|
-
|
|
302
|
-
Example
|
|
303
|
-
--------
|
|
304
|
-
>>> import numpy as np
|
|
305
|
-
>>> import matplotlib.pyplot as plt
|
|
306
|
-
>>> import pyExSi as es
|
|
307
|
-
|
|
308
|
-
>>> N = 1000
|
|
309
|
-
>>> n_start = 100
|
|
310
|
-
>>> width = 200
|
|
311
|
-
>>> amplitude = 3
|
|
312
|
-
>>> x_1 = es.impulse(N=N, n_start=n_start, width=width, amplitude=amplitude, window='triang')
|
|
313
|
-
>>> x_2 = es.impulse(N=N, n_start=n_start, width=width, amplitude=amplitude, window=('exponential',0,10))
|
|
314
|
-
>>> t = np.linspace(0,10,N)
|
|
315
|
-
>>> plt.plot(t,x_1, label='tringular')
|
|
316
|
-
>>> plt.plot(t,x_2, label='exponential')
|
|
317
|
-
>>> plt.legend()
|
|
318
|
-
>>> plt.show()
|
|
319
|
-
"""
|
|
320
|
-
if window == 'sine':
|
|
321
|
-
window = 'cosine'
|
|
322
|
-
if width is None:
|
|
323
|
-
width = N
|
|
324
|
-
if (
|
|
325
|
-
not isinstance(n_start, int)
|
|
326
|
-
or not isinstance(width, int)
|
|
327
|
-
or not isinstance(N, int)
|
|
328
|
-
):
|
|
329
|
-
raise ValueError('`N`, `n_start` and `width` must be integers!')
|
|
330
|
-
|
|
331
|
-
if N < n_start + width:
|
|
332
|
-
raise ValueError('`N` must be bigger than or equal to `n_start` + `length`!')
|
|
333
|
-
|
|
334
|
-
pulse = np.zeros(N - n_start)
|
|
335
|
-
|
|
336
|
-
if window != 'sawtooth':
|
|
337
|
-
window_pulse = signal.windows.get_window(window, width)
|
|
338
|
-
pulse[:width] = amplitude * window_pulse
|
|
339
|
-
else: # until sawtooth is added to scipy.signal.windows module
|
|
340
|
-
pulse[:width] = np.linspace(0, amplitude, width)
|
|
341
|
-
|
|
342
|
-
pulse = np.pad(pulse, (n_start, 0), mode='constant', constant_values=(0, 0))
|
|
343
|
-
|
|
344
|
-
return pulse
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
def get_psd(freq, freq_lower, freq_upper, variance=1):
|
|
348
|
-
"""
|
|
349
|
-
One-sided flat-shaped power spectral density (PSD).
|
|
350
|
-
|
|
351
|
-
:param freq: Frequency vector [Hz]
|
|
352
|
-
:type freq: array
|
|
353
|
-
:param freq_lower: Lower frequency of PSD [Hz]
|
|
354
|
-
:type freq_lower: float
|
|
355
|
-
:param freq_upper: Upper frequency of PSD [Hz]
|
|
356
|
-
:type freq_upper: float
|
|
357
|
-
:param variance: Variance of random process, described by PSD [unit^2]
|
|
358
|
-
:type variance: float
|
|
359
|
-
:returns: one-sided flat-shaped PSD [unit^2/Hz]
|
|
360
|
-
|
|
361
|
-
Example
|
|
362
|
-
--------
|
|
363
|
-
>>> import numpy as np
|
|
364
|
-
>>> import matplotlib.pyplot as plt
|
|
365
|
-
>>> import pyExSi as es
|
|
366
|
-
|
|
367
|
-
>>> N = 1000 # number of data points of time signal
|
|
368
|
-
>>> fs = 100 # sampling frequency [Hz]
|
|
369
|
-
>>> t = np.arange(0,N)/fs # time vector
|
|
370
|
-
>>> M = N // 2 + 1 # number of data points of frequency vector
|
|
371
|
-
>>> freq = np.arange(0, M, 1) * fs / N # frequency vector
|
|
372
|
-
>>> freq_lower = 10 # PSD lower frequency limit [Hz]
|
|
373
|
-
>>> freq_upper = 20 # PSD upper frequency limit [Hz]
|
|
374
|
-
|
|
375
|
-
>>> PSD = es.get_psd(freq, freq_lower, freq_upper) # one-sided flat-shaped PSD
|
|
376
|
-
>>> plt.plot(freq,PSD)
|
|
377
|
-
>>> plt.xlabel(f [Hz])
|
|
378
|
-
>>> plt.ylabel(PSD [unit^2/Hz])
|
|
379
|
-
>>> plt.show()
|
|
380
|
-
"""
|
|
381
|
-
PSD = np.zeros(len(freq))
|
|
382
|
-
indx = np.logical_and(freq >= freq_lower, freq <= freq_upper)
|
|
383
|
-
PSD_width = freq[indx][-1] - freq[indx][0]
|
|
384
|
-
PSD[indx] = variance / PSD_width # area under PSD is variance
|
|
385
|
-
return PSD
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
def random_gaussian(N, PSD, fs, rg=None):
|
|
389
|
-
"""
|
|
390
|
-
Stationary Gaussian realization of random process, characterized by PSD.
|
|
391
|
-
|
|
392
|
-
Random process is obtained with IFFT of amplitude spectra with random phase [1]. Area under PSD curve represents variance of random process.
|
|
393
|
-
|
|
394
|
-
:param N: Number of points.
|
|
395
|
-
:type N: int
|
|
396
|
-
:param PSD: one-sided power spectral density [unit^2].
|
|
397
|
-
:type PSD: array
|
|
398
|
-
:param fs: sampling frequency [Hz].
|
|
399
|
-
:type fs: int,float
|
|
400
|
-
:param rg: Initialized Generator object
|
|
401
|
-
:type rg: numpy.random._generator.Generator
|
|
402
|
-
:returns: stationary Gaussian realization of random process
|
|
403
|
-
|
|
404
|
-
References
|
|
405
|
-
----------
|
|
406
|
-
[1] D. E. Newland. An Introduction to Random Vibrations, Spectral & Wavelet Analysis.
|
|
407
|
-
Dover Publications, 2005
|
|
408
|
-
|
|
409
|
-
Example
|
|
410
|
-
--------
|
|
411
|
-
>>> import numpy as np
|
|
412
|
-
>>> import matplotlib.pyplot as plt
|
|
413
|
-
>>> import pyExSi as es
|
|
414
|
-
|
|
415
|
-
>>> N = 1000 # number of data points of time signal
|
|
416
|
-
>>> fs = 100 # sampling frequency [Hz]
|
|
417
|
-
>>> t = np.arange(0,N)/fs # time vector
|
|
418
|
-
>>> M = N // 2 + 1 # number of data points in frequency vector
|
|
419
|
-
>>> freq = np.arange(0, M, 1) * fs / N # frequency vector
|
|
420
|
-
>>> freq_lower = 10 # PSD lower frequency limit [Hz]
|
|
421
|
-
>>> freq_upper = 20 # PSD upper frequency limit [Hz]
|
|
422
|
-
|
|
423
|
-
>>> PSD = es.get_psd(freq, freq_lower, freq_upper) # one-sided flat-shaped PSD
|
|
424
|
-
>>> x = es.random_gaussian(N, PSD, fs)
|
|
425
|
-
>>> plt.plot(t,x)
|
|
426
|
-
>>> plt.xlabel(t [s])
|
|
427
|
-
>>> plt.ylabel(x [unit])
|
|
428
|
-
>>> plt.show()
|
|
429
|
-
"""
|
|
430
|
-
ampl_spectra = np.sqrt(PSD * N * fs / 2) # amplitude spectra
|
|
431
|
-
|
|
432
|
-
if rg == None:
|
|
433
|
-
rg = np.random.default_rng()
|
|
434
|
-
if isinstance(rg, np.random._generator.Generator):
|
|
435
|
-
ampl_spectra_random = ampl_spectra * np.exp(
|
|
436
|
-
1j * rg.uniform(0, 1, len(PSD)) * 2 * np.pi
|
|
437
|
-
) # amplitude spectra, random phase
|
|
438
|
-
else:
|
|
439
|
-
raise ValueError(
|
|
440
|
-
'`rg` must be initialized Generator object (numpy.random._generator.Generator)!'
|
|
441
|
-
)
|
|
442
|
-
|
|
443
|
-
burst = np.fft.irfft(ampl_spectra_random, n=N) # time signal
|
|
444
|
-
return burst
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
def stationary_nongaussian_signal(N, PSD, fs, s_k=0, k_u=3, mean=0, rg=None):
|
|
448
|
-
"""
|
|
449
|
-
Stationary non-Gaussian realization of random process.
|
|
450
|
-
|
|
451
|
-
Random process is obtained with IFFT of amplitude spectra with random phase [1]. Non-Gaussianity is obtained by Winterstein polynomials [2].
|
|
452
|
-
|
|
453
|
-
:param N: number of data points in returned signal
|
|
454
|
-
:type N: int
|
|
455
|
-
:param PSD: one-sided power spectral density
|
|
456
|
-
:type PSD: array
|
|
457
|
-
:param fs: sampling frequency
|
|
458
|
-
:type fs: int, float
|
|
459
|
-
:param s_k: skewness of returned signal
|
|
460
|
-
:type s_k: int, float
|
|
461
|
-
:param k_u: kurtossis of returned signal
|
|
462
|
-
:type k_u: int, float
|
|
463
|
-
:param mean: mean value of returned signal
|
|
464
|
-
:type mean: int, float
|
|
465
|
-
:param rg: Initialized Generator object
|
|
466
|
-
:type rg: numpy.random._generator.Generator
|
|
467
|
-
:returns: stationary non-Gaussian realization of random process.
|
|
468
|
-
|
|
469
|
-
References
|
|
470
|
-
----------
|
|
471
|
-
[1] D. E. Newland. An Introduction to Random Vibrations, Spectral & Wavelet
|
|
472
|
-
Analysis. Dover Publications, 2005
|
|
473
|
-
|
|
474
|
-
[2] Steven R. Winterstein. Nonlinear vibration models for extremes and
|
|
475
|
-
fatigue. ASCE Journal of Engineering Mechanics, 114:1772–1790, 1988.
|
|
476
|
-
|
|
477
|
-
Example
|
|
478
|
-
--------
|
|
479
|
-
>>> import numpy as np
|
|
480
|
-
>>> import matplotlib.pyplot as plt
|
|
481
|
-
>>> import pyExSi as es
|
|
482
|
-
|
|
483
|
-
>>> N = 1000 # number of data points of time signal
|
|
484
|
-
>>> fs = 100 # sampling frequency [Hz]
|
|
485
|
-
>>> t = np.arange(0,N)/fs # time vector
|
|
486
|
-
>>> M = N // 2 + 1 # number of data points of frequency vector
|
|
487
|
-
>>> freq = np.arange(0, M, 1) * fs / N # frequency vector
|
|
488
|
-
>>> freq_lower = 10 # PSD lower frequency limit [Hz]
|
|
489
|
-
>>> freq_upper = 20 # PSD upper frequency limit [Hz]
|
|
490
|
-
|
|
491
|
-
>>> PSD = es.get_psd(freq, freq_lower, freq_upper) # one-sided flat-shaped PSD
|
|
492
|
-
>>> x_gauss = es.random_gaussian(N, PSD, fs)
|
|
493
|
-
>>> x_ngauss = es.stationary_nongaussian_signal(N, PSD, fs, k_u = 5)
|
|
494
|
-
>>> plt.plot(t, x_gauss, label='gaussian')
|
|
495
|
-
>>> plt.plot(t, x_ngauss, label='non-gaussian')
|
|
496
|
-
>>> plt.xlabel(t [s])
|
|
497
|
-
>>> plt.ylabel(x [unit])
|
|
498
|
-
>>> plt.legend()
|
|
499
|
-
>>> plt.show()
|
|
500
|
-
"""
|
|
501
|
-
x = random_gaussian(N, PSD, fs, rg=rg) # gaussian random process
|
|
502
|
-
|
|
503
|
-
h_4 = (np.sqrt(1 + 1.5 * (k_u - 3)) - 1) / 18 # parameter h4 [2]
|
|
504
|
-
h_3 = s_k / (6 * (1 + 6 * h_4)) ##parameter h3 [2]
|
|
505
|
-
Κ = 1 / np.sqrt(1 + 2 * h_3 ** 2 + 6 * h_4 ** 2) # parameter K [2]
|
|
506
|
-
sigma_x = np.std(x) # standard deviation of gaussian process
|
|
507
|
-
nongaussian_signal = mean + Κ * (
|
|
508
|
-
x / sigma_x
|
|
509
|
-
+ h_3 * (x / sigma_x - 1)
|
|
510
|
-
+ h_4 * ((x / sigma_x) ** 3 - 3 * x / sigma_x)
|
|
511
|
-
) # [2]
|
|
512
|
-
|
|
513
|
-
return nongaussian_signal
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
def _get_nonstationary_signal_psd(N, PSD, fs, PSD_modulating, p=1, delta_m=1, rg=None):
|
|
517
|
-
"""
|
|
518
|
-
Non-stationary non-Gaussian realization of random process.
|
|
519
|
-
|
|
520
|
-
Non-stationarity random process is obtained by amplitude modulation of Gaussian random process[1].
|
|
521
|
-
Gaussian random process is obtained with IFFT of amplitude spectra with random phase [2].
|
|
522
|
-
Modulating signal is generated on PSD basis [3]. For internal use by `nonstationary_signal`.
|
|
523
|
-
|
|
524
|
-
:param N: number of data points in returned signal
|
|
525
|
-
:type N: int, float
|
|
526
|
-
:param PSD: one-sided power spectral density of carrier signal
|
|
527
|
-
:type PSD: array
|
|
528
|
-
:param fs: sampling frequency
|
|
529
|
-
:type fs: int, float
|
|
530
|
-
:param PSD_modulating: one-sided power spectral density of modulating signal
|
|
531
|
-
:type PSD_modulating: array
|
|
532
|
-
:param p: exponent
|
|
533
|
-
:type p: int, float
|
|
534
|
-
:param delta_m: offset
|
|
535
|
-
:type delta_m: int, float
|
|
536
|
-
:param rg: Initialized Generator object
|
|
537
|
-
:type rg: numpy.random._generator.Generator
|
|
538
|
-
:returns: nonstationary, stationary and modulating_signal
|
|
539
|
-
|
|
540
|
-
References
|
|
541
|
-
----------
|
|
542
|
-
[1] Frederic Kihm, Stephen A. Rizzi, N. S. Ferguson, and Andrew Halfpenny.
|
|
543
|
-
Understanding how kurtosis is transferred from input acceleration to stress
|
|
544
|
-
response and it’s influence on fatigue life. In Proceedings of the XI
|
|
545
|
-
International Conference on Recent Advances in Structural Dynamics, Pisa,
|
|
546
|
-
Italy, 07 2013.
|
|
547
|
-
|
|
548
|
-
[2] D. E. Newland. An Introduction to Random Vibrations, Spectral & Wavelet
|
|
549
|
-
Analysis. Dover Publications, 2005
|
|
550
|
-
|
|
551
|
-
[3] Arvid Trapp, Mafake James Makua, and Peter Wolfsteiner. Fatigue
|
|
552
|
-
assessment of amplitude-modulated nonstationary random vibration loading.
|
|
553
|
-
Procedia Structural Integrity, 17:379—-386, 2019.
|
|
554
|
-
|
|
555
|
-
"""
|
|
556
|
-
stationary_signal = random_gaussian(
|
|
557
|
-
N, PSD, fs, rg=rg
|
|
558
|
-
) # gaussian random process, carrier
|
|
559
|
-
modulating_signal = random_gaussian(
|
|
560
|
-
N, PSD_modulating, fs, rg=rg
|
|
561
|
-
) # gaussian random process, modulating signal
|
|
562
|
-
|
|
563
|
-
nonstationary_signal = stationary_signal * (
|
|
564
|
-
np.abs(modulating_signal) ** p + delta_m
|
|
565
|
-
) # [3]
|
|
566
|
-
nonstationary_signal = nonstationary_signal / np.std(
|
|
567
|
-
nonstationary_signal
|
|
568
|
-
) # non-stationary signal
|
|
569
|
-
|
|
570
|
-
return nonstationary_signal, stationary_signal, modulating_signal
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
def _get_nonstationary_signal_beta(N, PSD, fs, delta_n, alpha=1, beta=1, rg=None):
|
|
574
|
-
"""
|
|
575
|
-
Non-stationary non-Gaussian realization of random process.
|
|
576
|
-
|
|
577
|
-
Non-stationarity random process is obtained by amplitude modulation of Gaussian random process[1].
|
|
578
|
-
Gaussian random process is obtained with IFFT of amplitude spectra with random phase [2]. Modulating
|
|
579
|
-
signal is generated by cubic spline interpolation of points, based on beta distribution, defined by
|
|
580
|
-
parameters alpha and beta. For internal use by `nonstationary_signal`.
|
|
581
|
-
|
|
582
|
-
:param N: Number of data points in returned signal
|
|
583
|
-
:type N: int, float
|
|
584
|
-
:param PSD: One-sided power spectral density of carrier signal
|
|
585
|
-
:type PSD: array
|
|
586
|
-
:param fs: sampling frequency
|
|
587
|
-
:type fs: int, float
|
|
588
|
-
:param delta_n: Distance beetwen consecutive beta distributed points. Smaller delta_n corresponds to hihger modulation frequency.
|
|
589
|
-
:type delta_n: int
|
|
590
|
-
:param alpha: Parameter of beta distribution
|
|
591
|
-
:type alpha: float
|
|
592
|
-
:param beta: Parameter of beta distribution
|
|
593
|
-
:type beta: float
|
|
594
|
-
:param rg: Initialized Generator object
|
|
595
|
-
:type rg: numpy.random._generator.Generator
|
|
596
|
-
:returns: nonstationary, stationary and modulating_signal
|
|
597
|
-
|
|
598
|
-
References
|
|
599
|
-
----------
|
|
600
|
-
[1] Frederic Kihm, Stephen A. Rizzi, N. S. Ferguson, and Andrew Halfpenny.
|
|
601
|
-
Understanding how kurtosis is transferred from input acceleration to
|
|
602
|
-
stress response and it’s influence on fatigue life. In Proceedings of the
|
|
603
|
-
XI International Conference on Recent Advances in Structural Dynamics, Pisa,
|
|
604
|
-
Italy, 07 2013.
|
|
605
|
-
|
|
606
|
-
[2] D. E. Newland. An Introduction to Random Vibrations, Spectral & Wavelet
|
|
607
|
-
Analysis. Dover Publications, 2005
|
|
608
|
-
"""
|
|
609
|
-
stationary_signal = random_gaussian(N, PSD, fs, rg=rg) # gaussian random process
|
|
610
|
-
|
|
611
|
-
t = np.arange(0, N) / fs # time vector
|
|
612
|
-
n = N // delta_n # number of time intervals for beta distribution points
|
|
613
|
-
t_beta = np.copy(
|
|
614
|
-
t[: n * delta_n + 1 : delta_n]
|
|
615
|
-
) # time vector for modulating signal, with step delta_n
|
|
616
|
-
if N % delta_n == 0:
|
|
617
|
-
t_beta = np.append(t_beta, t[-1])
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
if rg == None:
|
|
621
|
-
rg = np.random.default_rng()
|
|
622
|
-
if isinstance(rg, np.random._generator.Generator):
|
|
623
|
-
points_beta = rg.beta(alpha, beta, n + 1)
|
|
624
|
-
points_beta[-1] = points_beta[0] # first and last points are the same
|
|
625
|
-
else:
|
|
626
|
-
raise ValueError(
|
|
627
|
-
"rg' must be initialized Generator object (numpy.random._generator.Generator)!"
|
|
628
|
-
)
|
|
629
|
-
|
|
630
|
-
points_beta[-1] = points_beta[0] # first and last points are the same
|
|
631
|
-
function_beta = CubicSpline(
|
|
632
|
-
t_beta, points_beta, bc_type='periodic', extrapolate=None
|
|
633
|
-
)
|
|
634
|
-
modulating_signal = function_beta(t) / np.std(
|
|
635
|
-
function_beta(t)
|
|
636
|
-
) # unit variance modulating signal
|
|
637
|
-
|
|
638
|
-
# shift to non-negative values
|
|
639
|
-
if np.min(modulating_signal) < 0:
|
|
640
|
-
modulating_signal += np.abs(np.min(modulating_signal))
|
|
641
|
-
|
|
642
|
-
nonstationary_signal = (
|
|
643
|
-
stationary_signal * modulating_signal[: len(stationary_signal)]
|
|
644
|
-
) # non-stationary signal
|
|
645
|
-
nonstationary_signal /= np.std(nonstationary_signal) # unit variance
|
|
646
|
-
|
|
647
|
-
return nonstationary_signal, stationary_signal, modulating_signal
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
def nonstationary_signal(
|
|
651
|
-
N,
|
|
652
|
-
PSD,
|
|
653
|
-
fs,
|
|
654
|
-
k_u=3,
|
|
655
|
-
modulating_signal=('PSD', None),
|
|
656
|
-
param1_list=None,
|
|
657
|
-
param2_list=None,
|
|
658
|
-
seed=None,
|
|
659
|
-
SQ=False,
|
|
660
|
-
):
|
|
661
|
-
"""
|
|
662
|
-
Non-stationary non-Gaussian realization of random process.
|
|
663
|
-
|
|
664
|
-
Non-stationarity random process is obtained by amplitude modulation of
|
|
665
|
-
Gaussian random process[1]. Gaussian random process is obtained with IFFT
|
|
666
|
-
of amplitude spectra with random phase [2]. Tuple modulating_signal selects
|
|
667
|
-
the type of modulating signal: 'PSD' for random process realization [3],
|
|
668
|
-
where PSD_modulating is power spectrum density of modulating signal, and
|
|
669
|
-
'CSI' for cubic spline interpolation [4,5], with sample step delta_n.
|
|
670
|
-
The desired kurtosis k_u is obtained by iteration over lists param1_list
|
|
671
|
-
and param2_list (for 'PSD' p and delta_m are needed, for 'CSI' alpha and
|
|
672
|
-
beta are needed).
|
|
673
|
-
|
|
674
|
-
:param N: Number of data points in returned signal
|
|
675
|
-
:type N: {int, float}
|
|
676
|
-
:param PSD: One-sided power spectral density of carrier signal
|
|
677
|
-
:type PSD: array
|
|
678
|
-
:param fs: sampling frequency
|
|
679
|
-
:type fs: {int, float}
|
|
680
|
-
:param k_u: Desired kurtosis value of returned signal. Defaults to 3 (Gaussian random process).
|
|
681
|
-
:type k_u: float
|
|
682
|
-
:param modulating_signal: Delects type of modulating signal and provides needed parameter.
|
|
683
|
-
:type modulating_signal: tuple with name and parameter.
|
|
684
|
-
:param param1_list: List of first parameter for modulating signal generation. Contains parameters p or alpha
|
|
685
|
-
:type param1_list: list of floats
|
|
686
|
-
:param param2_list: List of second parameter for modulating signal generation. Contains parameters delta_m or beta
|
|
687
|
-
:type param2_list: list of floats
|
|
688
|
-
:param seed: A seed to initialize the BitGenerator. For details, see numpy.random.default_rng()
|
|
689
|
-
:type seed: {None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional
|
|
690
|
-
:param SQ: If squeezing of signal [4] is required, set 'True'. Defaults to 'False'
|
|
691
|
-
:type SQ: boolean
|
|
692
|
-
:returns: nonstationary signal. Optionally, stationary and modulating_signal are returned as well.
|
|
693
|
-
|
|
694
|
-
References
|
|
695
|
-
----------
|
|
696
|
-
[1] Frederic Kihm, Stephen A. Rizzi, N. S. Ferguson, and Andrew Halfpenny.
|
|
697
|
-
Understanding how kurtosis is transferred from input acceleration to stress
|
|
698
|
-
response and it’s influence on fatigue life. In Proceedings of the XI
|
|
699
|
-
International Conference on Recent Advances in Structural Dynamics, Pisa,
|
|
700
|
-
Italy, 07 2013.
|
|
701
|
-
|
|
702
|
-
[2] D. E. Newland. An Introduction to Random Vibrations, Spectral & Wavelet
|
|
703
|
-
Analysis. Dover Publications, 2005
|
|
704
|
-
|
|
705
|
-
[3] Arvid Trapp, Mafake James Makua, and Peter Wolfsteiner. Fatigue
|
|
706
|
-
assessment of amplitude-modulated nonstationary random vibration loading.
|
|
707
|
-
Procedia Structural Integrity, 17:379—-386, 2019.
|
|
708
|
-
|
|
709
|
-
[4] Lorenzo Capponi, Martin Česnik, Janko Slavič, Filippo Cianetti, and
|
|
710
|
-
Miha Boltežar. Non-stationarity index in vibration fatigue: Theoretical
|
|
711
|
-
and ex-perimental research.International Journal of Fatigue, 104:221–230,
|
|
712
|
-
2017.
|
|
713
|
-
|
|
714
|
-
[5] Janko Slavič, Matjaž Mršnik, Martin Česnik, Jaka Javh, Miha Boltežar.
|
|
715
|
-
Vibration Fatigue by Spectral Methods, From Structural Dynamics to Fatigue Damage
|
|
716
|
-
– Theory and Experiments, ISBN: 9780128221907, Elsevier, 1st September 2020
|
|
717
|
-
|
|
718
|
-
Example
|
|
719
|
-
--------
|
|
720
|
-
>>> import numpy as np
|
|
721
|
-
>>> import matplotlib.pyplot as plt
|
|
722
|
-
>>> import pyExSi as es
|
|
723
|
-
|
|
724
|
-
>>> N = 1000 # number of data points of time signal
|
|
725
|
-
>>> fs = 100 # sampling frequency [Hz]
|
|
726
|
-
>>> t = np.arange(0,N)/fs # time vector
|
|
727
|
-
>>> M = N // 2 + 1 # number of data points of frequency vector
|
|
728
|
-
>>> freq = np.arange(0, M, 1) * fs / N # frequency vector
|
|
729
|
-
>>> freq_lower = 10 # PSD lower frequency limit [Hz]
|
|
730
|
-
>>> freq_upper = 20 # PSD upper frequency limit [Hz]
|
|
731
|
-
>>> freq_lower_mod = 1 # modulating signals's PSD lower frequency limit [Hz]
|
|
732
|
-
>>> freq_upper_mod = 2 # modulating signals's PSD upper frequency limit [Hz]
|
|
733
|
-
|
|
734
|
-
PSD of stationary and modulating signal
|
|
735
|
-
|
|
736
|
-
>>> PSD = es.get_psd(freq, freq_lower, freq_upper) # one-sided flat-shaped PSD
|
|
737
|
-
>>> PSD_modulating = es.get_psd(freq, freq_lower_mod, freq_upper_mod) # one-sided flat-shaped PSD
|
|
738
|
-
|
|
739
|
-
Specify kurtosis and return non-stationary signal
|
|
740
|
-
|
|
741
|
-
>>> k_u = 5
|
|
742
|
-
>>> x_nonstationary_1 = es.nonstationary_signal(N,PSD,fs,k_u=k_u,modulating_signal=('PSD',PSD_modulating))
|
|
743
|
-
|
|
744
|
-
Calculate kurtosis
|
|
745
|
-
|
|
746
|
-
>>> k_u_1 = es.get_kurtosis(x_nonstationary_1)
|
|
747
|
-
>>> print(f'desired kurtosis :{k_u:.3f}', actual kurtosis :{k_u_1:.3f}')
|
|
748
|
-
|
|
749
|
-
Refined array with amplitude modulation parameters
|
|
750
|
-
|
|
751
|
-
>>> delta_m_list = np.arange(.1,2.1,.1)
|
|
752
|
-
>>> p_list = np.arange(.1,2.1,.1)
|
|
753
|
-
>>> x_nonstationary_2 = es.nonstationary_signal(N,PSD,fs,k_u=k_u,modulating_signal=('PSD',PSD_modulating),
|
|
754
|
-
param1_list=delta_m_list,param2_list=p_list)
|
|
755
|
-
>>> k_u_2 = es.get_kurtosis(x_nonstationary_2)
|
|
756
|
-
>>> print(f'desired kurtosis :{k_u:.3f}', actual kurtosis :{k_u_2:.3f}')
|
|
757
|
-
|
|
758
|
-
Define array of parameters alpha and beta
|
|
759
|
-
|
|
760
|
-
>>> alpha_list = np.arange(1,4,.5)
|
|
761
|
-
>>> beta_list = np.arange(1,4,.5)
|
|
762
|
-
>>> x_nonstationary_3 = es.nonstationary_signal(N,PSD,fs,k_u=10,modulating_signal=('CSI',delta_n),
|
|
763
|
-
param1_list=alpha_list,param2_list=beta_list)
|
|
764
|
-
>>> k_u_3 = es.get_kurtosis(x_nonstationary_3)
|
|
765
|
-
>>> print(f'desired kurtosis :{k_u:.3f}', actual kurtosis :{k_u_3:.3f}')
|
|
766
|
-
|
|
767
|
-
>>> plt.plot(t, x_nonstationary_2, label='PSD')
|
|
768
|
-
>>> plt.plot(t, x_nonstationary_3, label='CSI)
|
|
769
|
-
>>> plt.xlabel(t [s])
|
|
770
|
-
>>> plt.ylabel(x [unit])
|
|
771
|
-
>>> plt.legend()
|
|
772
|
-
>>> plt.show()
|
|
773
|
-
"""
|
|
774
|
-
# read type and parameter of modulating signal
|
|
775
|
-
mod_signal_type, mod_sig_parameter = modulating_signal
|
|
776
|
-
|
|
777
|
-
# default param1/2 list, if not provided as function argument
|
|
778
|
-
if param1_list is None:
|
|
779
|
-
if mod_signal_type == 'PSD':
|
|
780
|
-
param1_list = np.arange(0.1, 2, 0.1) # p
|
|
781
|
-
else: #'CSI'
|
|
782
|
-
param1_list = np.arange(1, 10, 0.5) # alpha
|
|
783
|
-
|
|
784
|
-
if param2_list is None:
|
|
785
|
-
if mod_signal_type == 'PSD':
|
|
786
|
-
param2_list = np.arange(0, 1, 0.1) # delta_m
|
|
787
|
-
else: #'CSI'
|
|
788
|
-
param2_list = np.arange(1, 10, 0.5) # beta
|
|
789
|
-
|
|
790
|
-
nonstationary_signals_tmp = {} # temporary signals dict
|
|
791
|
-
delta_k_u_dict = {} # for difference of actual and targeted kurtosis
|
|
792
|
-
|
|
793
|
-
if SQ: # only if squeizzing is required
|
|
794
|
-
stationary_signals_tmp = {} # temporary stationary signals dict
|
|
795
|
-
modulation_signals_tmp = {} # temporary modulating signals dict
|
|
796
|
-
|
|
797
|
-
for param1 in param1_list: # p/alpha
|
|
798
|
-
for param2 in param2_list: # delta_m/beta
|
|
799
|
-
if seed == None:
|
|
800
|
-
rg = None
|
|
801
|
-
elif isinstance(seed, int):
|
|
802
|
-
rg = np.random.default_rng(seed)
|
|
803
|
-
else:
|
|
804
|
-
raise ValueError(
|
|
805
|
-
'`seed` must be of type {None, int, array_like[ints], SeedSequence, BitGenerator, Generator}!'
|
|
806
|
-
)
|
|
807
|
-
|
|
808
|
-
if mod_signal_type == 'PSD':
|
|
809
|
-
am_sig_tmp, sig_tmp, mod_tmp = _get_nonstationary_signal_psd(
|
|
810
|
-
N, PSD, fs, mod_sig_parameter, p=param1, delta_m=param2, rg=rg
|
|
811
|
-
)
|
|
812
|
-
elif mod_signal_type == 'CSI':
|
|
813
|
-
am_sig_tmp, sig_tmp, mod_tmp = _get_nonstationary_signal_beta(
|
|
814
|
-
N, PSD, fs, mod_sig_parameter, alpha=param1, beta=param2, rg=rg
|
|
815
|
-
)
|
|
816
|
-
else:
|
|
817
|
-
raise ValueError(
|
|
818
|
-
'Valid options for `mod_signal_type` are `PSD` and `CSI` '
|
|
819
|
-
)
|
|
820
|
-
|
|
821
|
-
nonstationary_signals_tmp[f'param1={param1}, param2={param2}'] = am_sig_tmp
|
|
822
|
-
k_u_tmp = moment(am_sig_tmp, 4) / (moment(am_sig_tmp, 2) ** 2)
|
|
823
|
-
delta_k_u_dict[f'param1={param1}, param2={param2}'] = np.abs(k_u - k_u_tmp)
|
|
824
|
-
|
|
825
|
-
if SQ:
|
|
826
|
-
stationary_signals_tmp[f'param1={param1}, param2={param2}'] = sig_tmp
|
|
827
|
-
modulation_signals_tmp[f'param1={param1}, param2={param2}'] = mod_tmp
|
|
828
|
-
|
|
829
|
-
min_key = min(delta_k_u_dict, key=delta_k_u_dict.get)
|
|
830
|
-
|
|
831
|
-
if not SQ:
|
|
832
|
-
return nonstationary_signals_tmp[min_key]
|
|
833
|
-
else:
|
|
834
|
-
return stationary_signals_tmp[min_key], modulation_signals_tmp[min_key]
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
def get_kurtosis(signal):
|
|
838
|
-
"""
|
|
839
|
-
Kurtosis of signal.
|
|
840
|
-
|
|
841
|
-
:param signal: input signal.
|
|
842
|
-
:type signal: array
|
|
843
|
-
:returns: kurtosis
|
|
844
|
-
"""
|
|
845
|
-
μ_2 = moment(signal, 2)
|
|
846
|
-
μ_4 = moment(signal, 4)
|
|
847
|
-
k_u = μ_4 / μ_2 ** 2
|
|
848
|
-
return k_u
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
if __name__ == "__main__":
|
|
852
|
-
time = np.arange(1000)/10000
|
|
853
|
-
burst = sine_sweep(time=time, freq_start=3000, freq_stop=15000, mode='logarithmic')
|
|
854
|
-
print(burst)
|
pyexsi-0.43.3/requirements.txt
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|