torchsig.signals.signal_types.SignalMetadataObject¶
- class torchsig.signals.signal_types.SignalMetadataObject(**kwargs: Any)[source]¶
Bases:
HierarchicalMetadataObjectRepresents metadata associated with a signal.
This class extends HierarchicalMetadataObject to provide signal-specific metadata properties and calculations.
Methods
Add parent Seedable object and set up RNGs accordingly.
Create a copy of the object.
Create distribution function with proper seeding.
Function for modifying and returning a new metadata with all the fields in parent or child, with child overriding parent in conflicts.
Gets second seed, usually used to seed both torch and numpy generators with slightly different seeds.
Lookup a metadata key with enhanced error reporting.
Get all metadata keys.
Seed number generators with given seed.
Initialize torch and numpy number generators, and update its children.
Returns SignalMetadataExternal as a full dictionary.
Update numpy and torch number generators with parent seed.
Attributes
Signal duration normalized to 0-1.0.
Calculates the lower frequency of a signal.
Calculates the oversampling rate for a signal.
Signal start normalized to duration of signal.
Signal stop normalized to duration of signal.
Signal stop in samples.
Calculates the upper frequency of a signal.
- __init__(**kwargs: Any) None[source]¶
Initializes the SignalMetadata object.
- Parameters:
**kwargs – Metadata key-value pairs to initialize the object.
- property start: float¶
Signal start normalized to duration of signal.
- Returns:
Signal start as a percentage of total time (0-1).
- Return type:
- property stop: float¶
Signal stop normalized to duration of signal.
- Returns:
Signal stop as a percentage of total time (0-1).
- Return type:
- property duration: float¶
Signal duration normalized to 0-1.0.
- Returns:
Signal duration as a percentage of total time (0-1).
- Return type:
- property stop_in_samples: int¶
Signal stop in samples.
- Returns:
Signal stop time in samples.
- Return type:
- property upper_freq: float¶
Calculates the upper frequency of a signal.
- Returns:
Upper frequency in Hz.
- Return type:
- Raises:
ValueError – If center_freq or bandwidth are not available.
- property lower_freq: float¶
Calculates the lower frequency of a signal.
- Returns:
Lower frequency in Hz.
- Return type:
- Raises:
ValueError – If center_freq or bandwidth are not available.
- property oversampling_rate: float¶
Calculates the oversampling rate for a signal.
- Returns:
Oversampling rate (sample_rate / bandwidth).
- Return type:
- to_dict() dict[str, Any][source]¶
Returns SignalMetadataExternal as a full dictionary.
- Returns:
Dictionary containing all metadata attributes.
- Return type:
Dict[str, Any]
- __repr__() str¶
Printable representation with seed and parent.
- Returns:
String representation of the object.
- add_parent(parent: Seedable, register: bool = True) None¶
Add parent Seedable object and set up RNGs accordingly.
- Parameters:
parent – Parent Seedable object to add.
register – If True (default), add self to parent.children so that future seed propagation reaches this object. Pass False for transient objects (e.g. per-sample Signal instances) that only need the parent link for metadata/RNG access during their lifetime but must not accumulate in the parent’s child list, which would otherwise cause unbounded memory growth.
- copy() HierarchicalMetadataObject¶
Create a copy of the object.
- Returns:
A new instance of the same class with the same metadata and parent.
Example
>>> obj = HierarchicalMetadataObject(metadata={"key": "value"}) >>> copy_obj = obj.copy() >>> copy_obj["key"] 'value'
- get_distribution(params: list | tuple | float, scaling: str = 'linear') Distribution¶
Create distribution function with proper seeding.
- Parameters:
params – Parameters for distribution.
scaling – Scaling param for distribution. Defaults to ‘linear’.
- Returns:
Distribution function, seeded.
- Return type:
- get_full_metadata() dict[str, Any]¶
Function for modifying and returning a new metadata with all the fields in parent or child, with child overriding parent in conflicts.
- Returns:
Dictionary containing all metadata from parent and child, with child values overriding parent values in case of conflicts.
Example
>>> parent = HierarchicalMetadataObject(metadata={"field_1": 4, "field_2": 5}) >>> child = HierarchicalMetadataObject(parent=parent, metadata={"field_2": 6}) >>> child.get_full_metadata() {'field_1': 4, 'field_2': 6}
- get_second_seed(seed: int) int¶
Gets second seed, usually used to seed both torch and numpy generators with slightly different seeds.
- Parameters:
seed – Seed to use.
- Returns:
New seed.
- key_lookup(key: str) Any¶
Lookup a metadata key with enhanced error reporting.
- Parameters:
key – The metadata key to lookup.
- Returns:
The value associated with the key.
- Raises:
MetadataAttributeError – If the key is not found in the metadata or parent metadata.
Example
>>> obj = HierarchicalMetadataObject(metadata={"key": "value"}) >>> obj.key_lookup("key") 'value'