zfp-oss #27
|
|
@ -159,7 +159,7 @@ Finally, RIA Toolkit OSS can be installed directly from the source code. This ap
|
||||||
Once the project is installed, you can import modules, functions, and classes from the Toolkit for use in your Python code. For example, you can use the following import statement to access the `Recording` object:
|
Once the project is installed, you can import modules, functions, and classes from the Toolkit for use in your Python code. For example, you can use the following import statement to access the `Recording` object:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
```
|
```
|
||||||
|
|
||||||
Additional usage information is provided in the project documentation: [RIA Toolkit OSS Documentation](https://ria-toolkit-oss.readthedocs.io/).
|
Additional usage information is provided in the project documentation: [RIA Toolkit OSS Documentation](https://ria-toolkit-oss.readthedocs.io/).
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ In this example, we initialize the `Blade` SDR, configure it to record a signal
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.sdr.blade import Blade
|
from ria_toolkit_oss.sdr.blade import Blade
|
||||||
|
|
||||||
my_radio = Blade()
|
my_radio = Blade()
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ Code
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.sdr.blade import Blade
|
from ria_toolkit_oss.sdr.blade import Blade
|
||||||
|
|
||||||
# Parameters
|
# Parameters
|
||||||
|
|
|
||||||
|
|
@ -1027,7 +1027,7 @@ For quick non-CLI use:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
from ria_toolkit_oss.io import load_recording, to_sigmf
|
from ria_toolkit_oss.io import load_recording, to_sigmf
|
||||||
from ria_toolkit_oss.transforms import iq_augmentations, iq_impairments
|
from ria_toolkit_oss.transforms import iq_augmentations, iq_impairments
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,15 @@ The Radio Dataset Framework provides a software interface to access and manipula
|
||||||
the need for users to interface with the source files directly. Instead, users initialize and interact with a Python
|
the need for users to interface with the source files directly. Instead, users initialize and interact with a Python
|
||||||
object, while the complexities of efficient data retrieval and source file manipulation are managed behind the scenes.
|
object, while the complexities of efficient data retrieval and source file manipulation are managed behind the scenes.
|
||||||
|
|
||||||
Ria Toolkit OSS includes an abstract class called :py:obj:`ria_toolkit_oss.datatypes.datasets.RadioDataset`, which defines common properties and
|
Ria Toolkit OSS includes an abstract class called :py:obj:`ria_toolkit_oss.data.datasets.RadioDataset`, which defines common properties and
|
||||||
behaviors for all radio datasets. :py:obj:`ria_toolkit_oss.datatypes.datasets.RadioDataset` can be considered a blueprint for all
|
behaviors for all radio datasets. :py:obj:`ria_toolkit_oss.data.datasets.RadioDataset` can be considered a blueprint for all
|
||||||
other radio dataset classes. This class is then subclassed to define more specific blueprints for different types
|
other radio dataset classes. This class is then subclassed to define more specific blueprints for different types
|
||||||
of radio datasets. For example, :py:obj:`ria_toolkit_oss.datatypes.datasets.IQDataset`, which is tailored for machine learning tasks
|
of radio datasets. For example, :py:obj:`ria_toolkit_oss.data.datasets.IQDataset`, which is tailored for machine learning tasks
|
||||||
involving the processing of signals represented as IQ (In-phase and Quadrature) samples.
|
involving the processing of signals represented as IQ (In-phase and Quadrature) samples.
|
||||||
|
|
||||||
Then, in the various project backends, there are concrete dataset classes, which inherit from both Ria Toolkit OSS and the base
|
Then, in the various project backends, there are concrete dataset classes, which inherit from both Ria Toolkit OSS and the base
|
||||||
dataset class from the respective backend. For example, the :py:obj:`TorchIQDataset` class extends both
|
dataset class from the respective backend. For example, the :py:obj:`TorchIQDataset` class extends both
|
||||||
:py:obj:`ria_toolkit_oss.datatypes.datasets.IQDataset` from Ria Toolkit OSS and :py:obj:`torch.ria_toolkit_oss.datatypes.IterableDataset` from
|
:py:obj:`ria_toolkit_oss.data.datasets.IQDataset` from Ria Toolkit OSS and :py:obj:`torch.ria_toolkit_oss.data.IterableDataset` from
|
||||||
PyTorch, providing a concrete dataset class tailored for IQ datasets and optimized for the PyTorch backend.
|
PyTorch, providing a concrete dataset class tailored for IQ datasets and optimized for the PyTorch backend.
|
||||||
|
|
||||||
Dataset initialization
|
Dataset initialization
|
||||||
|
|
@ -130,7 +130,7 @@ Dataset processing and manipulation
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
All radio datasets support methods tailored specifically for radio processing. These methods are backend-independent,
|
All radio datasets support methods tailored specifically for radio processing. These methods are backend-independent,
|
||||||
inherited from the blueprints in Ria Toolkit OSS like :py:obj:`ria_toolkit_oss.datatypes.datasets.RadioDataset`.
|
inherited from the blueprints in Ria Toolkit OSS like :py:obj:`ria_toolkit_oss.data.datasets.RadioDataset`.
|
||||||
|
|
||||||
For example, we can trim down the length of the examples from 1,024 to 512 samples, and then augment the dataset:
|
For example, we can trim down the length of the examples from 1,024 to 512 samples, and then augment the dataset:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
Dataset License SubModule
|
Dataset License SubModule
|
||||||
=========================
|
=========================
|
||||||
|
|
||||||
.. automodule:: ria_toolkit_oss.datatypes.datasets.license
|
.. automodule:: ria_toolkit_oss.data.datasets.license
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
Datatypes Package (ria_toolkit_oss.datatypes)
|
Datatypes Package (ria_toolkit_oss.data)
|
||||||
=============================================
|
=============================================
|
||||||
|
|
||||||
.. |br| raw:: html
|
.. |br| raw:: html
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
.. automodule:: ria_toolkit_oss.datatypes
|
.. automodule:: ria_toolkit_oss.data
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
@ -13,7 +13,7 @@ Datatypes Package (ria_toolkit_oss.datatypes)
|
||||||
Radio Dataset SubPackage
|
Radio Dataset SubPackage
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
.. automodule:: ria_toolkit_oss.datatypes.datasets
|
.. automodule:: ria_toolkit_oss.data.datasets
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
@ -21,5 +21,5 @@ Radio Dataset SubPackage
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
|
|
||||||
Dataset License SubModule <ria_toolkit_oss.datatypes.datasets.license>
|
Dataset License SubModule <ria_toolkit_oss.data.datasets.license>
|
||||||
Radio Datasets <radio_datasets>
|
Radio Datasets <radio_datasets>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class and function signatures, and doctest examples where available.
|
||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
:caption: Contents:
|
:caption: Contents:
|
||||||
|
|
||||||
Datatypes Package <datatypes/ria_toolkit_oss.datatypes>
|
Data Package <data/ria_toolkit_oss.data>
|
||||||
SDR Package <ria_toolkit_oss.sdr>
|
SDR Package <ria_toolkit_oss.sdr>
|
||||||
IO Package <ria_toolkit_oss.io>
|
IO Package <ria_toolkit_oss.io>
|
||||||
Transforms Package <ria_toolkit_oss.transforms>
|
Transforms Package <ria_toolkit_oss.transforms>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from ria_toolkit_oss.datatypes.annotation import Annotation
|
from ria_toolkit_oss.data.annotation import Annotation
|
||||||
|
|
||||||
# TODO figure out how to transfer labels in the merge case
|
# TODO figure out how to transfer labels in the merge case
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from typing import Optional
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Annotation, Recording
|
from ria_toolkit_oss.data import Annotation, Recording
|
||||||
|
|
||||||
|
|
||||||
def annotate_with_cusum(
|
def annotate_with_cusum(
|
||||||
|
|
@ -24,7 +24,7 @@ def annotate_with_cusum(
|
||||||
changes between a low and high amplitude.
|
changes between a low and high amplitude.
|
||||||
|
|
||||||
:param recording: A ``Recording`` object to annotate.
|
:param recording: A ``Recording`` object to annotate.
|
||||||
:type recording: ``ria_toolkit_oss.datatypes.Recording``
|
:type recording: ``ria_toolkit_oss.data.Recording``
|
||||||
:param label: Label for the detected segments.
|
:param label: Label for the detected segments.
|
||||||
:type label: str
|
:type label: str
|
||||||
:param window_size: The length (in samples) of the moving average window.
|
:param window_size: The length (in samples) of the moving average window.
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from typing import Tuple
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy.signal import filtfilt
|
from scipy.signal import filtfilt
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Annotation, Recording
|
from ria_toolkit_oss.data import Annotation, Recording
|
||||||
|
|
||||||
|
|
||||||
def detect_signals_energy(
|
def detect_signals_energy(
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ import numpy as np
|
||||||
from scipy import ndimage
|
from scipy import ndimage
|
||||||
from scipy import signal as scipy_signal
|
from scipy import signal as scipy_signal
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Annotation, Recording
|
from ria_toolkit_oss.data import Annotation, Recording
|
||||||
|
|
||||||
|
|
||||||
def find_spectral_components(
|
def find_spectral_components(
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
|
|
||||||
|
|
||||||
def qualify_slice_from_annotations(recording: Recording, slice_length: int):
|
def qualify_slice_from_annotations(recording: Recording, slice_length: int):
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy.signal import butter, lfilter
|
from scipy.signal import butter, lfilter
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.annotation import Annotation
|
from ria_toolkit_oss.data.annotation import Annotation
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
|
|
||||||
|
|
||||||
def isolate_signal(recording: Recording, annotation: Annotation) -> Recording:
|
def isolate_signal(recording: Recording, annotation: Annotation) -> Recording:
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ from typing import Optional
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Annotation, Recording
|
from ria_toolkit_oss.data import Annotation, Recording
|
||||||
|
|
||||||
|
|
||||||
def _find_ranges(indices, max_gap):
|
def _find_ranges(indices, max_gap):
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class Annotation:
|
||||||
|
|
||||||
def is_valid(self) -> bool:
|
def is_valid(self) -> bool:
|
||||||
"""
|
"""
|
||||||
Check that the annotation sample count is > 0 and the freq_lower_edge<freq_upper_edge.
|
Verify ``sample_count > 0`` and the ``freq_lower_edge < freq_upper_edge``.
|
||||||
|
|
||||||
:returns: True if valid, False if not.
|
:returns: True if valid, False if not.
|
||||||
"""
|
"""
|
||||||
|
|
@ -96,9 +96,9 @@ class Annotation:
|
||||||
def __eq__(self, other: Annotation) -> bool:
|
def __eq__(self, other: Annotation) -> bool:
|
||||||
return self.__dict__ == other.__dict__
|
return self.__dict__ == other.__dict__
|
||||||
|
|
||||||
def to_sigmf_format(self):
|
def to_sigmf_format(self) -> dict:
|
||||||
"""
|
"""
|
||||||
Returns a JSON dictionary representing this annotation formatted to be saved in a .sigmf-meta file.
|
Returns a JSON dictionary representation, formatted for saving in a ``.sigmf-meta`` file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
annotation_dict = {SigMFFile.START_INDEX_KEY: self.sample_start, SigMFFile.LENGTH_INDEX_KEY: self.sample_count}
|
annotation_dict = {SigMFFile.START_INDEX_KEY: self.sample_start, SigMFFile.LENGTH_INDEX_KEY: self.sample_count}
|
||||||
|
|
@ -119,7 +119,8 @@ class Annotation:
|
||||||
|
|
||||||
def _is_jsonable(x: Any) -> bool:
|
def _is_jsonable(x: Any) -> bool:
|
||||||
"""
|
"""
|
||||||
:return: True if x is JSON serializable, False otherwise.
|
:return: True if ``x`` is JSON serializable, False otherwise.
|
||||||
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
json.dumps(x)
|
json.dumps(x)
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ from typing import Any, Optional
|
||||||
|
|
||||||
from packaging.version import Version
|
from packaging.version import Version
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.datasets.license.dataset_license import DatasetLicense
|
from ria_toolkit_oss.data.datasets.license.dataset_license import DatasetLicense
|
||||||
from ria_toolkit_oss.datatypes.datasets.radio_dataset import RadioDataset
|
from ria_toolkit_oss.data.datasets.radio_dataset import RadioDataset
|
||||||
from ria_toolkit_oss.utils.abstract_attribute import abstract_attribute
|
from ria_toolkit_oss.utils.abstract_attribute import abstract_attribute
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -7,11 +7,11 @@ from typing import Optional
|
||||||
import h5py
|
import h5py
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.datasets.h5helpers import (
|
from ria_toolkit_oss.data.datasets.h5helpers import (
|
||||||
append_entry_inplace,
|
append_entry_inplace,
|
||||||
copy_dataset_entry_by_index,
|
copy_dataset_entry_by_index,
|
||||||
)
|
)
|
||||||
from ria_toolkit_oss.datatypes.datasets.radio_dataset import RadioDataset
|
from ria_toolkit_oss.data.datasets.radio_dataset import RadioDataset
|
||||||
|
|
||||||
|
|
||||||
class IQDataset(RadioDataset, ABC):
|
class IQDataset(RadioDataset, ABC):
|
||||||
|
|
@ -19,7 +19,7 @@ class IQDataset(RadioDataset, ABC):
|
||||||
radiofrequency (RF) signals represented as In-phase (I) and Quadrature (Q) samples.
|
radiofrequency (RF) signals represented as In-phase (I) and Quadrature (Q) samples.
|
||||||
|
|
||||||
For machine learning tasks that involve processing spectrograms, please use
|
For machine learning tasks that involve processing spectrograms, please use
|
||||||
ria_toolkit_oss.datatypes.datasets.SpectDataset instead.
|
ria_toolkit_oss.data.datasets.SpectDataset instead.
|
||||||
|
|
||||||
This is an abstract interface defining common properties and behaviour of IQDatasets. Therefore, this class
|
This is an abstract interface defining common properties and behaviour of IQDatasets. Therefore, this class
|
||||||
should not be instantiated directly. Instead, it is subclassed to define custom interfaces for specific machine
|
should not be instantiated directly. Instead, it is subclassed to define custom interfaces for specific machine
|
||||||
|
|
@ -12,7 +12,7 @@ import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from numpy.typing import ArrayLike
|
from numpy.typing import ArrayLike
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.datasets.h5helpers import (
|
from ria_toolkit_oss.data.datasets.h5helpers import (
|
||||||
append_entry_inplace,
|
append_entry_inplace,
|
||||||
copy_file,
|
copy_file,
|
||||||
copy_over_example,
|
copy_over_example,
|
||||||
|
|
@ -29,7 +29,7 @@ class RadioDataset(ABC):
|
||||||
|
|
||||||
This is an abstract interface defining common properties and behavior of radio datasets. Therefore, this class
|
This is an abstract interface defining common properties and behavior of radio datasets. Therefore, this class
|
||||||
should not be instantiated directly. Instead, it should be subclassed to define specific interfaces for different
|
should not be instantiated directly. Instead, it should be subclassed to define specific interfaces for different
|
||||||
types of radio datasets. For example, see ria_toolkit_oss.datatypes.datasets.IQDataset, which is a radio dataset
|
types of radio datasets. For example, see ria_toolkit_oss.data.datasets.IQDataset, which is a radio dataset
|
||||||
subclass tailored for tasks involving the processing of radio signals represented as IQ (In-phase and Quadrature)
|
subclass tailored for tasks involving the processing of radio signals represented as IQ (In-phase and Quadrature)
|
||||||
samples.
|
samples.
|
||||||
|
|
||||||
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
import os
|
import os
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.datasets.radio_dataset import RadioDataset
|
from ria_toolkit_oss.data.datasets.radio_dataset import RadioDataset
|
||||||
|
|
||||||
|
|
||||||
class SpectDataset(RadioDataset, ABC):
|
class SpectDataset(RadioDataset, ABC):
|
||||||
|
|
@ -13,7 +13,7 @@ class SpectDataset(RadioDataset, ABC):
|
||||||
radio signal spectrograms.
|
radio signal spectrograms.
|
||||||
|
|
||||||
For machine learning tasks that involve processing on IQ samples, please use
|
For machine learning tasks that involve processing on IQ samples, please use
|
||||||
ria_toolkit_oss.datatypes.datasets.IQDataset instead.
|
ria_toolkit_oss.data.datasets.IQDataset instead.
|
||||||
|
|
||||||
This is an abstract interface defining common properties and behaviour of IQDatasets. Therefore, this class
|
This is an abstract interface defining common properties and behaviour of IQDatasets. Therefore, this class
|
||||||
should not be instantiated directly. Instead, it is subclassed to define custom interfaces for specific machine
|
should not be instantiated directly. Instead, it is subclassed to define custom interfaces for specific machine
|
||||||
|
|
@ -6,11 +6,8 @@ from typing import Optional
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.random import Generator
|
from numpy.random import Generator
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.datasets import RadioDataset
|
from ria_toolkit_oss.data.datasets import RadioDataset
|
||||||
from ria_toolkit_oss.datatypes.datasets.h5helpers import (
|
from ria_toolkit_oss.data.datasets.h5helpers import copy_over_example, make_empty_clone
|
||||||
copy_over_example,
|
|
||||||
make_empty_clone,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def split(dataset: RadioDataset, lengths: list[int | float]) -> list[RadioDataset]:
|
def split(dataset: RadioDataset, lengths: list[int | float]) -> list[RadioDataset]:
|
||||||
|
|
@ -31,7 +28,7 @@ def split(dataset: RadioDataset, lengths: list[int | float]) -> list[RadioDatase
|
||||||
cases.
|
cases.
|
||||||
|
|
||||||
This function is deterministic, meaning it will always produce the same split. For a random split, see
|
This function is deterministic, meaning it will always produce the same split. For a random split, see
|
||||||
ria_toolkit_oss.datatypes.datasets.random_split.
|
ria_toolkit_oss.data.datasets.random_split.
|
||||||
|
|
||||||
:param dataset: Dataset to be split.
|
:param dataset: Dataset to be split.
|
||||||
:type dataset: RadioDataset
|
:type dataset: RadioDataset
|
||||||
|
|
@ -50,7 +47,7 @@ def split(dataset: RadioDataset, lengths: list[int | float]) -> list[RadioDatase
|
||||||
>>> import string
|
>>> import string
|
||||||
>>> import numpy as np
|
>>> import numpy as np
|
||||||
>>> import pandas as pd
|
>>> import pandas as pd
|
||||||
>>> from ria_toolkit_oss.datatypes.datasets import split
|
>>> from ria_toolkit_oss.data.datasets import split
|
||||||
|
|
||||||
First, let's generate some random data:
|
First, let's generate some random data:
|
||||||
|
|
||||||
|
|
@ -126,7 +123,7 @@ def random_split(
|
||||||
training and test datasets.
|
training and test datasets.
|
||||||
|
|
||||||
This restriction makes it unlikely that a random split will produce datasets with the exact lengths specified.
|
This restriction makes it unlikely that a random split will produce datasets with the exact lengths specified.
|
||||||
If it is important to ensure the closest possible split, consider using ria_toolkit_oss.datatypes.datasets.split
|
If it is important to ensure the closest possible split, consider using ria_toolkit_oss.data.datasets.split
|
||||||
instead.
|
instead.
|
||||||
|
|
||||||
:param dataset: Dataset to be split.
|
:param dataset: Dataset to be split.
|
||||||
|
|
@ -144,7 +141,7 @@ def random_split(
|
||||||
:rtype: list of RadioDataset
|
:rtype: list of RadioDataset
|
||||||
|
|
||||||
See Also:
|
See Also:
|
||||||
ria_toolkit_oss.datatypes.datasets.split: Usage is the same as for ``random_split()``.
|
ria_toolkit_oss.data.datasets.split: Usage is the same as for ``random_split()``.
|
||||||
"""
|
"""
|
||||||
if not isinstance(dataset, RadioDataset):
|
if not isinstance(dataset, RadioDataset):
|
||||||
raise ValueError(f"'dataset' must be RadioDataset or one of its subclasses, got {type(dataset)}.")
|
raise ValueError(f"'dataset' must be RadioDataset or one of its subclasses, got {type(dataset)}.")
|
||||||
|
|
@ -12,7 +12,7 @@ from typing import Any, Iterator, Optional
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.typing import ArrayLike
|
from numpy.typing import ArrayLike
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.annotation import Annotation
|
from ria_toolkit_oss.data.annotation import Annotation
|
||||||
|
|
||||||
PROTECTED_KEYS = ["rec_id", "timestamp"]
|
PROTECTED_KEYS = ["rec_id", "timestamp"]
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ class Recording:
|
||||||
Metadata is stored in a dictionary of key value pairs,
|
Metadata is stored in a dictionary of key value pairs,
|
||||||
to include information such as sample_rate and center_frequency.
|
to include information such as sample_rate and center_frequency.
|
||||||
|
|
||||||
Annotations are a list of :ref:`Annotation <utils.data.Annotation>`,
|
Annotations are a list of :class:`~ria_toolkit_oss.data.Annotation`,
|
||||||
defining bounding boxes in time and frequency with labels and metadata.
|
defining bounding boxes in time and frequency with labels and metadata.
|
||||||
|
|
||||||
Here, signal data is represented as a NumPy array. This class is then extended in the RIA Backends to provide
|
Here, signal data is represented as a NumPy array. This class is then extended in the RIA Backends to provide
|
||||||
|
|
@ -46,7 +46,7 @@ class Recording:
|
||||||
|
|
||||||
:param metadata: Additional information associated with the recording.
|
:param metadata: Additional information associated with the recording.
|
||||||
:type metadata: dict, optional
|
:type metadata: dict, optional
|
||||||
:param annotations: A collection of ``Annotation`` objects defining bounding boxes.
|
:param annotations: A collection of :class:`~ria_toolkit_oss.data.Annotation` objects defining bounding boxes.
|
||||||
:type annotations: list of Annotations, optional
|
:type annotations: list of Annotations, optional
|
||||||
|
|
||||||
:param dtype: Explicitly specify the data-type of the complex samples. Must be a complex NumPy type, such as
|
:param dtype: Explicitly specify the data-type of the complex samples. Must be a complex NumPy type, such as
|
||||||
|
|
@ -66,7 +66,7 @@ class Recording:
|
||||||
**Examples:**
|
**Examples:**
|
||||||
|
|
||||||
>>> import numpy
|
>>> import numpy
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording, Annotation
|
>>> from ria_toolkit_oss.data import Recording, Annotation
|
||||||
|
|
||||||
>>> # Create an array of complex samples, just 1s in this case.
|
>>> # Create an array of complex samples, just 1s in this case.
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
||||||
|
|
@ -146,7 +146,7 @@ class Recording:
|
||||||
self._metadata["timestamp"] = time.time()
|
self._metadata["timestamp"] = time.time()
|
||||||
else:
|
else:
|
||||||
if not isinstance(self._metadata["timestamp"], (int, float)):
|
if not isinstance(self._metadata["timestamp"], (int, float)):
|
||||||
raise ValueError("timestamp must be int or float, not ", type(self._metadata["timestamp"]))
|
raise ValueError(f"timestamp must be int or float, not {type(self._metadata['timestamp'])}")
|
||||||
|
|
||||||
if "rec_id" not in self.metadata:
|
if "rec_id" not in self.metadata:
|
||||||
self._metadata["rec_id"] = generate_recording_id(data=self.data, timestamp=self._metadata["timestamp"])
|
self._metadata["rec_id"] = generate_recording_id(data=self.data, timestamp=self._metadata["timestamp"])
|
||||||
|
|
@ -274,7 +274,13 @@ class Recording:
|
||||||
|
|
||||||
:return: A new recording with the same metadata and data, with dtype.
|
:return: A new recording with the same metadata and data, with dtype.
|
||||||
|
|
||||||
TODO: Add example usage.
|
|
||||||
|
**Examples:**
|
||||||
|
|
||||||
|
.. todo::
|
||||||
|
|
||||||
|
Usage examples coming soon!
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Rather than check for a valid datatype, let's cast and check the result. This makes it easier to provide
|
# Rather than check for a valid datatype, let's cast and check the result. This makes it easier to provide
|
||||||
# cross-platform support where the types are aliased across platforms.
|
# cross-platform support where the types are aliased across platforms.
|
||||||
|
|
@ -305,7 +311,7 @@ class Recording:
|
||||||
Create a recording and add metadata:
|
Create a recording and add metadata:
|
||||||
|
|
||||||
>>> import numpy
|
>>> import numpy
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording
|
>>> from ria_toolkit_oss.data import Recording
|
||||||
>>>
|
>>>
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
||||||
>>> metadata = {
|
>>> metadata = {
|
||||||
|
|
@ -360,7 +366,7 @@ class Recording:
|
||||||
Create a recording and update metadata:
|
Create a recording and update metadata:
|
||||||
|
|
||||||
>>> import numpy
|
>>> import numpy
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording
|
>>> from ria_toolkit_oss.data import Recording
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
||||||
>>> metadata = {
|
>>> metadata = {
|
||||||
|
|
@ -387,6 +393,7 @@ class Recording:
|
||||||
"""
|
"""
|
||||||
if key not in self.metadata:
|
if key not in self.metadata:
|
||||||
self.add_to_metadata(key=key, value=value)
|
self.add_to_metadata(key=key, value=value)
|
||||||
|
return
|
||||||
|
|
||||||
if not _is_jsonable(value):
|
if not _is_jsonable(value):
|
||||||
raise ValueError("Value must be JSON serializable.")
|
raise ValueError("Value must be JSON serializable.")
|
||||||
|
|
@ -414,7 +421,7 @@ class Recording:
|
||||||
Create a recording and add metadata:
|
Create a recording and add metadata:
|
||||||
|
|
||||||
>>> import numpy
|
>>> import numpy
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording
|
>>> from ria_toolkit_oss.data import Recording
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
||||||
>>> metadata = {
|
>>> metadata = {
|
||||||
|
|
@ -438,7 +445,7 @@ class Recording:
|
||||||
'rec_id': 'fda0f41...'} # Example value
|
'rec_id': 'fda0f41...'} # Example value
|
||||||
"""
|
"""
|
||||||
if key not in PROTECTED_KEYS:
|
if key not in PROTECTED_KEYS:
|
||||||
self._metadata.pop(key)
|
self._metadata.pop(key, None)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Key {key} is protected and cannot be modified or removed.")
|
raise ValueError(f"Key {key} is protected and cannot be modified or removed.")
|
||||||
|
|
||||||
|
|
@ -447,7 +454,7 @@ class Recording:
|
||||||
|
|
||||||
:param output_path: The output image path. Defaults to "images/signal.png".
|
:param output_path: The output image path. Defaults to "images/signal.png".
|
||||||
:type output_path: str, optional
|
:type output_path: str, optional
|
||||||
:param kwargs: Keyword arguments passed on to utils.view.view_sig.
|
:param kwargs: Keyword arguments passed on to ria_toolkit_oss.view.view_sig.
|
||||||
:type: dict of keyword arguments
|
:type: dict of keyword arguments
|
||||||
|
|
||||||
**Examples:**
|
**Examples:**
|
||||||
|
|
@ -455,7 +462,7 @@ class Recording:
|
||||||
Create a recording and view it as a plot in a .png image:
|
Create a recording and view it as a plot in a .png image:
|
||||||
|
|
||||||
>>> import numpy
|
>>> import numpy
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording
|
>>> from ria_toolkit_oss.data import Recording
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
||||||
>>> metadata = {
|
>>> metadata = {
|
||||||
|
|
@ -466,14 +473,14 @@ class Recording:
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
>>> recording = Recording(data=samples, metadata=metadata)
|
||||||
>>> recording.view()
|
>>> recording.view()
|
||||||
"""
|
"""
|
||||||
from ria_toolkit_oss.view import view_sig
|
from ria_toolkit_oss.view.view_signal import view_sig
|
||||||
|
|
||||||
view_sig(recording=self, output_path=output_path, **kwargs)
|
view_sig(recording=self, output_path=output_path, **kwargs)
|
||||||
|
|
||||||
def simple_view(self, **kwargs) -> None:
|
def simple_view(self, **kwargs) -> None:
|
||||||
"""Create a plot of various signal visualizations as a PNG or SVG image.
|
"""Create a plot of various signal visualizations as a PNG or SVG image.
|
||||||
|
|
||||||
:param kwargs: Keyword arguments passed on to ria_toolkit_oss.view.view_signal_simple.create_plots.
|
:param kwargs: Keyword arguments passed on to ria_toolkit_oss.view.view_signal_simple.view_simple_sig.
|
||||||
:type: dict of keyword arguments
|
:type: dict of keyword arguments
|
||||||
|
|
||||||
**Examples:**
|
**Examples:**
|
||||||
|
|
@ -481,7 +488,7 @@ class Recording:
|
||||||
Create a recording and view it as a plot in a .png image:
|
Create a recording and view it as a plot in a .png image:
|
||||||
|
|
||||||
>>> import numpy
|
>>> import numpy
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording
|
>>> from ria_toolkit_oss.data import Recording
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
||||||
>>> metadata = {
|
>>> metadata = {
|
||||||
|
|
@ -504,7 +511,7 @@ class Recording:
|
||||||
The SigMF io format is defined by the `SigMF Specification Project <https://github.com/sigmf/SigMF>`_
|
The SigMF io format is defined by the `SigMF Specification Project <https://github.com/sigmf/SigMF>`_
|
||||||
|
|
||||||
:param recording: The recording to be written to file.
|
:param recording: The recording to be written to file.
|
||||||
:type recording: utils.data.Recording
|
:type recording: ria_toolkit_oss.data.Recording
|
||||||
:param filename: The name of the file where the recording is to be saved. Defaults to auto generated filename.
|
:param filename: The name of the file where the recording is to be saved. Defaults to auto generated filename.
|
||||||
:type filename: os.PathLike or str, optional
|
:type filename: os.PathLike or str, optional
|
||||||
:param path: The directory path to where the recording is to be saved. Defaults to recordings/.
|
:param path: The directory path to where the recording is to be saved. Defaults to recordings/.
|
||||||
|
|
@ -513,22 +520,6 @@ class Recording:
|
||||||
:raises IOError: If there is an issue encountered during the file writing process.
|
:raises IOError: If there is an issue encountered during the file writing process.
|
||||||
|
|
||||||
:return: None
|
:return: None
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Create a recording and view it as a plot in a `.png` image:
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from utils.data import Recording
|
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
|
||||||
>>> metadata = {
|
|
||||||
... "sample_rate": 1e6,
|
|
||||||
... "center_frequency": 2.44e9,
|
|
||||||
... }
|
|
||||||
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
|
||||||
>>> recording.view()
|
|
||||||
"""
|
"""
|
||||||
from ria_toolkit_oss.io.recording import to_sigmf
|
from ria_toolkit_oss.io.recording import to_sigmf
|
||||||
|
|
||||||
|
|
@ -554,7 +545,7 @@ class Recording:
|
||||||
Create a recording and save it to a .npy file:
|
Create a recording and save it to a .npy file:
|
||||||
|
|
||||||
>>> import numpy
|
>>> import numpy
|
||||||
>>> from utils.data import Recording
|
>>> from ria_toolkit_oss.data import Recording
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
||||||
>>> metadata = {
|
>>> metadata = {
|
||||||
|
|
@ -605,7 +596,7 @@ class Recording:
|
||||||
Create a recording and save it to a .wav file:
|
Create a recording and save it to a .wav file:
|
||||||
|
|
||||||
>>> import numpy
|
>>> import numpy
|
||||||
>>> from utils.data import Recording
|
>>> from ria_toolkit_oss.data import Recording
|
||||||
>>> samples = numpy.exp(1j * 2 * numpy.pi * 0.1 * numpy.arange(10000))
|
>>> samples = numpy.exp(1j * 2 * numpy.pi * 0.1 * numpy.arange(10000))
|
||||||
>>> metadata = {"sample_rate": 1e6, "center_frequency": 915e6}
|
>>> metadata = {"sample_rate": 1e6, "center_frequency": 915e6}
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
>>> recording = Recording(data=samples, metadata=metadata)
|
||||||
|
|
@ -655,7 +646,7 @@ class Recording:
|
||||||
Create a recording and save it to a .blue file:
|
Create a recording and save it to a .blue file:
|
||||||
|
|
||||||
>>> import numpy
|
>>> import numpy
|
||||||
>>> from utils.data import Recording
|
>>> from ria_toolkit_oss.data import Recording
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
||||||
>>> metadata = {"sample_rate": 1e6, "center_frequency": 2.44e9}
|
>>> metadata = {"sample_rate": 1e6, "center_frequency": 2.44e9}
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
>>> recording = Recording(data=samples, metadata=metadata)
|
||||||
|
|
@ -668,36 +659,36 @@ class Recording:
|
||||||
def trim(self, num_samples: int, start_sample: Optional[int] = 0) -> Recording:
|
def trim(self, num_samples: int, start_sample: Optional[int] = 0) -> Recording:
|
||||||
"""Trim Recording samples to a desired length, shifting annotations to maintain alignment.
|
"""Trim Recording samples to a desired length, shifting annotations to maintain alignment.
|
||||||
|
|
||||||
:param start_sample: The start index of the desired trimmed recording. Defaults to 0.
|
:param start_sample: The start index of the desired trimmed recording. Defaults to 0.
|
||||||
:type start_sample: int, optional
|
:type start_sample: int, optional
|
||||||
:param num_samples: The number of samples that the output trimmed recording will have.
|
:param num_samples: The number of samples that the output trimmed recording will have.
|
||||||
:type num_samples: int
|
:type num_samples: int
|
||||||
:raises IndexError: If start_sample + num_samples is greater than the length of the recording.
|
:raises IndexError: If start_sample + num_samples is greater than the length of the recording.
|
||||||
:raises IndexError: If sample_start < 0 or num_samples < 0.
|
:raises IndexError: If sample_start < 0 or num_samples < 0.
|
||||||
|
|
||||||
:return: The trimmed Recording.
|
:return: The trimmed Recording.
|
||||||
:rtype: Recording
|
:rtype: Recording
|
||||||
|
|
||||||
**Examples:**
|
**Examples:**
|
||||||
|
|
||||||
Create a recording and trim it:
|
Create a recording and trim it:
|
||||||
|
|
||||||
>>> import numpy
|
>>> import numpy
|
||||||
>>> from utils.data import Recording
|
>>> from ria_toolkit_oss.data import Recording
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
||||||
>>> metadata = {
|
>>> metadata = {
|
||||||
... "sample_rate": 1e6,
|
... "sample_rate": 1e6,
|
||||||
... "center_frequency": 2.44e9,
|
... "center_frequency": 2.44e9,
|
||||||
... }
|
... }
|
||||||
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
>>> recording = Recording(data=samples, metadata=metadata)
|
||||||
>>> print(len(recording))
|
>>> print(len(recording))
|
||||||
10000
|
10000
|
||||||
|
|
||||||
>>> trimmed_recording = recording.trim(start_sample=1000, num_samples=1000)
|
>>> trimmed_recording = recording.trim(start_sample=1000, num_samples=1000)
|
||||||
>>> print(len(trimmed_recording))
|
>>> print(len(trimmed_recording))
|
||||||
1000
|
1000
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if start_sample < 0:
|
if start_sample < 0:
|
||||||
|
|
@ -712,7 +703,14 @@ class Recording:
|
||||||
data = self.data[:, start_sample:end_sample]
|
data = self.data[:, start_sample:end_sample]
|
||||||
|
|
||||||
new_annotations = copy.deepcopy(self.annotations)
|
new_annotations = copy.deepcopy(self.annotations)
|
||||||
|
trimmed_annotations = []
|
||||||
for annotation in new_annotations:
|
for annotation in new_annotations:
|
||||||
|
# skip annotations entirely outside the trim window
|
||||||
|
if annotation.sample_start + annotation.sample_count <= start_sample:
|
||||||
|
continue
|
||||||
|
if annotation.sample_start >= end_sample:
|
||||||
|
continue
|
||||||
|
|
||||||
# trim annotation if it goes outside the trim boundaries
|
# trim annotation if it goes outside the trim boundaries
|
||||||
if annotation.sample_start < start_sample:
|
if annotation.sample_start < start_sample:
|
||||||
annotation.sample_count = annotation.sample_count - (start_sample - annotation.sample_start)
|
annotation.sample_count = annotation.sample_count - (start_sample - annotation.sample_start)
|
||||||
|
|
@ -723,8 +721,9 @@ class Recording:
|
||||||
|
|
||||||
# shift annotation to align with the new start point
|
# shift annotation to align with the new start point
|
||||||
annotation.sample_start = annotation.sample_start - start_sample
|
annotation.sample_start = annotation.sample_start - start_sample
|
||||||
|
trimmed_annotations.append(annotation)
|
||||||
|
|
||||||
return Recording(data=data, metadata=self.metadata, annotations=new_annotations)
|
return Recording(data=data, metadata=self.metadata, annotations=trimmed_annotations)
|
||||||
|
|
||||||
def normalize(self) -> Recording:
|
def normalize(self) -> Recording:
|
||||||
"""Scale the recording data, relative to its maximum value, so that the magnitude of the maximum sample is 1.
|
"""Scale the recording data, relative to its maximum value, so that the magnitude of the maximum sample is 1.
|
||||||
|
|
@ -737,7 +736,7 @@ class Recording:
|
||||||
Create a recording with maximum amplitude 0.5 and normalize to a maximum amplitude of 1:
|
Create a recording with maximum amplitude 0.5 and normalize to a maximum amplitude of 1:
|
||||||
|
|
||||||
>>> import numpy
|
>>> import numpy
|
||||||
>>> from utils.data import Recording
|
>>> from ria_toolkit_oss.data import Recording
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64) * 0.5
|
>>> samples = numpy.ones(10000, dtype=numpy.complex64) * 0.5
|
||||||
>>> metadata = {
|
>>> metadata = {
|
||||||
|
|
@ -753,7 +752,10 @@ class Recording:
|
||||||
>>> print(numpy.max(numpy.abs(normalized_recording.data)))
|
>>> print(numpy.max(numpy.abs(normalized_recording.data)))
|
||||||
1
|
1
|
||||||
"""
|
"""
|
||||||
scaled_data = self.data / np.max(abs(self.data))
|
max_val = np.max(abs(self.data))
|
||||||
|
if max_val == 0:
|
||||||
|
raise ValueError("Cannot normalize a recording with all-zero data.")
|
||||||
|
scaled_data = self.data / max_val
|
||||||
return Recording(data=scaled_data, metadata=self.metadata, annotations=self.annotations)
|
return Recording(data=scaled_data, metadata=self.metadata, annotations=self.annotations)
|
||||||
|
|
||||||
def __len__(self) -> int:
|
def __len__(self) -> int:
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
"""
|
|
||||||
The datatypes package contains abstract data types tailored for radio machine learning.
|
|
||||||
"""
|
|
||||||
|
|
||||||
__all__ = ["Annotation", "Recording"]
|
|
||||||
|
|
||||||
from .annotation import Annotation
|
|
||||||
from .recording import Recording
|
|
||||||
|
|
@ -1,129 +0,0 @@
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import json
|
|
||||||
from typing import Any, Optional
|
|
||||||
|
|
||||||
from sigmf import SigMFFile
|
|
||||||
|
|
||||||
|
|
||||||
class Annotation:
|
|
||||||
"""Signal annotations are labels or additional information associated with specific data points or segments within
|
|
||||||
a signal. These annotations could be used for tasks like supervised learning, where the goal is to train a model
|
|
||||||
to recognize patterns or characteristics in the signal associated with these annotations.
|
|
||||||
|
|
||||||
Annotations can be used to label interesting points in your recording.
|
|
||||||
|
|
||||||
:param sample_start: The index of the starting sample of the annotation.
|
|
||||||
:type sample_start: int
|
|
||||||
:param sample_count: The index of the ending sample of the annotation, inclusive.
|
|
||||||
:type sample_count: int
|
|
||||||
:param freq_lower_edge: The lower frequency of the annotation.
|
|
||||||
:type freq_lower_edge: float
|
|
||||||
:param freq_upper_edge: The upper frequency of the annotation.
|
|
||||||
:type freq_upper_edge: float
|
|
||||||
:param label: The label that will be displayed with the bounding box in compatible viewers including IQEngine.
|
|
||||||
Defaults to an emtpy string.
|
|
||||||
:type label: str, optional
|
|
||||||
:param comment: A human-readable comment. Defaults to an empty string.
|
|
||||||
:type comment: str, optional
|
|
||||||
:param detail: A dictionary of user defined annotation-specific metadata. Defaults to None.
|
|
||||||
:type detail: dict, optional
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
sample_start: int,
|
|
||||||
sample_count: int,
|
|
||||||
freq_lower_edge: float,
|
|
||||||
freq_upper_edge: float,
|
|
||||||
label: Optional[str] = "",
|
|
||||||
comment: Optional[str] = "",
|
|
||||||
detail: Optional[dict] = None,
|
|
||||||
):
|
|
||||||
"""Initialize a new Annotation instance."""
|
|
||||||
self.sample_start = int(sample_start)
|
|
||||||
self.sample_count = int(sample_count)
|
|
||||||
self.freq_lower_edge = float(freq_lower_edge)
|
|
||||||
self.freq_upper_edge = float(freq_upper_edge)
|
|
||||||
self.label = str(label)
|
|
||||||
self.comment = str(comment)
|
|
||||||
|
|
||||||
if detail is None:
|
|
||||||
self.detail = {}
|
|
||||||
elif not _is_jsonable(detail):
|
|
||||||
raise ValueError(f"Detail object is not json serializable: {detail}")
|
|
||||||
else:
|
|
||||||
self.detail = detail
|
|
||||||
|
|
||||||
def is_valid(self) -> bool:
|
|
||||||
"""
|
|
||||||
Verify ``sample_count > 0`` and the ``freq_lower_edge < freq_upper_edge``.
|
|
||||||
|
|
||||||
:returns: True if valid, False if not.
|
|
||||||
"""
|
|
||||||
|
|
||||||
return self.sample_count > 0 and self.freq_lower_edge < self.freq_upper_edge
|
|
||||||
|
|
||||||
def overlap(self, other):
|
|
||||||
"""
|
|
||||||
Quantify how much the bounding box in this annotation overlaps with another annotation.
|
|
||||||
|
|
||||||
:param other: The other annotation.
|
|
||||||
:type other: Annotation
|
|
||||||
|
|
||||||
:returns: The area of the overlap in samples*frequency, or 0 if they do not overlap."""
|
|
||||||
|
|
||||||
sample_overlap_start = max(self.sample_start, other.sample_start)
|
|
||||||
sample_overlap_end = min(self.sample_start + self.sample_count, other.sample_start + other.sample_count)
|
|
||||||
|
|
||||||
freq_overlap_start = max(self.freq_lower_edge, other.freq_lower_edge)
|
|
||||||
freq_overlap_end = min(self.freq_upper_edge, other.freq_upper_edge)
|
|
||||||
|
|
||||||
if freq_overlap_start >= freq_overlap_end or sample_overlap_start >= sample_overlap_end:
|
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
return (sample_overlap_end - sample_overlap_start) * (freq_overlap_end - freq_overlap_start)
|
|
||||||
|
|
||||||
def area(self):
|
|
||||||
"""
|
|
||||||
The 'area' of the bounding box, samples*frequency.
|
|
||||||
Useful to quantify annotation size.
|
|
||||||
|
|
||||||
:returns: sample length multiplied by bandwidth."""
|
|
||||||
|
|
||||||
return self.sample_count * (self.freq_upper_edge - self.freq_lower_edge)
|
|
||||||
|
|
||||||
def __eq__(self, other: Annotation) -> bool:
|
|
||||||
return self.__dict__ == other.__dict__
|
|
||||||
|
|
||||||
def to_sigmf_format(self) -> dict:
|
|
||||||
"""
|
|
||||||
Returns a JSON dictionary representation, formatted for saving in a ``.sigmf-meta`` file.
|
|
||||||
"""
|
|
||||||
|
|
||||||
annotation_dict = {SigMFFile.START_INDEX_KEY: self.sample_start, SigMFFile.LENGTH_INDEX_KEY: self.sample_count}
|
|
||||||
|
|
||||||
annotation_dict["metadata"] = {
|
|
||||||
SigMFFile.LABEL_KEY: self.label,
|
|
||||||
SigMFFile.COMMENT_KEY: self.comment,
|
|
||||||
SigMFFile.FHI_KEY: self.freq_upper_edge,
|
|
||||||
SigMFFile.FLO_KEY: self.freq_lower_edge,
|
|
||||||
"ria:detail": self.detail,
|
|
||||||
}
|
|
||||||
|
|
||||||
if _is_jsonable(annotation_dict):
|
|
||||||
return annotation_dict
|
|
||||||
else:
|
|
||||||
raise ValueError("Annotation dictionary was not json serializable.")
|
|
||||||
|
|
||||||
|
|
||||||
def _is_jsonable(x: Any) -> bool:
|
|
||||||
"""
|
|
||||||
:return: True if ``x`` is JSON serializable, False otherwise.
|
|
||||||
:rtype: bool
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
json.dumps(x)
|
|
||||||
return True
|
|
||||||
except (TypeError, OverflowError):
|
|
||||||
return False
|
|
||||||
|
|
@ -1,855 +0,0 @@
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import copy
|
|
||||||
import hashlib
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import time
|
|
||||||
import warnings
|
|
||||||
from typing import Any, Iterator, Optional
|
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
from numpy.typing import ArrayLike
|
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.annotation import Annotation
|
|
||||||
|
|
||||||
PROTECTED_KEYS = ["rec_id", "timestamp"]
|
|
||||||
|
|
||||||
|
|
||||||
class Recording:
|
|
||||||
"""Tape of complex IQ (in-phase and quadrature) samples with associated metadata and annotations.
|
|
||||||
|
|
||||||
Recording data is a complex array of shape C x N, where C is the number of channels
|
|
||||||
and N is the number of samples in each channel.
|
|
||||||
|
|
||||||
Metadata is stored in a dictionary of key value pairs,
|
|
||||||
to include information such as sample_rate and center_frequency.
|
|
||||||
|
|
||||||
Annotations are a list of :class:`~ria_toolkit_oss.datatypes.Annotation`,
|
|
||||||
defining bounding boxes in time and frequency with labels and metadata.
|
|
||||||
|
|
||||||
Here, signal data is represented as a NumPy array. This class is then extended in the RIA Backends to provide
|
|
||||||
support for different data structures, such as Tensors.
|
|
||||||
|
|
||||||
Recordings are long-form tapes can be obtained either from a software-defined radio (SDR) or generated
|
|
||||||
synthetically. Then, machine learning datasets are curated from collection of recordings by segmenting these
|
|
||||||
longer-form tapes into shorter units called slices.
|
|
||||||
|
|
||||||
All recordings are assigned a unique 64-character recording ID, ``rec_id``. If this field is missing from the
|
|
||||||
provided metadata, a new ID will be generated upon object instantiation.
|
|
||||||
|
|
||||||
:param data: Signal data as a tape IQ samples, either C x N complex, where C is the number of
|
|
||||||
channels and N is number of samples in the signal. If data is a one-dimensional array of complex samples with
|
|
||||||
length N, it will be reshaped to a two-dimensional array with dimensions 1 x N.
|
|
||||||
:type data: array_like
|
|
||||||
|
|
||||||
:param metadata: Additional information associated with the recording.
|
|
||||||
:type metadata: dict, optional
|
|
||||||
:param annotations: A collection of :class:`~ria_toolkit_oss.datatypes.Annotation` objects defining bounding boxes.
|
|
||||||
:type annotations: list of Annotations, optional
|
|
||||||
|
|
||||||
:param dtype: Explicitly specify the data-type of the complex samples. Must be a complex NumPy type, such as
|
|
||||||
``np.complex64`` or ``np.complex128``. Default is None, in which case the type is determined implicitly. If
|
|
||||||
``data`` is a NumPy array, the Recording will use the dtype of ``data`` directly without any conversion.
|
|
||||||
:type dtype: numpy dtype object, optional
|
|
||||||
:param timestamp: The timestamp when the recording data was generated. If provided, it should be a float or integer
|
|
||||||
representing the time in seconds since epoch (e.g., ``time.time()``). Only used if the `timestamp` field is not
|
|
||||||
present in the provided metadata.
|
|
||||||
:type dtype: float or int, optional
|
|
||||||
|
|
||||||
:raises ValueError: If data is not complex 1xN or CxN.
|
|
||||||
:raises ValueError: If metadata is not a python dict.
|
|
||||||
:raises ValueError: If metadata is not json serializable.
|
|
||||||
:raises ValueError: If annotations is not a list of valid annotation objects.
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording, Annotation
|
|
||||||
|
|
||||||
>>> # Create an array of complex samples, just 1s in this case.
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
|
||||||
|
|
||||||
>>> # Create a dictionary of relevant metadata.
|
|
||||||
>>> sample_rate = 1e6
|
|
||||||
>>> center_frequency = 2.44e9
|
|
||||||
>>> metadata = {
|
|
||||||
... "sample_rate": sample_rate,
|
|
||||||
... "center_frequency": center_frequency,
|
|
||||||
... "author": "me",
|
|
||||||
... }
|
|
||||||
|
|
||||||
>>> # Create an annotation for the annotations list.
|
|
||||||
>>> annotations = [
|
|
||||||
... Annotation(
|
|
||||||
... sample_start=0,
|
|
||||||
... sample_count=1000,
|
|
||||||
... freq_lower_edge=center_frequency - (sample_rate / 2),
|
|
||||||
... freq_upper_edge=center_frequency + (sample_rate / 2),
|
|
||||||
... label="example",
|
|
||||||
... )
|
|
||||||
... ]
|
|
||||||
|
|
||||||
>>> # Store samples, metadata, and annotations together in a convenient object.
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata, annotations=annotations)
|
|
||||||
>>> print(recording.metadata)
|
|
||||||
{'sample_rate': 1000000.0, 'center_frequency': 2440000000.0, 'author': 'me'}
|
|
||||||
>>> print(recording.annotations[0].label)
|
|
||||||
'example'
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__( # noqa C901
|
|
||||||
self,
|
|
||||||
data: ArrayLike | list[list],
|
|
||||||
metadata: Optional[dict[str, any]] = None,
|
|
||||||
dtype: Optional[np.dtype] = None,
|
|
||||||
timestamp: Optional[float | int] = None,
|
|
||||||
annotations: Optional[list[Annotation]] = None,
|
|
||||||
):
|
|
||||||
|
|
||||||
data_arr = np.asarray(data)
|
|
||||||
|
|
||||||
if np.iscomplexobj(data_arr):
|
|
||||||
# Expect C x N
|
|
||||||
if data_arr.ndim == 1:
|
|
||||||
self._data = np.expand_dims(data_arr, axis=0) # N -> 1 x N
|
|
||||||
elif data_arr.ndim == 2:
|
|
||||||
self._data = data_arr
|
|
||||||
else:
|
|
||||||
raise ValueError("Complex data must be C x N.")
|
|
||||||
|
|
||||||
else:
|
|
||||||
raise ValueError("Input data must be complex.")
|
|
||||||
|
|
||||||
if dtype is not None:
|
|
||||||
self._data = self._data.astype(dtype)
|
|
||||||
|
|
||||||
assert np.iscomplexobj(self._data)
|
|
||||||
|
|
||||||
if metadata is None:
|
|
||||||
self._metadata = {}
|
|
||||||
elif isinstance(metadata, dict):
|
|
||||||
self._metadata = metadata
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Metadata must be a python dict, but was {type(metadata)}.")
|
|
||||||
|
|
||||||
if not _is_jsonable(metadata):
|
|
||||||
raise ValueError("Value must be JSON serializable.")
|
|
||||||
|
|
||||||
if "timestamp" not in self.metadata:
|
|
||||||
if timestamp is not None:
|
|
||||||
if not isinstance(timestamp, (int, float)):
|
|
||||||
raise ValueError(f"timestamp must be int or float, not {type(timestamp)}")
|
|
||||||
self._metadata["timestamp"] = timestamp
|
|
||||||
else:
|
|
||||||
self._metadata["timestamp"] = time.time()
|
|
||||||
else:
|
|
||||||
if not isinstance(self._metadata["timestamp"], (int, float)):
|
|
||||||
raise ValueError(f"timestamp must be int or float, not {type(self._metadata['timestamp'])}")
|
|
||||||
|
|
||||||
if "rec_id" not in self.metadata:
|
|
||||||
self._metadata["rec_id"] = generate_recording_id(data=self.data, timestamp=self._metadata["timestamp"])
|
|
||||||
|
|
||||||
if annotations is None:
|
|
||||||
self._annotations = []
|
|
||||||
elif isinstance(annotations, list):
|
|
||||||
self._annotations = annotations
|
|
||||||
else:
|
|
||||||
raise ValueError("Annotations must be a list or None.")
|
|
||||||
|
|
||||||
if not all(isinstance(annotation, Annotation) for annotation in self._annotations):
|
|
||||||
raise ValueError("All elements in self._annotations must be of type Annotation.")
|
|
||||||
|
|
||||||
self._index = 0
|
|
||||||
|
|
||||||
@property
|
|
||||||
def data(self) -> np.ndarray:
|
|
||||||
"""
|
|
||||||
:return: Recording data, as a complex array.
|
|
||||||
:type: np.ndarray
|
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
For recordings with more than 1,024 samples, this property returns a read-only view of the data.
|
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
To access specific samples, consider indexing the object directly with ``rec[c, n]``.
|
|
||||||
"""
|
|
||||||
if self._data.size > 1024:
|
|
||||||
# Returning a read-only view prevents mutation at a distance while maintaining performance.
|
|
||||||
v = self._data.view()
|
|
||||||
v.setflags(write=False)
|
|
||||||
return v
|
|
||||||
else:
|
|
||||||
return self._data.copy()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def metadata(self) -> dict:
|
|
||||||
"""
|
|
||||||
:return: Dictionary of recording metadata.
|
|
||||||
:type: dict
|
|
||||||
"""
|
|
||||||
return self._metadata.copy()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def annotations(self) -> list[Annotation]:
|
|
||||||
"""
|
|
||||||
:return: List of recording annotations
|
|
||||||
:type: list of Annotation objects
|
|
||||||
"""
|
|
||||||
return self._annotations.copy()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def shape(self) -> tuple[int]:
|
|
||||||
"""
|
|
||||||
:return: The shape of the data array.
|
|
||||||
:type: tuple of ints
|
|
||||||
"""
|
|
||||||
return np.shape(self.data)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def n_chan(self) -> int:
|
|
||||||
"""
|
|
||||||
:return: The number of channels in the recording.
|
|
||||||
:type: int
|
|
||||||
"""
|
|
||||||
return self.shape[0]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def rec_id(self) -> str:
|
|
||||||
"""
|
|
||||||
:return: Recording ID.
|
|
||||||
:type: str
|
|
||||||
"""
|
|
||||||
return self.metadata["rec_id"]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def dtype(self) -> str:
|
|
||||||
"""
|
|
||||||
:return: Data-type of the data array's elements.
|
|
||||||
:type: numpy dtype object
|
|
||||||
"""
|
|
||||||
return self.data.dtype
|
|
||||||
|
|
||||||
@property
|
|
||||||
def timestamp(self) -> float | int:
|
|
||||||
"""
|
|
||||||
:return: Recording timestamp (time in seconds since epoch).
|
|
||||||
:type: float or int
|
|
||||||
"""
|
|
||||||
return self.metadata["timestamp"]
|
|
||||||
|
|
||||||
@property
|
|
||||||
def sample_rate(self) -> float | None:
|
|
||||||
"""
|
|
||||||
:return: Sample rate of the recording, or None is 'sample_rate' is not in metadata.
|
|
||||||
:type: str
|
|
||||||
"""
|
|
||||||
return self.metadata.get("sample_rate")
|
|
||||||
|
|
||||||
@sample_rate.setter
|
|
||||||
def sample_rate(self, sample_rate: float | int) -> None:
|
|
||||||
"""Set the sample rate of the recording.
|
|
||||||
|
|
||||||
:param sample_rate: The sample rate of the recording.
|
|
||||||
:type sample_rate: float or int
|
|
||||||
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self.add_to_metadata(key="sample_rate", value=sample_rate)
|
|
||||||
|
|
||||||
def astype(self, dtype: np.dtype) -> Recording:
|
|
||||||
"""Copy of the recording, data cast to a specified type.
|
|
||||||
|
|
||||||
.. todo: This method is not yet implemented.
|
|
||||||
|
|
||||||
:param dtype: Data-type to which the array is cast. Must be a complex scalar type, such as ``np.complex64`` or
|
|
||||||
``np.complex128``.
|
|
||||||
:type dtype: NumPy data type, optional
|
|
||||||
|
|
||||||
.. note: Casting to a data type with less precision can risk losing data by truncating or rounding values,
|
|
||||||
potentially resulting in a loss of accuracy and significant information.
|
|
||||||
|
|
||||||
:return: A new recording with the same metadata and data, with dtype.
|
|
||||||
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
.. todo::
|
|
||||||
|
|
||||||
Usage examples coming soon!
|
|
||||||
|
|
||||||
"""
|
|
||||||
# Rather than check for a valid datatype, let's cast and check the result. This makes it easier to provide
|
|
||||||
# cross-platform support where the types are aliased across platforms.
|
|
||||||
with warnings.catch_warnings():
|
|
||||||
warnings.simplefilter("ignore") # Casting may generate user warnings. E.g., complex -> real
|
|
||||||
data = self.data.astype(dtype)
|
|
||||||
|
|
||||||
if np.iscomplexobj(data):
|
|
||||||
return Recording(data=data, metadata=self.metadata, annotations=self.annotations)
|
|
||||||
else:
|
|
||||||
raise ValueError("dtype must be a complex number scalar type.")
|
|
||||||
|
|
||||||
def add_to_metadata(self, key: str, value: Any) -> None:
|
|
||||||
"""Add a new key-value pair to the recording metadata.
|
|
||||||
|
|
||||||
:param key: New metadata key, must be snake_case.
|
|
||||||
:type key: str
|
|
||||||
:param value: Corresponding metadata value.
|
|
||||||
:type value: any
|
|
||||||
|
|
||||||
:raises ValueError: If key is already in metadata or if key is not a valid metadata key.
|
|
||||||
:raises ValueError: If value is not JSON serializable.
|
|
||||||
|
|
||||||
:return: None.
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Create a recording and add metadata:
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording
|
|
||||||
>>>
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
|
||||||
>>> metadata = {
|
|
||||||
>>> "sample_rate": 1e6,
|
|
||||||
>>> "center_frequency": 2.44e9,
|
|
||||||
>>> }
|
|
||||||
>>>
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
|
||||||
>>> print(recording.metadata)
|
|
||||||
{'sample_rate': 1000000.0,
|
|
||||||
'center_frequency': 2440000000.0,
|
|
||||||
'timestamp': 17369...,
|
|
||||||
'rec_id': 'fda0f41...'}
|
|
||||||
>>>
|
|
||||||
>>> recording.add_to_metadata(key="author", value="me")
|
|
||||||
>>> print(recording.metadata)
|
|
||||||
{'sample_rate': 1000000.0,
|
|
||||||
'center_frequency': 2440000000.0,
|
|
||||||
'author': 'me',
|
|
||||||
'timestamp': 17369...,
|
|
||||||
'rec_id': 'fda0f41...'}
|
|
||||||
"""
|
|
||||||
if key in self.metadata:
|
|
||||||
raise ValueError(
|
|
||||||
f"Key {key} already in metadata. Use Recording.update_metadata() to modify existing fields."
|
|
||||||
)
|
|
||||||
|
|
||||||
if not _is_valid_metadata_key(key):
|
|
||||||
raise ValueError(f"Invalid metadata key: {key}.")
|
|
||||||
|
|
||||||
if not _is_jsonable(value):
|
|
||||||
raise ValueError("Value must be JSON serializable.")
|
|
||||||
|
|
||||||
self._metadata[key] = value
|
|
||||||
|
|
||||||
def update_metadata(self, key: str, value: Any) -> None:
|
|
||||||
"""Update the value of an existing metadata key,
|
|
||||||
or add the key value pair if it does not already exist.
|
|
||||||
|
|
||||||
:param key: Existing metadata key.
|
|
||||||
:type key: str
|
|
||||||
:param value: New value to enter at key.
|
|
||||||
:type value: any
|
|
||||||
|
|
||||||
:raises ValueError: If value is not JSON serializable
|
|
||||||
:raises ValueError: If key is protected.
|
|
||||||
|
|
||||||
:return: None.
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Create a recording and update metadata:
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording
|
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
|
||||||
>>> metadata = {
|
|
||||||
>>> "sample_rate": 1e6,
|
|
||||||
>>> "center_frequency": 2.44e9,
|
|
||||||
>>> "author": "me"
|
|
||||||
>>> }
|
|
||||||
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
|
||||||
>>> print(recording.metadata)
|
|
||||||
{'sample_rate': 1000000.0,
|
|
||||||
'center_frequency': 2440000000.0,
|
|
||||||
'author': "me",
|
|
||||||
'timestamp': 17369...
|
|
||||||
'rec_id': 'fda0f41...'}
|
|
||||||
|
|
||||||
>>> recording.update_metadata(key="author", value=you")
|
|
||||||
>>> print(recording.metadata)
|
|
||||||
{'sample_rate': 1000000.0,
|
|
||||||
'center_frequency': 2440000000.0,
|
|
||||||
'author': "you",
|
|
||||||
'timestamp': 17369...
|
|
||||||
'rec_id': 'fda0f41...'}
|
|
||||||
"""
|
|
||||||
if key not in self.metadata:
|
|
||||||
self.add_to_metadata(key=key, value=value)
|
|
||||||
return
|
|
||||||
|
|
||||||
if not _is_jsonable(value):
|
|
||||||
raise ValueError("Value must be JSON serializable.")
|
|
||||||
|
|
||||||
if key in PROTECTED_KEYS: # Check protected keys.
|
|
||||||
raise ValueError(f"Key {key} is protected and cannot be modified or removed.")
|
|
||||||
|
|
||||||
else:
|
|
||||||
self._metadata[key] = value
|
|
||||||
|
|
||||||
def remove_from_metadata(self, key: str):
|
|
||||||
"""
|
|
||||||
Remove a key from the recording metadata.
|
|
||||||
Does not remove key if it is protected.
|
|
||||||
|
|
||||||
:param key: The key to remove.
|
|
||||||
:type key: str
|
|
||||||
|
|
||||||
:raises ValueError: If key is protected.
|
|
||||||
|
|
||||||
:return: None.
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Create a recording and add metadata:
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording
|
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
|
||||||
>>> metadata = {
|
|
||||||
... "sample_rate": 1e6,
|
|
||||||
... "center_frequency": 2.44e9,
|
|
||||||
... }
|
|
||||||
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
|
||||||
>>> print(recording.metadata)
|
|
||||||
{'sample_rate': 1000000.0,
|
|
||||||
'center_frequency': 2440000000.0,
|
|
||||||
'timestamp': 17369..., # Example value
|
|
||||||
'rec_id': 'fda0f41...'} # Example value
|
|
||||||
|
|
||||||
>>> recording.add_to_metadata(key="author", value="me")
|
|
||||||
>>> print(recording.metadata)
|
|
||||||
{'sample_rate': 1000000.0,
|
|
||||||
'center_frequency': 2440000000.0,
|
|
||||||
'author': 'me',
|
|
||||||
'timestamp': 17369..., # Example value
|
|
||||||
'rec_id': 'fda0f41...'} # Example value
|
|
||||||
"""
|
|
||||||
if key not in PROTECTED_KEYS:
|
|
||||||
self._metadata.pop(key, None)
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Key {key} is protected and cannot be modified or removed.")
|
|
||||||
|
|
||||||
def view(self, output_path: Optional[str] = "images/signal.png", **kwargs) -> None:
|
|
||||||
"""Create a plot of various signal visualizations as a PNG image.
|
|
||||||
|
|
||||||
:param output_path: The output image path. Defaults to "images/signal.png".
|
|
||||||
:type output_path: str, optional
|
|
||||||
:param kwargs: Keyword arguments passed on to utils.view.view_sig.
|
|
||||||
:type: dict of keyword arguments
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Create a recording and view it as a plot in a .png image:
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from utils.data import Recording
|
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
|
||||||
>>> metadata = {
|
|
||||||
>>> "sample_rate": 1e6,
|
|
||||||
>>> "center_frequency": 2.44e9,
|
|
||||||
>>> }
|
|
||||||
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
|
||||||
>>> recording.view()
|
|
||||||
"""
|
|
||||||
from ria_toolkit_oss.view.view_signal import view_sig
|
|
||||||
|
|
||||||
view_sig(recording=self, output_path=output_path, **kwargs)
|
|
||||||
|
|
||||||
def simple_view(self, **kwargs) -> None:
|
|
||||||
"""Create a plot of various signal visualizations as a PNG or SVG image.
|
|
||||||
|
|
||||||
:param kwargs: Keyword arguments passed on to utils.view.view_signal_simple.create_plots.
|
|
||||||
:type: dict of keyword arguments
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Create a recording and view it as a plot in a .png image:
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from utils.data import Recording
|
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
|
||||||
>>> metadata = {
|
|
||||||
>>> "sample_rate": 1e6,
|
|
||||||
>>> "center_frequency": 2.44e9,
|
|
||||||
>>> }
|
|
||||||
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
|
||||||
>>> recording.simple_view()
|
|
||||||
"""
|
|
||||||
from ria_toolkit_oss.view.view_signal_simple import view_simple_sig
|
|
||||||
|
|
||||||
view_simple_sig(recording=self, **kwargs)
|
|
||||||
|
|
||||||
def to_sigmf(
|
|
||||||
self, filename: Optional[str] = None, path: Optional[os.PathLike | str] = None, overwrite: bool = False
|
|
||||||
) -> None:
|
|
||||||
"""Write recording to a set of SigMF files.
|
|
||||||
|
|
||||||
The SigMF io format is defined by the `SigMF Specification Project <https://github.com/sigmf/SigMF>`_
|
|
||||||
|
|
||||||
:param recording: The recording to be written to file.
|
|
||||||
:type recording: ria_toolkit_oss.datatypes.Recording
|
|
||||||
:param filename: The name of the file where the recording is to be saved. Defaults to auto generated filename.
|
|
||||||
:type filename: os.PathLike or str, optional
|
|
||||||
:param path: The directory path to where the recording is to be saved. Defaults to recordings/.
|
|
||||||
:type path: os.PathLike or str, optional
|
|
||||||
|
|
||||||
:raises IOError: If there is an issue encountered during the file writing process.
|
|
||||||
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
from ria_toolkit_oss.io.recording import to_sigmf
|
|
||||||
|
|
||||||
to_sigmf(filename=filename, path=path, recording=self, overwrite=overwrite)
|
|
||||||
|
|
||||||
def to_npy(
|
|
||||||
self, filename: Optional[str] = None, path: Optional[os.PathLike | str] = None, overwrite: bool = False
|
|
||||||
) -> str:
|
|
||||||
"""Write recording to ``.npy`` binary file.
|
|
||||||
|
|
||||||
:param filename: The name of the file where the recording is to be saved. Defaults to auto generated filename.
|
|
||||||
:type filename: os.PathLike or str, optional
|
|
||||||
:param path: The directory path to where the recording is to be saved. Defaults to recordings/.
|
|
||||||
:type path: os.PathLike or str, optional
|
|
||||||
|
|
||||||
:raises IOError: If there is an issue encountered during the file writing process.
|
|
||||||
|
|
||||||
:return: Path where the file was saved.
|
|
||||||
:rtype: str
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Create a recording and save it to a .npy file:
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording
|
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
|
||||||
>>> metadata = {
|
|
||||||
>>> "sample_rate": 1e6,
|
|
||||||
>>> "center_frequency": 2.44e9,
|
|
||||||
>>> }
|
|
||||||
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
|
||||||
>>> recording.to_npy()
|
|
||||||
"""
|
|
||||||
from ria_toolkit_oss.io.recording import to_npy
|
|
||||||
|
|
||||||
to_npy(recording=self, filename=filename, path=path, overwrite=overwrite)
|
|
||||||
|
|
||||||
def to_wav(
|
|
||||||
self,
|
|
||||||
filename: Optional[str] = None,
|
|
||||||
path: Optional[os.PathLike | str] = None,
|
|
||||||
target_sample_rate: Optional[int] = 48000,
|
|
||||||
bits_per_sample: int = 32,
|
|
||||||
overwrite: bool = False,
|
|
||||||
) -> str:
|
|
||||||
"""Write recording to WAV file with embedded YAML metadata.
|
|
||||||
|
|
||||||
WAV format uses stereo audio with I (in-phase) in left channel and Q (quadrature) in right channel.
|
|
||||||
Metadata is stored in standard LIST INFO chunks with RF-specific metadata encoded as YAML
|
|
||||||
in the ICMT (comment) field for human readability.
|
|
||||||
|
|
||||||
:param filename: The name of the file where the recording is to be saved. Defaults to auto generated filename.
|
|
||||||
:type filename: os.PathLike or str, optional
|
|
||||||
:param path: The directory path to where the recording is to be saved. Defaults to recordings/.
|
|
||||||
:type path: os.PathLike or str, optional
|
|
||||||
:param target_sample_rate: Sample rate stored in the WAV header when no sample_rate metadata
|
|
||||||
is present. IQ samples are written without decimation or interpolation. Default is 48000 Hz.
|
|
||||||
:type target_sample_rate: int, optional
|
|
||||||
:param bits_per_sample: Bits per sample (32 for float32, 16 for int16). Default is 32.
|
|
||||||
:type bits_per_sample: int, optional
|
|
||||||
:param overwrite: Whether to overwrite existing files. Default is False.
|
|
||||||
:type overwrite: bool, optional
|
|
||||||
|
|
||||||
:raises IOError: If there is an issue encountered during the file writing process.
|
|
||||||
|
|
||||||
:return: Path where the file was saved.
|
|
||||||
:rtype: str
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Create a recording and save it to a .wav file:
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from utils.data import Recording
|
|
||||||
>>> samples = numpy.exp(1j * 2 * numpy.pi * 0.1 * numpy.arange(10000))
|
|
||||||
>>> metadata = {"sample_rate": 1e6, "center_frequency": 915e6}
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
|
||||||
>>> recording.to_wav()
|
|
||||||
"""
|
|
||||||
from ria_toolkit_oss.io.recording import to_wav
|
|
||||||
|
|
||||||
return to_wav(
|
|
||||||
recording=self,
|
|
||||||
filename=filename,
|
|
||||||
path=path,
|
|
||||||
target_sample_rate=target_sample_rate,
|
|
||||||
bits_per_sample=bits_per_sample,
|
|
||||||
overwrite=overwrite,
|
|
||||||
)
|
|
||||||
|
|
||||||
def to_blue(
|
|
||||||
self,
|
|
||||||
filename: Optional[str] = None,
|
|
||||||
path: Optional[os.PathLike | str] = None,
|
|
||||||
data_format: str = "CI",
|
|
||||||
overwrite: bool = False,
|
|
||||||
) -> str:
|
|
||||||
"""Write recording to MIDAS Blue file format.
|
|
||||||
|
|
||||||
MIDAS Blue is a legacy RF file format with a 512-byte binary header.
|
|
||||||
Commonly used with X-Midas and other RF/radar signal processing tools.
|
|
||||||
|
|
||||||
:param filename: The name of the file where the recording is to be saved. Defaults to auto generated filename.
|
|
||||||
:type filename: os.PathLike or str, optional
|
|
||||||
:param path: The directory path to where the recording is to be saved. Defaults to recordings/.
|
|
||||||
:type path: os.PathLike or str, optional
|
|
||||||
:param data_format: Format code (default 'CI' = complex int16).
|
|
||||||
Common formats: 'CI' (complex int16), 'CF' (complex float32), 'CD' (complex float64).
|
|
||||||
Integer formats require the IQ samples to already be scaled within [-1, 1).
|
|
||||||
:type data_format: str, optional
|
|
||||||
:param overwrite: Whether to overwrite existing files. Default is False.
|
|
||||||
:type overwrite: bool, optional
|
|
||||||
|
|
||||||
:raises IOError: If there is an issue encountered during the file writing process.
|
|
||||||
|
|
||||||
:return: Path where the file was saved.
|
|
||||||
:rtype: str
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Create a recording and save it to a .blue file:
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from utils.data import Recording
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
|
||||||
>>> metadata = {"sample_rate": 1e6, "center_frequency": 2.44e9}
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
|
||||||
>>> recording.to_blue()
|
|
||||||
"""
|
|
||||||
from ria_toolkit_oss.io.recording import to_blue
|
|
||||||
|
|
||||||
return to_blue(recording=self, filename=filename, path=path, data_format=data_format, overwrite=overwrite)
|
|
||||||
|
|
||||||
def trim(self, num_samples: int, start_sample: Optional[int] = 0) -> Recording:
|
|
||||||
"""Trim Recording samples to a desired length, shifting annotations to maintain alignment.
|
|
||||||
|
|
||||||
:param start_sample: The start index of the desired trimmed recording. Defaults to 0.
|
|
||||||
:type start_sample: int, optional
|
|
||||||
:param num_samples: The number of samples that the output trimmed recording will have.
|
|
||||||
:type num_samples: int
|
|
||||||
:raises IndexError: If start_sample + num_samples is greater than the length of the recording.
|
|
||||||
:raises IndexError: If sample_start < 0 or num_samples < 0.
|
|
||||||
|
|
||||||
:return: The trimmed Recording.
|
|
||||||
:rtype: Recording
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Create a recording and trim it:
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording
|
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64)
|
|
||||||
>>> metadata = {
|
|
||||||
... "sample_rate": 1e6,
|
|
||||||
... "center_frequency": 2.44e9,
|
|
||||||
... }
|
|
||||||
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
|
||||||
>>> print(len(recording))
|
|
||||||
10000
|
|
||||||
|
|
||||||
>>> trimmed_recording = recording.trim(start_sample=1000, num_samples=1000)
|
|
||||||
>>> print(len(trimmed_recording))
|
|
||||||
1000
|
|
||||||
"""
|
|
||||||
|
|
||||||
if start_sample < 0:
|
|
||||||
raise IndexError("start_sample cannot be < 0.")
|
|
||||||
elif start_sample + num_samples > len(self):
|
|
||||||
raise IndexError(
|
|
||||||
f"start_sample {start_sample} + num_samples {num_samples} > recording length {len(self)}."
|
|
||||||
)
|
|
||||||
|
|
||||||
end_sample = start_sample + num_samples
|
|
||||||
|
|
||||||
data = self.data[:, start_sample:end_sample]
|
|
||||||
|
|
||||||
new_annotations = copy.deepcopy(self.annotations)
|
|
||||||
trimmed_annotations = []
|
|
||||||
for annotation in new_annotations:
|
|
||||||
# skip annotations entirely outside the trim window
|
|
||||||
if annotation.sample_start + annotation.sample_count <= start_sample:
|
|
||||||
continue
|
|
||||||
if annotation.sample_start >= end_sample:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# trim annotation if it goes outside the trim boundaries
|
|
||||||
if annotation.sample_start < start_sample:
|
|
||||||
annotation.sample_count = annotation.sample_count - (start_sample - annotation.sample_start)
|
|
||||||
annotation.sample_start = start_sample
|
|
||||||
|
|
||||||
if annotation.sample_start + annotation.sample_count > end_sample:
|
|
||||||
annotation.sample_count = end_sample - annotation.sample_start
|
|
||||||
|
|
||||||
# shift annotation to align with the new start point
|
|
||||||
annotation.sample_start = annotation.sample_start - start_sample
|
|
||||||
trimmed_annotations.append(annotation)
|
|
||||||
|
|
||||||
return Recording(data=data, metadata=self.metadata, annotations=trimmed_annotations)
|
|
||||||
|
|
||||||
def normalize(self) -> Recording:
|
|
||||||
"""Scale the recording data, relative to its maximum value, so that the magnitude of the maximum sample is 1.
|
|
||||||
|
|
||||||
:return: Recording where the maximum sample amplitude is 1.
|
|
||||||
:rtype: Recording
|
|
||||||
|
|
||||||
**Examples:**
|
|
||||||
|
|
||||||
Create a recording with maximum amplitude 0.5 and normalize to a maximum amplitude of 1:
|
|
||||||
|
|
||||||
>>> import numpy
|
|
||||||
>>> from ria_toolkit_oss.datatypes import Recording
|
|
||||||
|
|
||||||
>>> samples = numpy.ones(10000, dtype=numpy.complex64) * 0.5
|
|
||||||
>>> metadata = {
|
|
||||||
... "sample_rate": 1e6,
|
|
||||||
... "center_frequency": 2.44e9,
|
|
||||||
... }
|
|
||||||
|
|
||||||
>>> recording = Recording(data=samples, metadata=metadata)
|
|
||||||
>>> print(numpy.max(numpy.abs(recording.data)))
|
|
||||||
0.5
|
|
||||||
|
|
||||||
>>> normalized_recording = recording.normalize()
|
|
||||||
>>> print(numpy.max(numpy.abs(normalized_recording.data)))
|
|
||||||
1
|
|
||||||
"""
|
|
||||||
max_val = np.max(abs(self.data))
|
|
||||||
if max_val == 0:
|
|
||||||
raise ValueError("Cannot normalize a recording with all-zero data.")
|
|
||||||
scaled_data = self.data / max_val
|
|
||||||
return Recording(data=scaled_data, metadata=self.metadata, annotations=self.annotations)
|
|
||||||
|
|
||||||
def __len__(self) -> int:
|
|
||||||
"""The length of a recording is defined by the number of complex samples in each channel of the recording."""
|
|
||||||
return self.shape[1]
|
|
||||||
|
|
||||||
def __eq__(self, other: Recording) -> bool:
|
|
||||||
"""Two Recordings are equal if all data, metadata, and annotations are the same."""
|
|
||||||
|
|
||||||
# counter used to allow for differently ordered annotation lists
|
|
||||||
return (
|
|
||||||
np.array_equal(self.data, other.data)
|
|
||||||
and self.metadata == other.metadata
|
|
||||||
and self.annotations == other.annotations
|
|
||||||
)
|
|
||||||
|
|
||||||
def __ne__(self, other: Recording) -> bool:
|
|
||||||
"""Two Recordings are equal if all data, and metadata, and annotations are the same."""
|
|
||||||
return not self.__eq__(other=other)
|
|
||||||
|
|
||||||
def __iter__(self) -> Iterator:
|
|
||||||
self._index = 0
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __next__(self) -> np.ndarray:
|
|
||||||
if self._index < self.n_chan:
|
|
||||||
to_ret = self.data[self._index]
|
|
||||||
self._index += 1
|
|
||||||
return to_ret
|
|
||||||
else:
|
|
||||||
raise StopIteration
|
|
||||||
|
|
||||||
def __getitem__(self, key: int | tuple[int] | slice) -> np.ndarray | np.complexfloating:
|
|
||||||
"""If key is an integer, tuple of integers, or a slice, return the corresponding samples.
|
|
||||||
|
|
||||||
For arrays with 1,024 or fewer samples, return a copy of the recording data. For larger arrays, return a
|
|
||||||
read-only view. This prevents mutation at a distance while maintaining performance.
|
|
||||||
"""
|
|
||||||
if isinstance(key, (int, tuple, slice)):
|
|
||||||
v = self._data[key]
|
|
||||||
if isinstance(v, np.complexfloating):
|
|
||||||
return v
|
|
||||||
elif v.size > 1024:
|
|
||||||
v.setflags(write=False) # Make view read-only.
|
|
||||||
return v
|
|
||||||
else:
|
|
||||||
return v.copy()
|
|
||||||
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Key must be an integer, tuple, or slice but was {type(key)}.")
|
|
||||||
|
|
||||||
def __setitem__(self, *args, **kwargs) -> None:
|
|
||||||
"""Raise an error if an attempt is made to assign to the recording."""
|
|
||||||
raise ValueError("Assignment to Recording is not allowed.")
|
|
||||||
|
|
||||||
|
|
||||||
def generate_recording_id(data: np.ndarray, timestamp: Optional[float | int] = None) -> str:
|
|
||||||
"""Generate unique 64-character recording ID. The recording ID is generated by hashing the recording data with
|
|
||||||
the datetime that the recording data was generated. If no datatime is provided, the current datatime is used.
|
|
||||||
|
|
||||||
:param data: Tape of IQ samples, as a NumPy array.
|
|
||||||
:type data: np.ndarray
|
|
||||||
:param timestamp: Unix timestamp in seconds. Defaults to None.
|
|
||||||
:type timestamp: float or int, optional
|
|
||||||
|
|
||||||
:return: 256-character hash, to be used as the recording ID.
|
|
||||||
:rtype: str
|
|
||||||
"""
|
|
||||||
if timestamp is None:
|
|
||||||
timestamp = time.time()
|
|
||||||
|
|
||||||
byte_sequence = data.tobytes() + str(timestamp).encode("utf-8")
|
|
||||||
sha256_hash = hashlib.sha256(byte_sequence)
|
|
||||||
|
|
||||||
return sha256_hash.hexdigest()
|
|
||||||
|
|
||||||
|
|
||||||
def _is_jsonable(x: Any) -> bool:
|
|
||||||
"""
|
|
||||||
:return: True if x is JSON serializable, False otherwise.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
json.dumps(x)
|
|
||||||
return True
|
|
||||||
except (TypeError, OverflowError):
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def _is_valid_metadata_key(key: Any) -> bool:
|
|
||||||
"""
|
|
||||||
:return: True if key is a valid metadata key, False otherwise.
|
|
||||||
"""
|
|
||||||
if isinstance(key, str) and key.islower() and re.match(pattern=r"^[a-z_]+$", string=key) is not None:
|
|
||||||
return True
|
|
||||||
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Utilities for input/output operations on the ria_toolkit_oss.datatypes.Recording object.
|
Utilities for input/output operations on the ria_toolkit_oss.data.Recording object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
@ -19,8 +19,8 @@ from quantiphy import Quantity
|
||||||
from sigmf import SigMFFile, sigmffile
|
from sigmf import SigMFFile, sigmffile
|
||||||
from sigmf.utils import get_data_type_str
|
from sigmf.utils import get_data_type_str
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Annotation
|
from ria_toolkit_oss.data import Annotation
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
|
|
||||||
_BLUE_META_PREFIX = "META_"
|
_BLUE_META_PREFIX = "META_"
|
||||||
_BLUE_META_TAG_MAX_LEN = 60
|
_BLUE_META_TAG_MAX_LEN = 60
|
||||||
|
|
@ -64,7 +64,7 @@ def to_npy(
|
||||||
"""Write recording to ``.npy`` binary file.
|
"""Write recording to ``.npy`` binary file.
|
||||||
|
|
||||||
:param recording: The recording to be written to file.
|
:param recording: The recording to be written to file.
|
||||||
:type recording: ria_toolkit_oss.datatypes.Recording
|
:type recording: ria_toolkit_oss.data.Recording
|
||||||
:param filename: The name of the file where the recording is to be saved. Defaults to auto generated filename.
|
:param filename: The name of the file where the recording is to be saved. Defaults to auto generated filename.
|
||||||
:type filename: os.PathLike or str, optional
|
:type filename: os.PathLike or str, optional
|
||||||
:param path: The directory path to where the recording is to be saved. Defaults to recordings/.
|
:param path: The directory path to where the recording is to be saved. Defaults to recordings/.
|
||||||
|
|
@ -135,7 +135,7 @@ def from_npy(file: os.PathLike | str, legacy: bool = False) -> Recording:
|
||||||
:raises IOError: If there is an issue encountered during the file reading process.
|
:raises IOError: If there is an issue encountered during the file reading process.
|
||||||
|
|
||||||
:return: The recording, as initialized from the ``.npy`` file.
|
:return: The recording, as initialized from the ``.npy`` file.
|
||||||
:rtype: ria_toolkit_oss.datatypes.Recording
|
:rtype: ria_toolkit_oss.data.Recording
|
||||||
"""
|
"""
|
||||||
|
|
||||||
filename, extension = os.path.splitext(file)
|
filename, extension = os.path.splitext(file)
|
||||||
|
|
@ -161,7 +161,7 @@ def from_npy(file: os.PathLike | str, legacy: bool = False) -> Recording:
|
||||||
try:
|
try:
|
||||||
raw_ann = np.load(f, allow_pickle=False)
|
raw_ann = np.load(f, allow_pickle=False)
|
||||||
ann_list = json.loads(raw_ann.tobytes().decode())
|
ann_list = json.loads(raw_ann.tobytes().decode())
|
||||||
from ria_toolkit_oss.datatypes.annotation import Annotation
|
from ria_toolkit_oss.data.annotation import Annotation
|
||||||
|
|
||||||
annotations = [Annotation(**a) for a in ann_list]
|
annotations = [Annotation(**a) for a in ann_list]
|
||||||
except EOFError:
|
except EOFError:
|
||||||
|
|
@ -198,7 +198,7 @@ def from_npy_legacy(file: os.PathLike | str) -> Recording:
|
||||||
:raises IOError: If there is an issue encountered during the file reading process.
|
:raises IOError: If there is an issue encountered during the file reading process.
|
||||||
|
|
||||||
:return: The recording, as initialized from the legacy ``.npy`` file.
|
:return: The recording, as initialized from the legacy ``.npy`` file.
|
||||||
:rtype: ria_toolkit_oss.datatypes.Recording
|
:rtype: ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
**Examples:**
|
**Examples:**
|
||||||
|
|
||||||
|
|
@ -270,7 +270,7 @@ def to_sigmf(
|
||||||
The SigMF io format is defined by the `SigMF Specification Project <https://github.com/sigmf/SigMF>`_
|
The SigMF io format is defined by the `SigMF Specification Project <https://github.com/sigmf/SigMF>`_
|
||||||
|
|
||||||
:param recording: The recording to be written to file.
|
:param recording: The recording to be written to file.
|
||||||
:type recording: ria_toolkit_oss.datatypes.Recording
|
:type recording: ria_toolkit_oss.data.Recording
|
||||||
:param filename: The name of the file where the recording is to be saved. Defaults to auto generated filename.
|
:param filename: The name of the file where the recording is to be saved. Defaults to auto generated filename.
|
||||||
:type filename: os.PathLike or str, optional
|
:type filename: os.PathLike or str, optional
|
||||||
:param path: The directory path to where the recording is to be saved. Defaults to recordings/.
|
:param path: The directory path to where the recording is to be saved. Defaults to recordings/.
|
||||||
|
|
@ -381,7 +381,7 @@ def from_sigmf(file: os.PathLike | str) -> Recording:
|
||||||
:raises IOError: If there is an issue encountered during the file reading process.
|
:raises IOError: If there is an issue encountered during the file reading process.
|
||||||
|
|
||||||
:return: The recording, as initialized from the SigMF files.
|
:return: The recording, as initialized from the SigMF files.
|
||||||
:rtype: ria_toolkit_oss.datatypes.Recording
|
:rtype: ria_toolkit_oss.data.Recording
|
||||||
"""
|
"""
|
||||||
|
|
||||||
file = str(file)
|
file = str(file)
|
||||||
|
|
@ -443,7 +443,7 @@ def to_wav(
|
||||||
in the ICMT (comment) field for human readability.
|
in the ICMT (comment) field for human readability.
|
||||||
|
|
||||||
:param recording: The recording to be written to file.
|
:param recording: The recording to be written to file.
|
||||||
:type recording: ria_toolkit_oss.datatypes.Recording
|
:type recording: ria_toolkit_oss.data.Recording
|
||||||
:param filename: The name of the file where the recording is to be saved.
|
:param filename: The name of the file where the recording is to be saved.
|
||||||
Defaults to auto-generated filename.
|
Defaults to auto-generated filename.
|
||||||
:type filename: str, optional
|
:type filename: str, optional
|
||||||
|
|
@ -553,7 +553,7 @@ def from_wav(file: os.PathLike | str) -> Recording:
|
||||||
:raises ValueError: If file is not stereo or has unsupported format.
|
:raises ValueError: If file is not stereo or has unsupported format.
|
||||||
|
|
||||||
:return: The recording, as initialized from the WAV file.
|
:return: The recording, as initialized from the WAV file.
|
||||||
:rtype: ria_toolkit_oss.datatypes.Recording
|
:rtype: ria_toolkit_oss.data.Recording
|
||||||
"""
|
"""
|
||||||
import wave
|
import wave
|
||||||
|
|
||||||
|
|
@ -635,7 +635,7 @@ def to_blue(
|
||||||
Commonly used with X-Midas and other RF/radar signal processing tools.
|
Commonly used with X-Midas and other RF/radar signal processing tools.
|
||||||
|
|
||||||
:param recording: The recording to be written to file.
|
:param recording: The recording to be written to file.
|
||||||
:type recording: ria_toolkit_oss.datatypes.Recording
|
:type recording: ria_toolkit_oss.data.Recording
|
||||||
:param filename: The name of the file where the recording is to be saved.
|
:param filename: The name of the file where the recording is to be saved.
|
||||||
Defaults to auto-generated filename.
|
Defaults to auto-generated filename.
|
||||||
:type filename: str, optional
|
:type filename: str, optional
|
||||||
|
|
@ -792,7 +792,7 @@ def from_blue(file: os.PathLike | str) -> Recording:
|
||||||
:raises ValueError: If file format is not valid or unsupported.
|
:raises ValueError: If file format is not valid or unsupported.
|
||||||
|
|
||||||
:return: The recording, as initialized from the Blue file.
|
:return: The recording, as initialized from the Blue file.
|
||||||
:rtype: ria_toolkit_oss.datatypes.Recording
|
:rtype: ria_toolkit_oss.data.Recording
|
||||||
"""
|
"""
|
||||||
filename = str(file)
|
filename = str(file)
|
||||||
if not filename.endswith(".blue"):
|
if not filename.endswith(".blue"):
|
||||||
|
|
@ -917,7 +917,7 @@ def load_recording(file: os.PathLike) -> Recording:
|
||||||
:raises ValueError: If the inferred file extension is not supported.
|
:raises ValueError: If the inferred file extension is not supported.
|
||||||
|
|
||||||
:return: The recording, as initialized from file(s).
|
:return: The recording, as initialized from file(s).
|
||||||
:rtype: ria_toolkit_oss.datatypes.Recording
|
:rtype: ria_toolkit_oss.data.Recording
|
||||||
"""
|
"""
|
||||||
_, extension = os.path.splitext(file)
|
_, extension = os.path.splitext(file)
|
||||||
extension = extension.lstrip(".")
|
extension = extension.lstrip(".")
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from dataclasses import dataclass, field, replace
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Callable, Optional
|
from typing import Callable, Optional
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.io.recording import to_sigmf
|
from ria_toolkit_oss.io.recording import to_sigmf
|
||||||
|
|
||||||
from .campaign import CampaignConfig, CaptureStep, TransmitterConfig
|
from .campaign import CampaignConfig, CaptureStep, TransmitterConfig
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
|
|
||||||
from .campaign import CaptureStep
|
from .campaign import CaptureStep
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from dataclasses import dataclass, field
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
|
|
||||||
from .campaign import QAConfig
|
from .campaign import QAConfig
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from typing import Optional
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from bladerf import _bladerf
|
from bladerf import _bladerf
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
from ria_toolkit_oss.sdr import SDR, SDRError, SDRParameterError
|
from ria_toolkit_oss.sdr import SDR, SDRError, SDRParameterError
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from typing import Optional
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.sdr._external.libhackrf import HackRF as hrf
|
from ria_toolkit_oss.sdr._external.libhackrf import HackRF as hrf
|
||||||
from ria_toolkit_oss.sdr.sdr import SDR, SDRParameterError
|
from ria_toolkit_oss.sdr.sdr import SDR, SDRParameterError
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from typing import Optional
|
||||||
import adi
|
import adi
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.sdr.sdr import (
|
from ria_toolkit_oss.sdr.sdr import (
|
||||||
SDR,
|
SDR,
|
||||||
SDRError,
|
SDRError,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ try:
|
||||||
except ImportError as exc: # pragma: no cover - dependency provided by end user
|
except ImportError as exc: # pragma: no cover - dependency provided by end user
|
||||||
raise ImportError("pyrtlsdr is required to use the RTLSDR class") from exc
|
raise ImportError("pyrtlsdr is required to use the RTLSDR class") from exc
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.sdr.sdr import SDR, SDRParameterError
|
from ria_toolkit_oss.sdr.sdr import SDR, SDRParameterError
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from typing import Optional
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import zmq
|
import zmq
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
|
|
||||||
|
|
||||||
class SDR(ABC):
|
class SDR(ABC):
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from typing import Optional
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import uhd
|
import uhd
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.sdr.sdr import SDR, SDRParameterError
|
from ria_toolkit_oss.sdr.sdr import SDR, SDRParameterError
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from scipy.signal import butter
|
||||||
from scipy.signal import chirp as sci_chirp
|
from scipy.signal import chirp as sci_chirp
|
||||||
from scipy.signal import hilbert, lfilter
|
from scipy.signal import hilbert, lfilter
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
|
|
||||||
|
|
||||||
def sine(
|
def sine(
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.signal.block_generator.generators.signal_generator import (
|
from ria_toolkit_oss.signal.block_generator.generators.signal_generator import (
|
||||||
SignalGenerator,
|
SignalGenerator,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.signal.block_generator.generators.signal_generator import (
|
from ria_toolkit_oss.signal.block_generator.generators.signal_generator import (
|
||||||
SignalGenerator,
|
SignalGenerator,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.signal.block_generator.generators.signal_generator import (
|
from ria_toolkit_oss.signal.block_generator.generators.signal_generator import (
|
||||||
SignalGenerator,
|
SignalGenerator,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
from ria_toolkit_oss.signal import Recordable
|
from ria_toolkit_oss.signal import Recordable
|
||||||
from ria_toolkit_oss.signal.block_generator.block import Block
|
from ria_toolkit_oss.signal.block_generator.block import Block
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ from datetime import datetime
|
||||||
import click
|
import click
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.signal.block_generator.mapping.mapper import Mapper
|
from ria_toolkit_oss.signal.block_generator.mapping.mapper import Mapper
|
||||||
from ria_toolkit_oss.signal.block_generator.multirate.upsampling import Upsampling
|
from ria_toolkit_oss.signal.block_generator.multirate.upsampling import Upsampling
|
||||||
from ria_toolkit_oss.signal.block_generator.pulse_shaping.raised_cosine_filter import (
|
from ria_toolkit_oss.signal.block_generator.pulse_shaping.raised_cosine_filter import (
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
from ria_toolkit_oss.signal.block_generator.data_types import DataType
|
from ria_toolkit_oss.signal.block_generator.data_types import DataType
|
||||||
from ria_toolkit_oss.signal.block_generator.recordable_block import RecordableBlock
|
from ria_toolkit_oss.signal.block_generator.recordable_block import RecordableBlock
|
||||||
from ria_toolkit_oss.signal.block_generator.source_block import SourceBlock
|
from ria_toolkit_oss.signal.block_generator.source_block import SourceBlock
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
|
|
||||||
|
|
||||||
class Recordable(ABC):
|
class Recordable(ABC):
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from typing import Optional
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numpy.typing import ArrayLike
|
from numpy.typing import ArrayLike
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.utils.array_conversion import convert_to_2xn
|
from ria_toolkit_oss.utils.array_conversion import convert_to_2xn
|
||||||
|
|
||||||
# TODO: For round 2 of index generation, should j be at min 2 spots away from where it was to prevent adjacent patches.
|
# TODO: For round 2 of index generation, should j be at min 2 spots away from where it was to prevent adjacent patches.
|
||||||
|
|
@ -29,7 +29,7 @@ def generate_awgn(signal: ArrayLike | Recording, snr: Optional[float] = 1) -> np
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param snr: The signal-to-noise ratio in dB. Default is 1.
|
:param snr: The signal-to-noise ratio in dB. Default is 1.
|
||||||
:type snr: float, optional
|
:type snr: float, optional
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ def generate_awgn(signal: ArrayLike | Recording, snr: Optional[float] = 1) -> np
|
||||||
|
|
||||||
:return: A numpy array representing the generated noise which matches the SNR of `signal`. If `signal` is a
|
:return: A numpy array representing the generated noise which matches the SNR of `signal`. If `signal` is a
|
||||||
Recording, returns a Recording object with its `data` attribute containing the generated noise array.
|
Recording, returns a Recording object with its `data` attribute containing the generated noise array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[2 + 5j, 1 + 8j]])
|
>>> rec = Recording(data=[[2 + 5j, 1 + 8j]])
|
||||||
>>> new_rec = generate_awgn(rec)
|
>>> new_rec = generate_awgn(rec)
|
||||||
|
|
@ -80,14 +80,14 @@ def time_reversal(signal: ArrayLike | Recording) -> np.ndarray | Recording:
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:raises ValueError: If `signal` is not CxN complex.
|
:raises ValueError: If `signal` is not CxN complex.
|
||||||
|
|
||||||
:return: A numpy array containing the reversed I and Q data samples if `signal` is an array.
|
:return: A numpy array containing the reversed I and Q data samples if `signal` is an array.
|
||||||
If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing the
|
If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing the
|
||||||
reversed array.
|
reversed array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[1+2j, 3+4j, 5+6j]])
|
>>> rec = Recording(data=[[1+2j, 3+4j, 5+6j]])
|
||||||
>>> new_rec = time_reversal(rec)
|
>>> new_rec = time_reversal(rec)
|
||||||
|
|
@ -123,14 +123,14 @@ def spectral_inversion(signal: ArrayLike | Recording) -> np.ndarray | Recording:
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:raises ValueError: If `signal` is not CxN complex.
|
:raises ValueError: If `signal` is not CxN complex.
|
||||||
|
|
||||||
:return: A numpy array containing the original I and negated Q data samples if `signal` is an array.
|
:return: A numpy array containing the original I and negated Q data samples if `signal` is an array.
|
||||||
If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing the
|
If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing the
|
||||||
inverted array.
|
inverted array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[0+45j, 2-10j]])
|
>>> rec = Recording(data=[[0+45j, 2-10j]])
|
||||||
>>> new_rec = spectral_inversion(rec)
|
>>> new_rec = spectral_inversion(rec)
|
||||||
|
|
@ -165,14 +165,14 @@ def channel_swap(signal: ArrayLike | Recording) -> np.ndarray | Recording:
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:raises ValueError: If `signal` is not CxN complex.
|
:raises ValueError: If `signal` is not CxN complex.
|
||||||
|
|
||||||
:return: A numpy array containing the swapped I and Q data samples if `signal` is an array.
|
:return: A numpy array containing the swapped I and Q data samples if `signal` is an array.
|
||||||
If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing the
|
If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing the
|
||||||
swapped array.
|
swapped array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[10+20j, 7+35j]])
|
>>> rec = Recording(data=[[10+20j, 7+35j]])
|
||||||
>>> new_rec = channel_swap(rec)
|
>>> new_rec = channel_swap(rec)
|
||||||
|
|
@ -207,14 +207,14 @@ def amplitude_reversal(signal: ArrayLike | Recording) -> np.ndarray | Recording:
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:raises ValueError: If `signal` is not CxN complex.
|
:raises ValueError: If `signal` is not CxN complex.
|
||||||
|
|
||||||
:return: A numpy array containing the negated I and Q data samples if `signal` is an array.
|
:return: A numpy array containing the negated I and Q data samples if `signal` is an array.
|
||||||
If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing the
|
If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing the
|
||||||
negated array.
|
negated array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[4-3j, -5-2j, -9+1j]])
|
>>> rec = Recording(data=[[4-3j, -5-2j, -9+1j]])
|
||||||
>>> new_rec = amplitude_reversal(rec)
|
>>> new_rec = amplitude_reversal(rec)
|
||||||
|
|
@ -253,7 +253,7 @@ def drop_samples( # noqa: C901 # TODO: Simplify function
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param max_section_size: Maximum allowable size of the section to be dropped and replaced. Default is 2.
|
:param max_section_size: Maximum allowable size of the section to be dropped and replaced. Default is 2.
|
||||||
:type max_section_size: int, optional
|
:type max_section_size: int, optional
|
||||||
:param fill_type: Fill option used to replace dropped section of data (back-fill, front-fill, mean, zeros).
|
:param fill_type: Fill option used to replace dropped section of data (back-fill, front-fill, mean, zeros).
|
||||||
|
|
@ -275,7 +275,7 @@ def drop_samples( # noqa: C901 # TODO: Simplify function
|
||||||
:return: A numpy array containing the I and Q data samples with replaced subsections if
|
:return: A numpy array containing the I and Q data samples with replaced subsections if
|
||||||
`signal` is an array. If `signal` is a `Recording`, returns a `Recording` object with its `data`
|
`signal` is an array. If `signal` is a `Recording`, returns a `Recording` object with its `data`
|
||||||
attribute containing the array with dropped samples.
|
attribute containing the array with dropped samples.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[2+5j, 1+8j, 6+4j, 3+7j, 4+9j]])
|
>>> rec = Recording(data=[[2+5j, 1+8j, 6+4j, 3+7j, 4+9j]])
|
||||||
>>> new_rec = drop_samples(rec)
|
>>> new_rec = drop_samples(rec)
|
||||||
|
|
@ -346,7 +346,7 @@ def quantize_tape(
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param bin_number: The number of bins the signal should be divided into. Default is 4.
|
:param bin_number: The number of bins the signal should be divided into. Default is 4.
|
||||||
:type bin_number: int, optional
|
:type bin_number: int, optional
|
||||||
:param rounding_type: The type of rounding applied during processing. Default is "floor".
|
:param rounding_type: The type of rounding applied during processing. Default is "floor".
|
||||||
|
|
@ -362,7 +362,7 @@ def quantize_tape(
|
||||||
:return: A numpy array containing the quantized I and Q data samples if `signal` is an array.
|
:return: A numpy array containing the quantized I and Q data samples if `signal` is an array.
|
||||||
If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing
|
If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing
|
||||||
the quantized array.
|
the quantized array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[1+1j, 4+4j, 1+2j, 1+4j]])
|
>>> rec = Recording(data=[[1+1j, 4+4j, 1+2j, 1+4j]])
|
||||||
>>> new_rec = quantize_tape(rec)
|
>>> new_rec = quantize_tape(rec)
|
||||||
|
|
@ -421,7 +421,7 @@ def quantize_parts(
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param max_section_size: Maximum allowable size of the section to be quantized. Default is 2.
|
:param max_section_size: Maximum allowable size of the section to be quantized. Default is 2.
|
||||||
:type max_section_size: int, optional
|
:type max_section_size: int, optional
|
||||||
:param bin_number: The number of bins the signal should be divided into. Default is 4.
|
:param bin_number: The number of bins the signal should be divided into. Default is 4.
|
||||||
|
|
@ -439,7 +439,7 @@ def quantize_parts(
|
||||||
:return: A numpy array containing the I and Q data samples with quantized subsections if `signal`
|
:return: A numpy array containing the I and Q data samples with quantized subsections if `signal`
|
||||||
is an array. If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute
|
is an array. If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute
|
||||||
containing the partially quantized array.
|
containing the partially quantized array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[2+5j, 1+8j, 6+4j, 3+7j, 4+9j]])
|
>>> rec = Recording(data=[[2+5j, 1+8j, 6+4j, 3+7j, 4+9j]])
|
||||||
>>> new_rec = quantize_parts(rec)
|
>>> new_rec = quantize_parts(rec)
|
||||||
|
|
@ -510,7 +510,7 @@ def magnitude_rescale(
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param starting_bounds: The bounds (inclusive) as indices in which the starting position of the rescaling occurs.
|
:param starting_bounds: The bounds (inclusive) as indices in which the starting position of the rescaling occurs.
|
||||||
Default is None, but if user does not assign any bounds, the bounds become (random index, N-1).
|
Default is None, but if user does not assign any bounds, the bounds become (random index, N-1).
|
||||||
:type starting_bounds: tuple, optional
|
:type starting_bounds: tuple, optional
|
||||||
|
|
@ -522,7 +522,7 @@ def magnitude_rescale(
|
||||||
:return: A numpy array containing the I and Q data samples with the rescaled magnitude after the random
|
:return: A numpy array containing the I and Q data samples with the rescaled magnitude after the random
|
||||||
starting point if `signal` is an array. If `signal` is a `Recording`, returns a `Recording`
|
starting point if `signal` is an array. If `signal` is a `Recording`, returns a `Recording`
|
||||||
object with its `data` attribute containing the rescaled array.
|
object with its `data` attribute containing the rescaled array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[2+5j, 1+8j, 6+4j, 3+7j, 4+9j]])
|
>>> rec = Recording(data=[[2+5j, 1+8j, 6+4j, 3+7j, 4+9j]])
|
||||||
>>> new_rec = magniute_rescale(rec)
|
>>> new_rec = magniute_rescale(rec)
|
||||||
|
|
@ -571,7 +571,7 @@ def cut_out( # noqa: C901 # TODO: Simplify function
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param max_section_size: Maximum allowable size of the section to be quantized. Default is 3.
|
:param max_section_size: Maximum allowable size of the section to be quantized. Default is 3.
|
||||||
:type max_section_size: int, optional
|
:type max_section_size: int, optional
|
||||||
:param fill_type: Fill option used to replace cutout section of data (zeros, ones, low-snr, avg-snr-1, avg-snr-2).
|
:param fill_type: Fill option used to replace cutout section of data (zeros, ones, low-snr, avg-snr-1, avg-snr-2).
|
||||||
|
|
@ -596,7 +596,7 @@ def cut_out( # noqa: C901 # TODO: Simplify function
|
||||||
:return: A numpy array containing the I and Q data samples with random sections cut out and replaced according to
|
:return: A numpy array containing the I and Q data samples with random sections cut out and replaced according to
|
||||||
`fill_type` if `signal` is an array. If `signal` is a `Recording`, returns a `Recording` object
|
`fill_type` if `signal` is an array. If `signal` is a `Recording`, returns a `Recording` object
|
||||||
with its `data` attribute containing the cut out and replaced array.
|
with its `data` attribute containing the cut out and replaced array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[2+5j, 1+8j, 6+4j, 3+7j, 4+9j]])
|
>>> rec = Recording(data=[[2+5j, 1+8j, 6+4j, 3+7j, 4+9j]])
|
||||||
>>> new_rec = cut_out(rec)
|
>>> new_rec = cut_out(rec)
|
||||||
|
|
@ -666,7 +666,7 @@ def patch_shuffle(signal: ArrayLike | Recording, max_patch_size: Optional[int] =
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param max_patch_size: Maximum allowable patch size of the data that can be shuffled. Default is 3.
|
:param max_patch_size: Maximum allowable patch size of the data that can be shuffled. Default is 3.
|
||||||
:type max_patch_size: int, optional
|
:type max_patch_size: int, optional
|
||||||
|
|
||||||
|
|
@ -676,7 +676,7 @@ def patch_shuffle(signal: ArrayLike | Recording, max_patch_size: Optional[int] =
|
||||||
:return: A numpy array containing the I and Q data samples with randomly shuffled regions if `signal` is
|
:return: A numpy array containing the I and Q data samples with randomly shuffled regions if `signal` is
|
||||||
an array. If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing
|
an array. If `signal` is a `Recording`, returns a `Recording` object with its `data` attribute containing
|
||||||
the shuffled array.
|
the shuffled array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[2+5j, 1+8j, 6+4j, 3+7j, 4+9j]])
|
>>> rec = Recording(data=[[2+5j, 1+8j, 6+4j, 3+7j, 4+9j]])
|
||||||
>>> new_rec = patch_shuffle(rec)
|
>>> new_rec = patch_shuffle(rec)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import numpy as np
|
||||||
from numpy.typing import ArrayLike
|
from numpy.typing import ArrayLike
|
||||||
from scipy.signal import resample_poly
|
from scipy.signal import resample_poly
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
from ria_toolkit_oss.transforms import iq_augmentations
|
from ria_toolkit_oss.transforms import iq_augmentations
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ def add_awgn_to_signal(signal: ArrayLike | Recording, snr: Optional[float] = 1)
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex ``C x N`` array or `Recording`, where ``C`` is the number of channels
|
:param signal: Input IQ data as a complex ``C x N`` array or `Recording`, where ``C`` is the number of channels
|
||||||
and ``N`` is the length of the IQ examples.
|
and ``N`` is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param snr: The signal-to-noise ratio in dB. Default is 1.
|
:param snr: The signal-to-noise ratio in dB. Default is 1.
|
||||||
:type snr: float, optional
|
:type snr: float, optional
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ def add_awgn_to_signal(signal: ArrayLike | Recording, snr: Optional[float] = 1)
|
||||||
|
|
||||||
:return: A numpy array which is the sum of the noise (which matches the SNR) and the original signal. If `signal`
|
:return: A numpy array which is the sum of the noise (which matches the SNR) and the original signal. If `signal`
|
||||||
is a `Recording`, returns a `Recording object` with its `data` attribute containing the noisy signal array.
|
is a `Recording`, returns a `Recording object` with its `data` attribute containing the noisy signal array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[1+1j, 2+2j]])
|
>>> rec = Recording(data=[[1+1j, 2+2j]])
|
||||||
>>> new_rec = add_awgn_to_signal(rec)
|
>>> new_rec = add_awgn_to_signal(rec)
|
||||||
|
|
@ -71,7 +71,7 @@ def time_shift(signal: ArrayLike | Recording, shift: Optional[int] = 1) -> np.nd
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param shift: The number of indices to shift by. Default is 1.
|
:param shift: The number of indices to shift by. Default is 1.
|
||||||
:type shift: int, optional
|
:type shift: int, optional
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ def time_shift(signal: ArrayLike | Recording, shift: Optional[int] = 1) -> np.nd
|
||||||
|
|
||||||
:return: A numpy array which represents the time-shifted signal. If `signal` is a `Recording`,
|
:return: A numpy array which represents the time-shifted signal. If `signal` is a `Recording`,
|
||||||
returns a `Recording object` with its `data` attribute containing the time-shifted array.
|
returns a `Recording object` with its `data` attribute containing the time-shifted array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[1+1j, 2+2j, 3+3j, 4+4j, 5+5j]])
|
>>> rec = Recording(data=[[1+1j, 2+2j, 3+3j, 4+4j, 5+5j]])
|
||||||
>>> new_rec = time_shift(rec, -2)
|
>>> new_rec = time_shift(rec, -2)
|
||||||
|
|
@ -134,7 +134,7 @@ def frequency_shift(signal: ArrayLike | Recording, shift: Optional[float] = 0.5)
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param shift: The frequency shift relative to the sample rate. Must be in the range ``[-0.5, 0.5]``.
|
:param shift: The frequency shift relative to the sample rate. Must be in the range ``[-0.5, 0.5]``.
|
||||||
Default is 0.5.
|
Default is 0.5.
|
||||||
:type shift: float, optional
|
:type shift: float, optional
|
||||||
|
|
@ -144,7 +144,7 @@ def frequency_shift(signal: ArrayLike | Recording, shift: Optional[float] = 0.5)
|
||||||
|
|
||||||
:return: A numpy array which represents the frequency-shifted signal. If `signal` is a `Recording`,
|
:return: A numpy array which represents the frequency-shifted signal. If `signal` is a `Recording`,
|
||||||
returns a `Recording object` with its `data` attribute containing the frequency-shifted array.
|
returns a `Recording object` with its `data` attribute containing the frequency-shifted array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[1+1j, 2+2j, 3+3j, 4+4j]])
|
>>> rec = Recording(data=[[1+1j, 2+2j, 3+3j, 4+4j]])
|
||||||
>>> new_rec = frequency_shift(rec, -0.4)
|
>>> new_rec = frequency_shift(rec, -0.4)
|
||||||
|
|
@ -189,7 +189,7 @@ def phase_shift(signal: ArrayLike | Recording, phase: Optional[float] = np.pi) -
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param phase: The phase angle by which to rotate the IQ samples, in radians. Must be in the range ``[-π, π]``.
|
:param phase: The phase angle by which to rotate the IQ samples, in radians. Must be in the range ``[-π, π]``.
|
||||||
Default is π.
|
Default is π.
|
||||||
:type phase: float, optional
|
:type phase: float, optional
|
||||||
|
|
@ -199,7 +199,7 @@ def phase_shift(signal: ArrayLike | Recording, phase: Optional[float] = np.pi) -
|
||||||
|
|
||||||
:return: A numpy array which represents the phase-shifted signal. If `signal` is a `Recording`,
|
:return: A numpy array which represents the phase-shifted signal. If `signal` is a `Recording`,
|
||||||
returns a `Recording object` with its `data` attribute containing the phase-shifted array.
|
returns a `Recording object` with its `data` attribute containing the phase-shifted array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[1+1j, 2+2j, 3+3j, 4+4j]])
|
>>> rec = Recording(data=[[1+1j, 2+2j, 3+3j, 4+4j]])
|
||||||
>>> new_rec = phase_shift(rec, np.pi/2)
|
>>> new_rec = phase_shift(rec, np.pi/2)
|
||||||
|
|
@ -246,7 +246,7 @@ def iq_imbalance(
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param amplitude_imbalance: The IQ amplitude imbalance to apply, in dB. Default is 1.5.
|
:param amplitude_imbalance: The IQ amplitude imbalance to apply, in dB. Default is 1.5.
|
||||||
:type amplitude_imbalance: float, optional
|
:type amplitude_imbalance: float, optional
|
||||||
:param phase_imbalance: The IQ phase imbalance to apply, in radians. Default is π.
|
:param phase_imbalance: The IQ phase imbalance to apply, in radians. Default is π.
|
||||||
|
|
@ -260,7 +260,7 @@ def iq_imbalance(
|
||||||
|
|
||||||
:return: A numpy array which is the original signal with an applied IQ imbalance. If `signal` is a `Recording`,
|
:return: A numpy array which is the original signal with an applied IQ imbalance. If `signal` is a `Recording`,
|
||||||
returns a `Recording object` with its `data` attribute containing the IQ imbalanced signal array.
|
returns a `Recording object` with its `data` attribute containing the IQ imbalanced signal array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[2+18j, -34+2j, 3+9j]])
|
>>> rec = Recording(data=[[2+18j, -34+2j, 3+9j]])
|
||||||
>>> new_rec = iq_imbalance(rec, 1, np.pi, 2)
|
>>> new_rec = iq_imbalance(rec, 1, np.pi, 2)
|
||||||
|
|
@ -315,7 +315,7 @@ def resample(signal: ArrayLike | Recording, up: Optional[int] = 4, down: Optiona
|
||||||
|
|
||||||
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
:param signal: Input IQ data as a complex CxN array or `Recording`, where C is the number of channels and N
|
||||||
is the length of the IQ examples.
|
is the length of the IQ examples.
|
||||||
:type signal: array_like or ria_toolkit_oss.datatypes.Recording
|
:type signal: array_like or ria_toolkit_oss.data.Recording
|
||||||
:param up: The upsampling factor. Default is 4.
|
:param up: The upsampling factor. Default is 4.
|
||||||
:type up: int, optional
|
:type up: int, optional
|
||||||
:param down: The downsampling factor. Default is 2.
|
:param down: The downsampling factor. Default is 2.
|
||||||
|
|
@ -325,7 +325,7 @@ def resample(signal: ArrayLike | Recording, up: Optional[int] = 4, down: Optiona
|
||||||
|
|
||||||
:return: A numpy array which represents the resampled signal If `signal` is a `Recording`,
|
:return: A numpy array which represents the resampled signal If `signal` is a `Recording`,
|
||||||
returns a `Recording object` with its `data` attribute containing the resampled array.
|
returns a `Recording object` with its `data` attribute containing the resampled array.
|
||||||
:rtype: np.ndarray or ria_toolkit_oss.datatypes.Recording
|
:rtype: np.ndarray or ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
>>> rec = Recording(data=[[1+1j, 2+2j]])
|
>>> rec = Recording(data=[[1+1j, 2+2j]])
|
||||||
>>> new_rec = resample(rec, 2, 1)
|
>>> new_rec = resample(rec, 2, 1)
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ import scipy.signal as signal
|
||||||
from plotly.graph_objs import Figure
|
from plotly.graph_objs import Figure
|
||||||
from scipy.fft import fft, fftshift
|
from scipy.fft import fft, fftshift
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
|
|
||||||
|
|
||||||
def spectrogram(rec: Recording, thumbnail: bool = False) -> Figure:
|
def spectrogram(rec: Recording, thumbnail: bool = False) -> Figure:
|
||||||
"""Create a spectrogram for the recording.
|
"""Create a spectrogram for the recording.
|
||||||
|
|
||||||
:param rec: Signal to plot.
|
:param rec: Signal to plot.
|
||||||
:type rec: ria_toolkit_oss.datatypes.Recording
|
:type rec: ria_toolkit_oss.data.Recording
|
||||||
:param thumbnail: Whether to return a small thumbnail version or full plot.
|
:param thumbnail: Whether to return a small thumbnail version or full plot.
|
||||||
:type thumbnail: bool
|
:type thumbnail: bool
|
||||||
|
|
||||||
|
|
@ -95,7 +95,7 @@ def iq_time_series(rec: Recording) -> Figure:
|
||||||
"""Create a time series plot of the real and imaginary parts of signal.
|
"""Create a time series plot of the real and imaginary parts of signal.
|
||||||
|
|
||||||
:param rec: Signal to plot.
|
:param rec: Signal to plot.
|
||||||
:type rec: ria_toolkit_oss.datatypes.Recording
|
:type rec: ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:return: Time series plot as a Plotly figure.
|
:return: Time series plot as a Plotly figure.
|
||||||
"""
|
"""
|
||||||
|
|
@ -125,7 +125,7 @@ def frequency_spectrum(rec: Recording) -> Figure:
|
||||||
"""Create a frequency spectrum plot from the recording.
|
"""Create a frequency spectrum plot from the recording.
|
||||||
|
|
||||||
:param rec: Input signal to plot.
|
:param rec: Input signal to plot.
|
||||||
:type rec: ria_toolkit_oss.datatypes.Recording
|
:type rec: ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:return: Frequency spectrum as a Plotly figure.
|
:return: Frequency spectrum as a Plotly figure.
|
||||||
"""
|
"""
|
||||||
|
|
@ -160,7 +160,7 @@ def constellation(rec: Recording) -> Figure:
|
||||||
"""Create a constellation plot from the recording.
|
"""Create a constellation plot from the recording.
|
||||||
|
|
||||||
:param rec: Input signal to plot.
|
:param rec: Input signal to plot.
|
||||||
:type rec: ria_toolkit_oss.datatypes.Recording
|
:type rec: ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:return: Constellation as a Plotly figure.
|
:return: Constellation as a Plotly figure.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ from scipy.fft import fft, fftshift
|
||||||
from scipy.signal import spectrogram
|
from scipy.signal import spectrogram
|
||||||
from scipy.signal.windows import hann
|
from scipy.signal.windows import hann
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.view.tools import (
|
from ria_toolkit_oss.view.tools import (
|
||||||
COLORS,
|
COLORS,
|
||||||
decimate,
|
decimate,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import numpy as np
|
||||||
from scipy.fft import fft, fftshift
|
from scipy.fft import fft, fftshift
|
||||||
from scipy.signal.windows import hann
|
from scipy.signal.windows import hann
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.view.tools import (
|
from ria_toolkit_oss.view.tools import (
|
||||||
COLORS,
|
COLORS,
|
||||||
decimate,
|
decimate,
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ import scipy.signal as signal
|
||||||
from plotly.graph_objs import Figure
|
from plotly.graph_objs import Figure
|
||||||
from scipy.fft import fft, fftshift
|
from scipy.fft import fft, fftshift
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
|
|
||||||
|
|
||||||
def spectrogram(rec: Recording, thumbnail: bool = False) -> Figure:
|
def spectrogram(rec: Recording, thumbnail: bool = False) -> Figure:
|
||||||
"""Create a spectrogram for the recording.
|
"""Create a spectrogram for the recording.
|
||||||
|
|
||||||
:param rec: Signal to plot.
|
:param rec: Signal to plot.
|
||||||
:type rec: ria_toolkit_oss.datatypes.Recording
|
:type rec: ria_toolkit_oss.data.Recording
|
||||||
:param thumbnail: Whether to return a small thumbnail version or full plot.
|
:param thumbnail: Whether to return a small thumbnail version or full plot.
|
||||||
:type thumbnail: bool
|
:type thumbnail: bool
|
||||||
|
|
||||||
|
|
@ -107,7 +107,7 @@ def iq_time_series(rec: Recording) -> Figure:
|
||||||
"""Create a time series plot of the real and imaginary parts of signal.
|
"""Create a time series plot of the real and imaginary parts of signal.
|
||||||
|
|
||||||
:param rec: Signal to plot.
|
:param rec: Signal to plot.
|
||||||
:type rec: ria_toolkit_oss.datatypes.Recording
|
:type rec: ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:return: Time series plot, as a Plotly Figure.
|
:return: Time series plot, as a Plotly Figure.
|
||||||
"""
|
"""
|
||||||
|
|
@ -145,7 +145,7 @@ def frequency_spectrum(rec: Recording) -> Figure:
|
||||||
"""Create a frequency spectrum plot from the recording.
|
"""Create a frequency spectrum plot from the recording.
|
||||||
|
|
||||||
:param rec: Input signal to plot.
|
:param rec: Input signal to plot.
|
||||||
:type rec: ria_toolkit_oss.datatypes.Recording
|
:type rec: ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:return: Frequency spectrum, as a Plotly figure.
|
:return: Frequency spectrum, as a Plotly figure.
|
||||||
"""
|
"""
|
||||||
|
|
@ -187,7 +187,7 @@ def constellation(rec: Recording) -> Figure:
|
||||||
"""Create a constellation plot from the recording.
|
"""Create a constellation plot from the recording.
|
||||||
|
|
||||||
:param rec: Input signal to plot.
|
:param rec: Input signal to plot.
|
||||||
:type rec: ria_toolkit_oss.datatypes.Recording
|
:type rec: ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:return: Constellation, as a Plotly Figure.
|
:return: Constellation, as a Plotly Figure.
|
||||||
"""
|
"""
|
||||||
|
|
@ -222,7 +222,7 @@ def power_spectral_density(rec: Recording) -> Figure:
|
||||||
"""Create a Power Spectral Density (PSD) plot from the recording.
|
"""Create a Power Spectral Density (PSD) plot from the recording.
|
||||||
|
|
||||||
:param rec: Input signal to plot.
|
:param rec: Input signal to plot.
|
||||||
:type rec: ria_toolkit_oss.datatypes.Recording
|
:type rec: ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:return: PSD plot, as a Plotly Figure.
|
:return: PSD plot, as a Plotly Figure.
|
||||||
"""
|
"""
|
||||||
|
|
@ -268,7 +268,7 @@ def fft_plot(rec: Recording) -> Figure:
|
||||||
"""Create an FFT magnitude plot from the recording.
|
"""Create an FFT magnitude plot from the recording.
|
||||||
|
|
||||||
:param rec: Input signal to plot.
|
:param rec: Input signal to plot.
|
||||||
:type rec: ria_toolkit_oss.datatypes.Recording
|
:type rec: ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:return: FFT plot, as a Plotly Figure.
|
:return: FFT plot, as a Plotly Figure.
|
||||||
"""
|
"""
|
||||||
|
|
@ -312,7 +312,7 @@ def spectrogram_3d(rec: Recording) -> Figure:
|
||||||
"""Create a 3D spectrogram plot from the recording.
|
"""Create a 3D spectrogram plot from the recording.
|
||||||
|
|
||||||
:param rec: Input signal to plot.
|
:param rec: Input signal to plot.
|
||||||
:type rec: ria_toolkit_oss.datatypes.Recording
|
:type rec: ria_toolkit_oss.data.Recording
|
||||||
|
|
||||||
:return: 3D Spectrogram, as a Plotly Figure.
|
:return: 3D Spectrogram, as a Plotly Figure.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ from ria_toolkit_oss.annotations import (
|
||||||
split_recording_annotations,
|
split_recording_annotations,
|
||||||
threshold_qualifier,
|
threshold_qualifier,
|
||||||
)
|
)
|
||||||
from ria_toolkit_oss.datatypes import Annotation
|
from ria_toolkit_oss.data import Annotation
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.io import load_recording, to_blue, to_npy, to_sigmf, to_wav
|
from ria_toolkit_oss.io import load_recording, to_blue, to_npy, to_sigmf, to_wav
|
||||||
from ria_toolkit_oss_cli.ria_toolkit_oss.common import (
|
from ria_toolkit_oss_cli.ria_toolkit_oss.common import (
|
||||||
format_frequency,
|
format_frequency,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from pathlib import Path
|
||||||
import click
|
import click
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
from ria_toolkit_oss.io import from_npy_legacy, load_recording
|
from ria_toolkit_oss.io import from_npy_legacy, load_recording
|
||||||
from ria_toolkit_oss_cli.ria_toolkit_oss.common import (
|
from ria_toolkit_oss_cli.ria_toolkit_oss.common import (
|
||||||
echo_progress,
|
echo_progress,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from typing import Any, Dict, List, Optional
|
||||||
import click
|
import click
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.io.recording import to_blue, to_npy, to_sigmf, to_wav
|
from ria_toolkit_oss.io.recording import to_blue, to_npy, to_sigmf, to_wav
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import numpy as np
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
import ria_toolkit_oss.signal.basic_signal_generator as basic_gen
|
import ria_toolkit_oss.signal.basic_signal_generator as basic_gen
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
from ria_toolkit_oss.signal.block_generator.basic import FrequencyShift
|
from ria_toolkit_oss.signal.block_generator.basic import FrequencyShift
|
||||||
from ria_toolkit_oss.signal.block_generator.continuous_modulation.fsk_modulator import (
|
from ria_toolkit_oss.signal.block_generator.continuous_modulation.fsk_modulator import (
|
||||||
FSKModulator,
|
FSKModulator,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from pathlib import Path
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.io.recording import load_recording
|
from ria_toolkit_oss.io.recording import load_recording
|
||||||
from ria_toolkit_oss.transforms import iq_augmentations, iq_impairments
|
from ria_toolkit_oss.transforms import iq_augmentations, iq_impairments
|
||||||
from ria_toolkit_oss_cli.ria_toolkit_oss.common import (
|
from ria_toolkit_oss_cli.ria_toolkit_oss.common import (
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import time
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
from ria_toolkit_oss.io import from_npy_legacy, load_recording
|
from ria_toolkit_oss.io import from_npy_legacy, load_recording
|
||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from ria_toolkit_oss.datatypes import Annotation
|
from ria_toolkit_oss.data import Annotation
|
||||||
|
|
||||||
|
|
||||||
def test_annotation_creation():
|
def test_annotation_creation():
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ from typing import Iterable
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Annotation, Recording
|
from ria_toolkit_oss.data import Annotation, Recording
|
||||||
from ria_toolkit_oss.datatypes.recording import generate_recording_id
|
from ria_toolkit_oss.data.recording import generate_recording_id
|
||||||
|
|
||||||
COMPLEX_DATA_1 = [[0.5 + 0.5j, 0.1 + 0.1j, 0.3 + 0.3j, 0.4 + 0.4j, 0.5 + 0.5j]]
|
COMPLEX_DATA_1 = [[0.5 + 0.5j, 0.1 + 0.1j, 0.3 + 0.3j, 0.4 + 0.4j, 0.5 + 0.5j]]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Annotation, Recording
|
from ria_toolkit_oss.data import Annotation, Recording
|
||||||
from ria_toolkit_oss.io.recording import (
|
from ria_toolkit_oss.io.recording import (
|
||||||
from_npy,
|
from_npy,
|
||||||
from_sigmf,
|
from_sigmf,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import time
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.orchestration.campaign import CaptureStep
|
from ria_toolkit_oss.orchestration.campaign import CaptureStep
|
||||||
from ria_toolkit_oss.orchestration.labeler import build_output_filename, label_recording
|
from ria_toolkit_oss.orchestration.labeler import build_output_filename, label_recording
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes.recording import Recording
|
from ria_toolkit_oss.data.recording import Recording
|
||||||
from ria_toolkit_oss.orchestration.campaign import QAConfig
|
from ria_toolkit_oss.orchestration.campaign import QAConfig
|
||||||
from ria_toolkit_oss.orchestration.qa import QAResult, check_recording, estimate_snr_db
|
from ria_toolkit_oss.orchestration.qa import QAResult, check_recording, estimate_snr_db
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Annotation, Recording
|
from ria_toolkit_oss.data import Annotation, Recording
|
||||||
from ria_toolkit_oss.io import load_recording, to_npy, to_sigmf
|
from ria_toolkit_oss.io import load_recording, to_npy, to_sigmf
|
||||||
from ria_toolkit_oss_cli.cli import cli
|
from ria_toolkit_oss_cli.cli import cli
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Annotation, Recording
|
from ria_toolkit_oss.data import Annotation, Recording
|
||||||
from ria_toolkit_oss.io import load_recording, to_sigmf
|
from ria_toolkit_oss.io import load_recording, to_sigmf
|
||||||
from ria_toolkit_oss_cli.cli import cli
|
from ria_toolkit_oss_cli.cli import cli
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
from ria_toolkit_oss.transforms import iq_augmentations
|
from ria_toolkit_oss.transforms import iq_augmentations
|
||||||
|
|
||||||
TEST_DATA1 = [[1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j]]
|
TEST_DATA1 = [[1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j]]
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ Bugs/issues identified during review:
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from ria_toolkit_oss.datatypes import Recording
|
from ria_toolkit_oss.data import Recording
|
||||||
from ria_toolkit_oss.transforms import iq_impairments
|
from ria_toolkit_oss.transforms import iq_impairments
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user