modusa 0.2.23__py3-none-any.whl → 0.3__py3-none-any.whl
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.
- modusa/.DS_Store +0 -0
- modusa/__init__.py +8 -1
- modusa/devtools/{generate_doc_source.py → generate_docs_source.py} +5 -5
- modusa/devtools/generate_template.py +5 -5
- modusa/devtools/main.py +3 -3
- modusa/devtools/templates/generator.py +1 -1
- modusa/devtools/templates/io.py +1 -1
- modusa/devtools/templates/{signal.py → model.py} +18 -11
- modusa/devtools/templates/plugin.py +1 -1
- modusa/generators/__init__.py +11 -1
- modusa/generators/audio.py +188 -0
- modusa/generators/audio_waveforms.py +1 -1
- modusa/generators/base.py +1 -1
- modusa/generators/ftds.py +298 -0
- modusa/generators/s1d.py +270 -0
- modusa/generators/s2d.py +300 -0
- modusa/generators/s_ax.py +102 -0
- modusa/generators/t_ax.py +64 -0
- modusa/generators/tds.py +267 -0
- modusa/models/__init__.py +14 -0
- modusa/models/__pycache__/signal1D.cpython-312.pyc.4443461152 +0 -0
- modusa/models/audio.py +90 -0
- modusa/models/base.py +70 -0
- modusa/models/data.py +457 -0
- modusa/models/ftds.py +584 -0
- modusa/models/s1d.py +578 -0
- modusa/models/s2d.py +619 -0
- modusa/models/s_ax.py +448 -0
- modusa/models/t_ax.py +335 -0
- modusa/models/tds.py +465 -0
- modusa/plugins/__init__.py +3 -1
- modusa/tmp.py +98 -0
- modusa/tools/__init__.py +5 -0
- modusa/tools/audio_converter.py +56 -67
- modusa/tools/audio_loader.py +90 -0
- modusa/tools/audio_player.py +42 -67
- modusa/tools/math_ops.py +104 -1
- modusa/tools/plotter.py +305 -497
- modusa/tools/youtube_downloader.py +31 -98
- modusa/utils/excp.py +6 -0
- modusa/utils/np_func_cat.py +44 -0
- modusa/utils/plot.py +142 -0
- {modusa-0.2.23.dist-info → modusa-0.3.dist-info}/METADATA +5 -16
- modusa-0.3.dist-info/RECORD +60 -0
- modusa/devtools/docs/source/generators/audio_waveforms.rst +0 -8
- modusa/devtools/docs/source/generators/base.rst +0 -8
- modusa/devtools/docs/source/generators/index.rst +0 -8
- modusa/devtools/docs/source/io/audio_loader.rst +0 -8
- modusa/devtools/docs/source/io/base.rst +0 -8
- modusa/devtools/docs/source/io/index.rst +0 -8
- modusa/devtools/docs/source/plugins/base.rst +0 -8
- modusa/devtools/docs/source/plugins/index.rst +0 -7
- modusa/devtools/docs/source/signals/audio_signal.rst +0 -8
- modusa/devtools/docs/source/signals/base.rst +0 -8
- modusa/devtools/docs/source/signals/frequency_domain_signal.rst +0 -8
- modusa/devtools/docs/source/signals/index.rst +0 -11
- modusa/devtools/docs/source/signals/spectrogram.rst +0 -8
- modusa/devtools/docs/source/signals/time_domain_signal.rst +0 -8
- modusa/devtools/docs/source/tools/audio_converter.rst +0 -8
- modusa/devtools/docs/source/tools/audio_player.rst +0 -8
- modusa/devtools/docs/source/tools/base.rst +0 -8
- modusa/devtools/docs/source/tools/fourier_tranform.rst +0 -8
- modusa/devtools/docs/source/tools/index.rst +0 -13
- modusa/devtools/docs/source/tools/math_ops.rst +0 -8
- modusa/devtools/docs/source/tools/plotter.rst +0 -8
- modusa/devtools/docs/source/tools/youtube_downloader.rst +0 -8
- modusa/io/__init__.py +0 -5
- modusa/io/audio_loader.py +0 -184
- modusa/io/base.py +0 -43
- modusa/signals/__init__.py +0 -3
- modusa/signals/audio_signal.py +0 -540
- modusa/signals/base.py +0 -27
- modusa/signals/frequency_domain_signal.py +0 -376
- modusa/signals/spectrogram.py +0 -564
- modusa/signals/time_domain_signal.py +0 -412
- modusa/tools/fourier_tranform.py +0 -24
- modusa-0.2.23.dist-info/RECORD +0 -70
- {modusa-0.2.23.dist-info → modusa-0.3.dist-info}/WHEEL +0 -0
- {modusa-0.2.23.dist-info → modusa-0.3.dist-info}/entry_points.txt +0 -0
- {modusa-0.2.23.dist-info → modusa-0.3.dist-info}/licenses/LICENSE.md +0 -0
modusa/.DS_Store
CHANGED
|
Binary file
|
modusa/__init__.py
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
from modusa.utils import excp, config
|
|
1
|
+
from modusa.utils import excp, config
|
|
2
|
+
|
|
3
|
+
#=====Giving access to plot functions to plot multiple signals.=====
|
|
4
|
+
from modusa.tools import plot1d, plot2d
|
|
5
|
+
from modusa.tools import play, convert
|
|
6
|
+
from modusa.tools import download
|
|
7
|
+
from modusa.tools import load
|
|
8
|
+
#=====
|
|
@@ -9,17 +9,17 @@ from collections import defaultdict
|
|
|
9
9
|
# === Configuration ===
|
|
10
10
|
BASE_MODULES = [
|
|
11
11
|
'modusa.tools',
|
|
12
|
-
'modusa.
|
|
12
|
+
'modusa.models',
|
|
13
13
|
'modusa.generators',
|
|
14
14
|
'modusa.plugins',
|
|
15
|
-
|
|
15
|
+
# 'modusa.io'
|
|
16
16
|
]
|
|
17
17
|
OUTPUT_DIRS = [
|
|
18
18
|
Path('docs/source/tools'),
|
|
19
|
-
Path('docs/source/
|
|
19
|
+
Path('docs/source/models'),
|
|
20
20
|
Path('docs/source/generators'),
|
|
21
21
|
Path('docs/source/plugins'),
|
|
22
|
-
|
|
22
|
+
# Path('docs/source/io')
|
|
23
23
|
]
|
|
24
24
|
|
|
25
25
|
# Ensure output directories exist
|
|
@@ -81,7 +81,7 @@ def write_index_rst_file(tools_by_module, output_dir, section_name="Tools"):
|
|
|
81
81
|
f.write(f" {name}\n")
|
|
82
82
|
|
|
83
83
|
# === Main Script ===
|
|
84
|
-
def
|
|
84
|
+
def generate_docs_source():
|
|
85
85
|
for base_module, output_dir in zip(BASE_MODULES, OUTPUT_DIRS):
|
|
86
86
|
module_class_map = get_classes_grouped_by_module(base_module)
|
|
87
87
|
|
|
@@ -28,11 +28,11 @@ GENERATOR_INFO = {
|
|
|
28
28
|
"template_dump_dp": SRC_CODE_DIR / "generators",
|
|
29
29
|
"test_template_dump_dp": TESTS_DIR / "test_generators"
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
"template_fp": TEMPLATES_DIR / "
|
|
31
|
+
MODEL_INFO = {
|
|
32
|
+
"template_fp": TEMPLATES_DIR / "model.py",
|
|
33
33
|
"test_template_fp": TEMPLATES_DIR / "test.py",
|
|
34
|
-
"template_dump_dp": SRC_CODE_DIR / "
|
|
35
|
-
"test_template_dump_dp": TESTS_DIR / "
|
|
34
|
+
"template_dump_dp": SRC_CODE_DIR / "models",
|
|
35
|
+
"test_template_dump_dp": TESTS_DIR / "test_models"
|
|
36
36
|
}
|
|
37
37
|
TOOL_INFO = {
|
|
38
38
|
"template_fp": TEMPLATES_DIR / "tool.py",
|
|
@@ -53,7 +53,7 @@ class TemplateGenerator():
|
|
|
53
53
|
def get_path_info(for_what: str):
|
|
54
54
|
if for_what == "plugin": return PLUGIN_INFO
|
|
55
55
|
if for_what == "io": return IO_INFO
|
|
56
|
-
if for_what == "
|
|
56
|
+
if for_what == "model": return MODEL_INFO
|
|
57
57
|
if for_what == "tool": return TOOL_INFO
|
|
58
58
|
if for_what == "generator": return GENERATOR_INFO
|
|
59
59
|
|
modusa/devtools/main.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
from .generate_template import TemplateGenerator
|
|
5
|
-
from .
|
|
5
|
+
from .generate_docs_source import generate_docs_source
|
|
6
6
|
from .list_plugins import list_plugins
|
|
7
7
|
from . import list_authors
|
|
8
8
|
|
|
@@ -23,10 +23,10 @@ def main():
|
|
|
23
23
|
|
|
24
24
|
create_subparsers.add_parser("tool", help="Create a new tool class").set_defaults(func=lambda:TemplateGenerator.create_template("tool"))
|
|
25
25
|
create_subparsers.add_parser("plugin", help="Create a new plugin class").set_defaults(func=lambda:TemplateGenerator.create_template("plugin"))
|
|
26
|
-
create_subparsers.add_parser("
|
|
26
|
+
create_subparsers.add_parser("model", help="Create a new model class").set_defaults(func=lambda:TemplateGenerator.create_template("model"))
|
|
27
27
|
create_subparsers.add_parser("generator", help="Create a new signal generator class").set_defaults(func=lambda:TemplateGenerator.create_template("generator"))
|
|
28
28
|
create_subparsers.add_parser("io", help="Create a new IO class").set_defaults(func=lambda:TemplateGenerator.create_template("io"))
|
|
29
|
-
create_subparsers.add_parser("
|
|
29
|
+
create_subparsers.add_parser("docs", help="Generate the docs").set_defaults(func=lambda:generate_docs_source())
|
|
30
30
|
|
|
31
31
|
# --- LIST group ---
|
|
32
32
|
list_parser = subparsers.add_parser("list", help="List information about Modusa components")
|
modusa/devtools/templates/io.py
CHANGED
|
@@ -3,17 +3,18 @@
|
|
|
3
3
|
|
|
4
4
|
from modusa import excp
|
|
5
5
|
from modusa.decorators import immutable_property, validate_args_type
|
|
6
|
-
from modusa.signals.base import
|
|
6
|
+
from modusa.signals.base import ?
|
|
7
7
|
from typing import Self, Any
|
|
8
8
|
import numpy as np
|
|
9
9
|
|
|
10
|
-
class {class_name}(
|
|
10
|
+
class {class_name}():
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
15
|
#--------Meta Information----------
|
|
16
16
|
_name = ""
|
|
17
|
+
_nickname = "" # This is to be used in repr/str methods
|
|
17
18
|
_description = ""
|
|
18
19
|
_author_name = "{author_name}"
|
|
19
20
|
_author_email = "{author_email}"
|
|
@@ -26,15 +27,21 @@ class {class_name}(ModusaSignal):
|
|
|
26
27
|
|
|
27
28
|
self.title = "" # This title will be used as plot title by default
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
#-----------------------------------
|
|
30
31
|
# Properties
|
|
31
|
-
|
|
32
|
+
#-----------------------------------
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
|
|
35
|
+
#===================================
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
#-----------------------------------
|
|
39
43
|
# Tools
|
|
40
|
-
|
|
44
|
+
#-----------------------------------
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
#===================================
|
modusa/generators/__init__.py
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
|
|
3
|
-
from .
|
|
3
|
+
from .base import ModusaGenerator
|
|
4
|
+
|
|
5
|
+
from .s_ax import SAxGen
|
|
6
|
+
from .t_ax import TAxGen
|
|
7
|
+
|
|
8
|
+
from .s1d import S1DGen
|
|
9
|
+
from .tds import TDSGen
|
|
10
|
+
from .audio import AudioGen
|
|
11
|
+
|
|
12
|
+
from .s2d import S2DGen
|
|
13
|
+
from .ftds import FTDSGen
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from modusa import excp
|
|
5
|
+
from modusa.decorators import validate_args_type
|
|
6
|
+
from .base import ModusaGenerator
|
|
7
|
+
from modusa.models.t_ax import TAx
|
|
8
|
+
from modusa.models.audio import Audio
|
|
9
|
+
from modusa.models.data import Data
|
|
10
|
+
import numpy as np
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
class AudioGen(ModusaGenerator):
|
|
14
|
+
"""
|
|
15
|
+
Provides user friendly APIs to generate instances of different
|
|
16
|
+
`AudioSignal` instances.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
#--------Meta Information----------
|
|
20
|
+
_name = ""
|
|
21
|
+
_description = ""
|
|
22
|
+
_author_name = "Ankit Anand"
|
|
23
|
+
_author_email = "ankit0.anand0@gmail.com"
|
|
24
|
+
_created_at = "2025-07-27"
|
|
25
|
+
#----------------------------------
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def from_array(
|
|
29
|
+
y: np.ndarray,
|
|
30
|
+
sr: float | int = 1.0,
|
|
31
|
+
t0: float | int = 0.0,
|
|
32
|
+
y_label: str = "Amplitude",
|
|
33
|
+
t_label: str = "Time (sec)",
|
|
34
|
+
title: str = "Audio Signal"
|
|
35
|
+
) -> Audio:
|
|
36
|
+
"""
|
|
37
|
+
Create `AudioSignal` instance from basic data structures.
|
|
38
|
+
|
|
39
|
+
.. code-block:: python
|
|
40
|
+
|
|
41
|
+
import modusa as ms
|
|
42
|
+
t = ms.tds.from_array([1, 2, 3])
|
|
43
|
+
print(t)
|
|
44
|
+
t.print_info()
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
y: np.ndarray
|
|
49
|
+
- Audio data array.
|
|
50
|
+
sr: float | int
|
|
51
|
+
- Sampling rate.
|
|
52
|
+
t0: float | int
|
|
53
|
+
- Start timestamp.
|
|
54
|
+
y_label: str
|
|
55
|
+
- Y label for the signal.
|
|
56
|
+
- Default: "Y"
|
|
57
|
+
t_label: str
|
|
58
|
+
- T label for the signal.
|
|
59
|
+
- Default: "Time (sec)"
|
|
60
|
+
title: str
|
|
61
|
+
- Title for the signal.
|
|
62
|
+
- Default: "1D Signal"
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
Audio
|
|
66
|
+
An instance of Audio.
|
|
67
|
+
"""
|
|
68
|
+
assert isinstance(y, np.ndarray)
|
|
69
|
+
assert isinstance(sr, (int, float)) and isinstance(t0, (int, float))
|
|
70
|
+
assert isinstance(y_label, str) and isinstance(t_label, str) and isinstance(title, str)
|
|
71
|
+
|
|
72
|
+
assert y.ndim == 1
|
|
73
|
+
|
|
74
|
+
sr = float(sr)
|
|
75
|
+
t0 = float(t0)
|
|
76
|
+
|
|
77
|
+
t = TAx(n_points=y.shape[0], sr=sr, t0=t0, label=t_label) # Creating a signal axis instance
|
|
78
|
+
y = Data(values=y, label=y_label)
|
|
79
|
+
|
|
80
|
+
return Audio(y=y, t=t, title=title)
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def from_youtube(cls, url: str, sr: int | float = None):
|
|
84
|
+
"""
|
|
85
|
+
Loads audio from youtube at a given sr.
|
|
86
|
+
The audio is deleted from the device
|
|
87
|
+
after loading.
|
|
88
|
+
|
|
89
|
+
.. code-block:: python
|
|
90
|
+
|
|
91
|
+
import modusa as ms
|
|
92
|
+
audio = ms.audio.from_youtube(
|
|
93
|
+
url="https://www.youtube.com/watch?v=lIpw9-Y_N0g",
|
|
94
|
+
sr=None
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
PARAMETERS
|
|
98
|
+
----------
|
|
99
|
+
url: str
|
|
100
|
+
Link to the YouTube video.
|
|
101
|
+
sr: int
|
|
102
|
+
Sampling rate to load the audio in.
|
|
103
|
+
|
|
104
|
+
Returns
|
|
105
|
+
-------
|
|
106
|
+
Audio:
|
|
107
|
+
An `Audio` instance with loaded audio content from YouTube.
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
from modusa.tools.youtube_downloader import YoutubeDownloader
|
|
111
|
+
from modusa import convert
|
|
112
|
+
import soundfile as sf
|
|
113
|
+
from scipy.signal import resample
|
|
114
|
+
import tempfile
|
|
115
|
+
|
|
116
|
+
# Download the audio in temp directory using tempfile module
|
|
117
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
118
|
+
audio_fp: Path = YoutubeDownloader.download(url=url, content_type="audio", output_dir=Path(tmpdir))
|
|
119
|
+
|
|
120
|
+
# Convert the audio to ".wav" form for loading
|
|
121
|
+
wav_audio_fp: Path = convert(inp_audio_fp=audio_fp, output_audio_fp=audio_fp.with_suffix(".wav"))
|
|
122
|
+
|
|
123
|
+
# Load the audio in memory
|
|
124
|
+
audio_data, audio_sr = sf.read(wav_audio_fp)
|
|
125
|
+
|
|
126
|
+
# Convert to mono if it's multi-channel
|
|
127
|
+
if audio_data.ndim > 1:
|
|
128
|
+
audio_data = audio_data.mean(axis=1)
|
|
129
|
+
|
|
130
|
+
# Resample if needed
|
|
131
|
+
if sr is not None:
|
|
132
|
+
if audio_sr != sr:
|
|
133
|
+
n_samples = int(len(audio_data) * sr / audio_sr)
|
|
134
|
+
audio_data = resample(audio_data, n_samples)
|
|
135
|
+
audio_sr = sr
|
|
136
|
+
|
|
137
|
+
audio = cls.from_array(y=audio_data, sr=audio_sr, title=audio_fp.stem)
|
|
138
|
+
|
|
139
|
+
return audio
|
|
140
|
+
|
|
141
|
+
@classmethod
|
|
142
|
+
def from_filepath(cls, fp: str | Path, sr: int | float = None):
|
|
143
|
+
"""
|
|
144
|
+
Loads audio from filepath at a given sr.
|
|
145
|
+
|
|
146
|
+
.. code-block:: python
|
|
147
|
+
|
|
148
|
+
import modusa as ms
|
|
149
|
+
audio = ms.audio.from_filepath(
|
|
150
|
+
fp="path/to/audio.wav",
|
|
151
|
+
sr=None
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
PARAMETERS
|
|
155
|
+
----------
|
|
156
|
+
fp: str | Path
|
|
157
|
+
Audio file path.
|
|
158
|
+
sr: int
|
|
159
|
+
Sampling rate to load the audio in.
|
|
160
|
+
|
|
161
|
+
Returns
|
|
162
|
+
-------
|
|
163
|
+
Audio:
|
|
164
|
+
An `Audio` instance with loaded audio content.
|
|
165
|
+
"""
|
|
166
|
+
import soundfile as sf
|
|
167
|
+
from scipy.signal import resample
|
|
168
|
+
from pathlib import Path
|
|
169
|
+
|
|
170
|
+
fp = Path(fp)
|
|
171
|
+
# Load the audio in memory
|
|
172
|
+
audio_data, audio_sr = sf.read(fp)
|
|
173
|
+
|
|
174
|
+
# Convert to mono if it's multi-channel
|
|
175
|
+
if audio_data.ndim > 1:
|
|
176
|
+
audio_data = audio_data.mean(axis=1)
|
|
177
|
+
|
|
178
|
+
# Resample if needed
|
|
179
|
+
if sr is not None:
|
|
180
|
+
if audio_sr != sr:
|
|
181
|
+
n_samples = int(len(audio_data) * sr / audio_sr)
|
|
182
|
+
audio_data = resample(audio_data, n_samples)
|
|
183
|
+
audio_sr = sr
|
|
184
|
+
|
|
185
|
+
audio = cls.from_array(y=audio_data, sr=audio_sr, title=fp.stem)
|
|
186
|
+
|
|
187
|
+
return audio
|
|
188
|
+
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
from modusa import excp
|
|
5
5
|
from modusa.decorators import validate_args_type
|
|
6
6
|
from modusa.generators.base import ModusaGenerator
|
|
7
|
-
from modusa.
|
|
7
|
+
from modusa.models.audio_signal import AudioSignal
|
|
8
8
|
import numpy as np
|
|
9
9
|
|
|
10
10
|
class AudioWaveformGenerator(ModusaGenerator):
|
modusa/generators/base.py
CHANGED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from modusa import excp
|
|
5
|
+
from modusa.decorators import validate_args_type
|
|
6
|
+
from .base import ModusaGenerator
|
|
7
|
+
from modusa.models.data import Data
|
|
8
|
+
from modusa.models.s_ax import SAx
|
|
9
|
+
from modusa.models.t_ax import TAx
|
|
10
|
+
from modusa.models.ftds import FTDS
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
class FTDSGen(ModusaGenerator):
|
|
14
|
+
"""
|
|
15
|
+
Provides user friendly APIs to generate instances of different
|
|
16
|
+
`FTDS` instances.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
#--------Meta Information----------
|
|
20
|
+
_name = ""
|
|
21
|
+
_description = ""
|
|
22
|
+
_author_name = "Ankit Anand"
|
|
23
|
+
_author_email = "ankit0.anand0@gmail.com"
|
|
24
|
+
_created_at = "2025-07-27"
|
|
25
|
+
#----------------------------------
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def from_array(
|
|
29
|
+
M: np.ndarray | list | float | int | np.generic,
|
|
30
|
+
f: np.ndarray | list | float | int | np.generic | None = None,
|
|
31
|
+
sr: int | float = 1.0,
|
|
32
|
+
t0: int | float = 0.0,
|
|
33
|
+
M_label: str = "M",
|
|
34
|
+
f_label: str = "Feature",
|
|
35
|
+
t_label: str = "Time (sec)",
|
|
36
|
+
title: str = "Feature Time Domain Signal"
|
|
37
|
+
) -> FTDS:
|
|
38
|
+
"""
|
|
39
|
+
Create `FDTS` instance from basic data structures.
|
|
40
|
+
|
|
41
|
+
.. code-block:: python
|
|
42
|
+
|
|
43
|
+
import modusa as ms
|
|
44
|
+
M = ms.ftds.from_array([1, 2, 3])
|
|
45
|
+
print(M)
|
|
46
|
+
M.print_info()
|
|
47
|
+
|
|
48
|
+
Parameters
|
|
49
|
+
----------
|
|
50
|
+
M: np.ndarray | list | float | int | np.generic
|
|
51
|
+
- Data values.
|
|
52
|
+
f: np.ndarray | list | float | int | np.generic | None
|
|
53
|
+
- y axis values.
|
|
54
|
+
- Default: None → Creates an integer indexing.
|
|
55
|
+
sr: int | float
|
|
56
|
+
- Sampling rate / Frame rate.
|
|
57
|
+
- Default: 1.0
|
|
58
|
+
t0: int | float
|
|
59
|
+
- Start timestamp.
|
|
60
|
+
- Default: 0.0
|
|
61
|
+
M_label: str
|
|
62
|
+
- Label for the data.
|
|
63
|
+
- Default: "M"
|
|
64
|
+
f_label: str
|
|
65
|
+
- Feature label for the signal.
|
|
66
|
+
- Default: "Feature"
|
|
67
|
+
t_label: str
|
|
68
|
+
- Time label for the signal.
|
|
69
|
+
- Default: "Time (sec)"
|
|
70
|
+
title: str
|
|
71
|
+
- Title for the signal.
|
|
72
|
+
- Default: "Feature Time Domain Signal"
|
|
73
|
+
Returns
|
|
74
|
+
-------
|
|
75
|
+
FTDS
|
|
76
|
+
An instance of FTDS.
|
|
77
|
+
"""
|
|
78
|
+
assert isinstance(M, (np.ndarray, list, float, int, np.generic))
|
|
79
|
+
assert isinstance(f, (np.ndarray, list, float, int, np.generic)) or f is None
|
|
80
|
+
assert isinstance(sr, (int, float)) and isinstance(t0, (int, float))
|
|
81
|
+
assert isinstance(M_label, str) and isinstance(f_label, str) and isinstance(t_label, str) and isinstance(title, str)
|
|
82
|
+
|
|
83
|
+
if isinstance(M, (float, int, np.generic)): M = [[M]] # Convert to list of 1 element
|
|
84
|
+
if isinstance(f, (float, int, np.generic)): f = [f] # Convert to list of 1 element
|
|
85
|
+
|
|
86
|
+
M = np.asarray(M)
|
|
87
|
+
assert M.ndim == 2
|
|
88
|
+
|
|
89
|
+
if f is None: f = np.arange(M.shape[0])
|
|
90
|
+
else: f = np.asarray(f)
|
|
91
|
+
assert f.ndim == 1
|
|
92
|
+
assert f.shape[0] == M.shape[0], "Shape mismatch"
|
|
93
|
+
|
|
94
|
+
sr = float(sr)
|
|
95
|
+
t0 = float(t0)
|
|
96
|
+
|
|
97
|
+
M = Data(values=M, label=M_label)
|
|
98
|
+
f = SAx(values=f, label=f_label)
|
|
99
|
+
t = TAx(n_points=M.shape[1], sr=sr, t0=t0, label=t_label)
|
|
100
|
+
|
|
101
|
+
return FTDS(M=M, f=f, t=t, title=title)
|
|
102
|
+
|
|
103
|
+
@classmethod
|
|
104
|
+
def zeros(cls, shape, f=None, sr=1.0, t0=0.0) -> FTDS:
|
|
105
|
+
"""
|
|
106
|
+
Create `FTDS` instance with all zeros.
|
|
107
|
+
|
|
108
|
+
.. code-block:: python
|
|
109
|
+
|
|
110
|
+
import modusa as ms
|
|
111
|
+
M = ms.ftds.zeros((10, 5))
|
|
112
|
+
print(M)
|
|
113
|
+
M.print_info()
|
|
114
|
+
|
|
115
|
+
Parameters
|
|
116
|
+
----------
|
|
117
|
+
shape: tuple[int, int]
|
|
118
|
+
- Shape of the signal with zeros.
|
|
119
|
+
- Must be 1 dimensional
|
|
120
|
+
- E.g. (10, 5)
|
|
121
|
+
Returns
|
|
122
|
+
-------
|
|
123
|
+
FTDS
|
|
124
|
+
An instance of FTDS.
|
|
125
|
+
"""
|
|
126
|
+
assert isinstance(shape, tuple)
|
|
127
|
+
M = np.zeros(shape)
|
|
128
|
+
|
|
129
|
+
return cls.from_array(M=M, f=f, sr=sr, t0=t0, title="Zeros")
|
|
130
|
+
|
|
131
|
+
@classmethod
|
|
132
|
+
def zeros_like(cls, signal: FTDS) -> FTDS:
|
|
133
|
+
"""
|
|
134
|
+
Create `FTDS` instance similar to `signal`
|
|
135
|
+
but with all entries being zeros.
|
|
136
|
+
|
|
137
|
+
.. code-block:: python
|
|
138
|
+
|
|
139
|
+
import modusa as ms
|
|
140
|
+
signal = ms.ftds.from_array([[1, 2, 3], [4, 5, 6]])
|
|
141
|
+
M = ms.ftds.zeros_like(signal)
|
|
142
|
+
print(M)
|
|
143
|
+
M.print_info()
|
|
144
|
+
|
|
145
|
+
Parameters
|
|
146
|
+
----------
|
|
147
|
+
signal: FTDS
|
|
148
|
+
- Reference signal to create zeros like that.
|
|
149
|
+
Returns
|
|
150
|
+
-------
|
|
151
|
+
FTDS
|
|
152
|
+
An instance of FTDS.
|
|
153
|
+
"""
|
|
154
|
+
|
|
155
|
+
assert signal.__class__ in [FTDS]
|
|
156
|
+
|
|
157
|
+
M = np.zeros(signal.shape)
|
|
158
|
+
f = signal._f
|
|
159
|
+
t = signal._t
|
|
160
|
+
|
|
161
|
+
M_label = signal._M_label
|
|
162
|
+
f_label = signal._f_label
|
|
163
|
+
t_label = signal._t_label
|
|
164
|
+
title = signal._title
|
|
165
|
+
|
|
166
|
+
return cls.from_array(M=M, f=f, t=t, M_label=M_label, f_label=f_label, t_label=t_label, title=title)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
@classmethod
|
|
170
|
+
def ones(cls, shape: tuple[int, int]) -> FTDS:
|
|
171
|
+
"""
|
|
172
|
+
Create `FTDS` instance with all ones.
|
|
173
|
+
|
|
174
|
+
.. code-block:: python
|
|
175
|
+
|
|
176
|
+
import modusa as ms
|
|
177
|
+
M = ms.ftds.ones((10, 5))
|
|
178
|
+
print(M)
|
|
179
|
+
M.print_info()
|
|
180
|
+
|
|
181
|
+
Parameters
|
|
182
|
+
----------
|
|
183
|
+
shape: tuple[int, int]
|
|
184
|
+
- Shape of the signal with ones.
|
|
185
|
+
- Must be 1 dimensional
|
|
186
|
+
- E.g. (10, 5)
|
|
187
|
+
Returns
|
|
188
|
+
-------
|
|
189
|
+
FTDS
|
|
190
|
+
An instance of FTDS.
|
|
191
|
+
"""
|
|
192
|
+
assert isinstance(shape, tuple)
|
|
193
|
+
M = np.ones(shape)
|
|
194
|
+
|
|
195
|
+
return cls.from_array(M=M, title="Ones")
|
|
196
|
+
|
|
197
|
+
@classmethod
|
|
198
|
+
def ones_like(cls, signal: FTDS) -> FTDS:
|
|
199
|
+
"""
|
|
200
|
+
Create `FTDS` instance similar to `signal`
|
|
201
|
+
but with all entries being ones.
|
|
202
|
+
|
|
203
|
+
.. code-block:: python
|
|
204
|
+
|
|
205
|
+
import modusa as ms
|
|
206
|
+
signal = ms.ftds.from_array([[1, 2, 3], [4, 5, 6]])
|
|
207
|
+
M = ms.ftds.ones_like(signal)
|
|
208
|
+
print(M)
|
|
209
|
+
M.print_info()
|
|
210
|
+
|
|
211
|
+
Parameters
|
|
212
|
+
----------
|
|
213
|
+
signal: FTDS
|
|
214
|
+
- Reference signal to create ones like that.
|
|
215
|
+
Returns
|
|
216
|
+
-------
|
|
217
|
+
FTDS
|
|
218
|
+
An instance of FTDS.
|
|
219
|
+
"""
|
|
220
|
+
|
|
221
|
+
assert signal.__class__ in [FTDS]
|
|
222
|
+
|
|
223
|
+
M = np.ones(signal.shape)
|
|
224
|
+
f = signal._f
|
|
225
|
+
t = signal._t
|
|
226
|
+
|
|
227
|
+
M_label = signal._M_label
|
|
228
|
+
f_label = signal._f_label
|
|
229
|
+
t_label = signal._t_label
|
|
230
|
+
title = signal._title
|
|
231
|
+
|
|
232
|
+
return cls.from_array(M=M, f=f, t=t, M_label=M_label, f_label=f_label, t_label=t_label, title=title)
|
|
233
|
+
|
|
234
|
+
@classmethod
|
|
235
|
+
def random(cls, shape: tuple[int, int]) -> FTDS:
|
|
236
|
+
"""
|
|
237
|
+
Create `FTDS` instance with random entries.
|
|
238
|
+
|
|
239
|
+
.. code-block:: python
|
|
240
|
+
|
|
241
|
+
import modusa as ms
|
|
242
|
+
M = ms.ftds.random((10, 5))
|
|
243
|
+
print(M)
|
|
244
|
+
M.print_info()
|
|
245
|
+
|
|
246
|
+
Parameters
|
|
247
|
+
----------
|
|
248
|
+
shape: tuple[int, int]
|
|
249
|
+
- Shape of the signal with random values.
|
|
250
|
+
- Must be 1 dimensional
|
|
251
|
+
- E.g. (10, 5)
|
|
252
|
+
Returns
|
|
253
|
+
-------
|
|
254
|
+
FTDS
|
|
255
|
+
An instance of FTDS.
|
|
256
|
+
"""
|
|
257
|
+
assert isinstance(shape, tuple)
|
|
258
|
+
M = np.random.random(shape)
|
|
259
|
+
|
|
260
|
+
return cls.from_array(M=M, title="Random")
|
|
261
|
+
|
|
262
|
+
@classmethod
|
|
263
|
+
def random_like(cls, signal: FTDS) -> FTDS:
|
|
264
|
+
"""
|
|
265
|
+
Create `FTDS` instance similar to `signal`
|
|
266
|
+
but with random entries.
|
|
267
|
+
|
|
268
|
+
.. code-block:: python
|
|
269
|
+
|
|
270
|
+
import modusa as ms
|
|
271
|
+
signal = ms.ftds.from_array([[1, 2, 3], [4, 5, 6]])
|
|
272
|
+
M = ms.ftds.random_like(signal)
|
|
273
|
+
print(M)
|
|
274
|
+
M.print_info()
|
|
275
|
+
|
|
276
|
+
Parameters
|
|
277
|
+
----------
|
|
278
|
+
signal: FTDS
|
|
279
|
+
- Reference signal.
|
|
280
|
+
Returns
|
|
281
|
+
-------
|
|
282
|
+
FTDS
|
|
283
|
+
An instance of FTDS with random values.
|
|
284
|
+
"""
|
|
285
|
+
|
|
286
|
+
assert signal.__class__ in [FTDS]
|
|
287
|
+
|
|
288
|
+
M = np.random.random(signal.shape)
|
|
289
|
+
f = signal._f
|
|
290
|
+
t = signal._t
|
|
291
|
+
|
|
292
|
+
M_label = signal._M_label
|
|
293
|
+
f_label = signal._f_label
|
|
294
|
+
t_label = signal._t_label
|
|
295
|
+
title = signal._title
|
|
296
|
+
|
|
297
|
+
return cls.from_array(M=M, f=f, t=t, M_label=M_label, f_label=f_label, t_label=t_label, title=title)
|
|
298
|
+
|