modusa 0.4.28__py3-none-any.whl → 0.4.30__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/__init__.py +9 -8
- modusa/tools/__init__.py +7 -2
- modusa/tools/ann_saver.py +30 -0
- modusa/tools/audio_recorder.py +0 -1
- modusa/tools/synth.py +2 -0
- modusa/tools/youtube_downloader.py +1 -4
- {modusa-0.4.28.dist-info → modusa-0.4.30.dist-info}/METADATA +2 -2
- modusa-0.4.30.dist-info/RECORD +21 -0
- pyproject.toml +2 -2
- modusa/config.py +0 -18
- modusa/decorators.py +0 -176
- modusa/devtools/generate_docs_source.py +0 -92
- modusa/devtools/generate_template.py +0 -144
- modusa/devtools/list_authors.py +0 -2
- modusa/devtools/list_plugins.py +0 -60
- modusa/devtools/main.py +0 -45
- modusa/devtools/templates/generator.py +0 -24
- modusa/devtools/templates/io.py +0 -24
- modusa/devtools/templates/model.py +0 -47
- modusa/devtools/templates/plugin.py +0 -41
- modusa/devtools/templates/test.py +0 -10
- modusa/devtools/templates/tool.py +0 -24
- modusa/generators/__init__.py +0 -13
- modusa/generators/audio.py +0 -188
- modusa/generators/audio_waveforms.py +0 -236
- modusa/generators/base.py +0 -29
- modusa/generators/ftds.py +0 -298
- modusa/generators/s1d.py +0 -270
- modusa/generators/s2d.py +0 -300
- modusa/generators/s_ax.py +0 -102
- modusa/generators/t_ax.py +0 -64
- modusa/generators/tds.py +0 -267
- modusa/models/__init__.py +0 -14
- modusa/models/audio.py +0 -90
- modusa/models/base.py +0 -70
- modusa/models/data.py +0 -457
- modusa/models/ftds.py +0 -584
- modusa/models/s1d.py +0 -578
- modusa/models/s2d.py +0 -619
- modusa/models/s_ax.py +0 -448
- modusa/models/t_ax.py +0 -335
- modusa/models/tds.py +0 -465
- modusa/plugins/__init__.py +0 -3
- modusa/plugins/base.py +0 -100
- modusa/tools/_plotter_old.py +0 -629
- modusa/tools/audio_saver.py +0 -30
- modusa/tools/base.py +0 -43
- modusa/tools/math_ops.py +0 -335
- modusa/utils/__init__.py +0 -1
- modusa/utils/config.py +0 -25
- modusa/utils/excp.py +0 -49
- modusa/utils/logger.py +0 -18
- modusa/utils/np_func_cat.py +0 -44
- modusa/utils/plot.py +0 -142
- modusa-0.4.28.dist-info/RECORD +0 -65
- {modusa-0.4.28.dist-info → modusa-0.4.30.dist-info}/WHEEL +0 -0
- {modusa-0.4.28.dist-info → modusa-0.4.30.dist-info}/entry_points.txt +0 -0
- {modusa-0.4.28.dist-info → modusa-0.4.30.dist-info}/licenses/LICENSE.md +0 -0
modusa/generators/ftds.py
DELETED
@@ -1,298 +0,0 @@
|
|
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
|
-
|
modusa/generators/s1d.py
DELETED
@@ -1,270 +0,0 @@
|
|
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.s1d import S1D
|
8
|
-
from modusa.models.s_ax import SAx
|
9
|
-
from modusa.models.data import Data
|
10
|
-
import numpy as np
|
11
|
-
|
12
|
-
class S1DGen(ModusaGenerator):
|
13
|
-
"""
|
14
|
-
Provides user friendly APIs to generate instances of different `S1D`
|
15
|
-
instances.
|
16
|
-
"""
|
17
|
-
|
18
|
-
#--------Meta Information----------
|
19
|
-
_name = ""
|
20
|
-
_description = ""
|
21
|
-
_author_name = "Ankit Anand"
|
22
|
-
_author_email = "ankit0.anand0@gmail.com"
|
23
|
-
_created_at = "2025-07-27"
|
24
|
-
#----------------------------------
|
25
|
-
|
26
|
-
@staticmethod
|
27
|
-
def from_array(
|
28
|
-
y,
|
29
|
-
x = None,
|
30
|
-
y_label: str = "Y",
|
31
|
-
x_label: str = "X",
|
32
|
-
title: str = "1D Signal"
|
33
|
-
) -> S1D:
|
34
|
-
"""
|
35
|
-
Create `S1D` instance from basic data structures.
|
36
|
-
|
37
|
-
.. code-block:: python
|
38
|
-
|
39
|
-
import modusa as ms
|
40
|
-
x = ms.s1d.from_array([1, 2, 3])
|
41
|
-
print(x)
|
42
|
-
x.print_info()
|
43
|
-
|
44
|
-
Parameters
|
45
|
-
----------
|
46
|
-
y: array-like
|
47
|
-
- Data values.
|
48
|
-
x: array-like | None
|
49
|
-
- Corresponding axis values.
|
50
|
-
- Default: None → Creates an integer indexing.
|
51
|
-
y_label: str
|
52
|
-
- Y label for the signal.
|
53
|
-
- Default: "Y"
|
54
|
-
x_label: str
|
55
|
-
- X label for the signal.
|
56
|
-
- Default: "X"
|
57
|
-
title: str
|
58
|
-
- Title for the signal.
|
59
|
-
- Default: "1D Signal"
|
60
|
-
Returns
|
61
|
-
-------
|
62
|
-
S1D
|
63
|
-
An instance of S1D.
|
64
|
-
"""
|
65
|
-
assert isinstance(y, (np.ndarray, list, float, int, np.generic))
|
66
|
-
assert isinstance(x, (np.ndarray, list, float, int, np.generic)) or x is None
|
67
|
-
assert isinstance(y_label, str) and isinstance(x_label, str) and isinstance(title, str)
|
68
|
-
|
69
|
-
if isinstance(y, (float, int, np.generic)): y = [y] # Convert to list of 1 element
|
70
|
-
if isinstance(x, (float, int, np.generic)): x = [x] # Convert to list of 1 element
|
71
|
-
|
72
|
-
y = np.asarray(y)
|
73
|
-
if x is None: x = np.arange(y.shape[0])
|
74
|
-
else: x = np.asarray(x)
|
75
|
-
|
76
|
-
assert y.ndim ==1 and x.ndim == 1, "S1D must have only one dimension"
|
77
|
-
assert y.shape == x.shape, "Shape mismatch"
|
78
|
-
|
79
|
-
y = Data(values=y, label=y_label)
|
80
|
-
x = SAx(values=x, label=x_label) # Creating a signal axis instance
|
81
|
-
|
82
|
-
return S1D(y=y, x=x, title=title)
|
83
|
-
|
84
|
-
@classmethod
|
85
|
-
def zeros(cls, shape) -> S1D:
|
86
|
-
"""
|
87
|
-
Create `S1D` instance with all zeros.
|
88
|
-
|
89
|
-
.. code-block:: python
|
90
|
-
|
91
|
-
import modusa as ms
|
92
|
-
y = ms.s1d.zeros(10)
|
93
|
-
print(y)
|
94
|
-
y.print_info()
|
95
|
-
|
96
|
-
Parameters
|
97
|
-
----------
|
98
|
-
shape: int | tuple[int]
|
99
|
-
- Shape of the signal with zeros.
|
100
|
-
- Must be 1 dimensional
|
101
|
-
- E.g. 10 or (10, )
|
102
|
-
Returns
|
103
|
-
-------
|
104
|
-
S1D
|
105
|
-
An instance of S1D.
|
106
|
-
"""
|
107
|
-
assert isinstance(shape, (int, tuple))
|
108
|
-
y = np.zeros(shape)
|
109
|
-
|
110
|
-
return cls.from_array(y=y, title="Zeros")
|
111
|
-
|
112
|
-
@classmethod
|
113
|
-
def zeros_like(cls, signal: S1D) -> S1D:
|
114
|
-
"""
|
115
|
-
Create `S1D` instance similar to `signal`
|
116
|
-
but with all entries being zeros.
|
117
|
-
|
118
|
-
.. code-block:: python
|
119
|
-
|
120
|
-
import modusa as ms
|
121
|
-
signal = ms.s1d.from_array([1, 2, 3])
|
122
|
-
y = ms.s1d.zeros_like(signal)
|
123
|
-
print(y)
|
124
|
-
x.print_info()
|
125
|
-
|
126
|
-
Parameters
|
127
|
-
----------
|
128
|
-
signal: S1D
|
129
|
-
- Reference signal to create zeros like that.
|
130
|
-
Returns
|
131
|
-
-------
|
132
|
-
S1D
|
133
|
-
An instance of S1D.
|
134
|
-
"""
|
135
|
-
|
136
|
-
assert signal.__class__ in [S1D]
|
137
|
-
|
138
|
-
y = np.zeros(signal.shape)
|
139
|
-
y_label = signal._y_label
|
140
|
-
x = signal._x
|
141
|
-
x_label = signal._x_label
|
142
|
-
title = signal._title
|
143
|
-
|
144
|
-
return cls.from_array(y=y, x=x, y_label=y_label, x_label=x_label, title=title)
|
145
|
-
|
146
|
-
|
147
|
-
@classmethod
|
148
|
-
def ones(cls, shape: int | tuple[int, int]) -> S1D:
|
149
|
-
"""
|
150
|
-
Create `S1D` instance with all ones.
|
151
|
-
|
152
|
-
.. code-block:: python
|
153
|
-
|
154
|
-
import modusa as ms
|
155
|
-
y = ms.s1d.ones(10)
|
156
|
-
print(y)
|
157
|
-
y.print_info()
|
158
|
-
|
159
|
-
Parameters
|
160
|
-
----------
|
161
|
-
shape: int | tuple[int]
|
162
|
-
- Shape of the signal with ones.
|
163
|
-
- Must be 1 dimensional
|
164
|
-
- E.g. 10 or (10, )
|
165
|
-
Returns
|
166
|
-
-------
|
167
|
-
S1D
|
168
|
-
An instance of S1D.
|
169
|
-
"""
|
170
|
-
assert isinstance(shape, (int, tuple))
|
171
|
-
y = np.ones(shape)
|
172
|
-
|
173
|
-
return cls.from_array(y=y, title="Ones")
|
174
|
-
|
175
|
-
@classmethod
|
176
|
-
def ones_like(cls, signal: S1D) -> S1D:
|
177
|
-
"""
|
178
|
-
Create `S1D` instance similar to `signal`
|
179
|
-
but with all entries being ones.
|
180
|
-
|
181
|
-
.. code-block:: python
|
182
|
-
|
183
|
-
import modusa as ms
|
184
|
-
signal = ms.s1d.from_array([1, 2, 3])
|
185
|
-
y = ms.s1d.ones_like(signal)
|
186
|
-
print(y)
|
187
|
-
y.print_info()
|
188
|
-
|
189
|
-
Parameters
|
190
|
-
----------
|
191
|
-
signal: S1D
|
192
|
-
- Reference signal to create ones like that.
|
193
|
-
Returns
|
194
|
-
-------
|
195
|
-
S1D
|
196
|
-
An instance of S1D.
|
197
|
-
"""
|
198
|
-
|
199
|
-
assert signal.__class__ in [S1D]
|
200
|
-
|
201
|
-
y = np.ones(signal.shape)
|
202
|
-
y_label = signal._y_label
|
203
|
-
x = signal._x
|
204
|
-
x_label = signal._x_label
|
205
|
-
title = signal._title
|
206
|
-
|
207
|
-
return cls.from_array(y=y, x=x, y_label=y_label, x_label=x_label, title=title)
|
208
|
-
|
209
|
-
@classmethod
|
210
|
-
def random(cls, shape: int) -> S1D:
|
211
|
-
"""
|
212
|
-
Create `S1D` instance with random entries.
|
213
|
-
|
214
|
-
.. code-block:: python
|
215
|
-
|
216
|
-
import modusa as ms
|
217
|
-
y = ms.s1d.random(10)
|
218
|
-
print(y)
|
219
|
-
y.print_info()
|
220
|
-
|
221
|
-
Parameters
|
222
|
-
----------
|
223
|
-
shape: int | tuple[int]
|
224
|
-
- Shape of the signal.
|
225
|
-
- Must be 1 dimensional
|
226
|
-
- E.g. 10 or (10, )
|
227
|
-
Returns
|
228
|
-
-------
|
229
|
-
S1D
|
230
|
-
An instance of S1D with random values.
|
231
|
-
"""
|
232
|
-
assert isinstance(shape, (int, tuple))
|
233
|
-
y = np.random.random(shape)
|
234
|
-
|
235
|
-
return cls.from_array(y=y, title="Random")
|
236
|
-
|
237
|
-
@classmethod
|
238
|
-
def random_like(cls, signal: S1D) -> S1D:
|
239
|
-
"""
|
240
|
-
Create `S1D` instance similar to `signal`
|
241
|
-
but with all entries being ones.
|
242
|
-
|
243
|
-
.. code-block:: python
|
244
|
-
|
245
|
-
import modusa as ms
|
246
|
-
signal = ms.s1d.from_array([1, 2, 3])
|
247
|
-
y = ms.s1d.random_like(signal)
|
248
|
-
print(y)
|
249
|
-
y.print_info()
|
250
|
-
|
251
|
-
Parameters
|
252
|
-
----------
|
253
|
-
signal: S1D
|
254
|
-
- Reference signal to create one with random entries.
|
255
|
-
Returns
|
256
|
-
-------
|
257
|
-
S1D
|
258
|
-
An instance of S1D with random values.
|
259
|
-
"""
|
260
|
-
|
261
|
-
assert signal.__class__ in [S1D]
|
262
|
-
|
263
|
-
y = np.random.random(signal.shape)
|
264
|
-
y_label = signal._y_label
|
265
|
-
x = signal._x
|
266
|
-
x_label = signal._x_label
|
267
|
-
title = signal._title
|
268
|
-
|
269
|
-
return cls.from_array(y=y, x=x, y_label=y_label, x_label=x_label, title=title)
|
270
|
-
|