-
Notifications
You must be signed in to change notification settings - Fork 7
Fix/wfm waveform type detection #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ersion, better field separation, and enhanced metadata preservation
…d waveform.py. Handle all fields and ensure clean output.
- Add proper _check_metadata() methods to each WFM format class - Digital waveforms identified by data_type == 6 (DataTypes.DIGITAL) - IQ waveforms identified by presence of IQ-specific metadata fields - Analog waveforms as default case when neither digital nor IQ - Prevents all format classes from returning True for any valid WFM file - Resolves issue where digital and IQ waveforms were incorrectly read as analog
- Enhanced error messages with helpful guidance for custom metadata - Added set_custom_metadata() convenience method for easier metadata management - Improved remap() method with better warnings and documentation - Added comprehensive docstrings to all metadata classes and methods - Enhanced WaveformMetaInfo, AnalogWaveformMetaInfo, DigitalWaveformMetaInfo, and IQWaveformMetaInfo - Added detailed field-level documentation for extended_metadata - Included practical examples and file format compatibility notes - Maintains 100% backwards compatibility Addresses usability issues identified in suggestions.md while keeping the API stable.
- Added entries for WFM type detection fix - Added entries for metadata system usability improvements - Documented new set_custom_metadata() method - Documented enhanced error messages and docstrings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test marked as xfail needs that marker removed, it should pass now.
- interpreter_factor: Factor used for data interpretation | ||
- real_data_start_index: Index where real data starts | ||
Example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proper docstring syntax is Examples:
Example: | |
Examples: |
- digital_probe_0_name through digital_probe_7_name: Names of digital probes | ||
- digital_probe_0_unit through digital_probe_7_unit: Units for digital probes | ||
Example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example: | |
Examples: |
for digital probe states and digital signal information. | ||
Digital-specific fields: | ||
- digital_probe_0_state through digital_probe_7_state: State of digital probes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about 16-bit digital probes?
- iq_window_type: Type of window function used | ||
- iq_sample_rate: Sample rate of the IQ signal | ||
Example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example: | |
Examples: |
raise an AttributeError with helpful guidance on how to add the field. | ||
""" | ||
|
||
def __getattr__(self, name: str) -> Any: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for the entire dataclass or just the extended metadata? Won't this break normal getattr calls on the dataclass? What about the attributes that aren't part of the extended metadata?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking specifically about subclasses.
raise AttributeError( | ||
f"{type(self).__name__} object has no attribute {name!r}. " | ||
f"Available custom metadata keys: {available_keys}. " | ||
f"To add this field: meta_info.extended_metadata['{name}'] = your_value" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f"To add this field: meta_info.extended_metadata['{name}'] = your_value" | |
f"To add this field use: meta_info.extended_metadata['{name}'] = your_value" |
remapped = self.META_DATA_TYPE.remap(self._META_DATA_LOOKUP.inverse, formatted_data.meta_data) | ||
|
||
# Convert bytes to strings for string-like metadata | ||
def convert_bytes_to_str(value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be useful as a helper function outside this function.
|
||
# Reading | ||
def _check_metadata(self, meta_data: Dict[str, Any]) -> bool: | ||
"""Check if metadata indicates this is an analog waveform. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend encapsulating this behavior into a helper function that returns an enum. Then that single function can be called in multiple places and the output checked to determine the boolean return value for this function.
Something like this:
return get_wfm_type(meta_data) == WfmType.ANALOG
|
||
return remapped_dict | ||
|
||
extended_metadata: Optional[Dict[str, Any]] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move the dataclass attribute above the methods? That is a more standard organization for dataclasses.
This branch needs to be rebased on top of main |
Proposed Changes
This PR addresses two main areas:
1. WFM Type Detection Fix
WaveformFileWFMDigital
: Detects digital waveforms bydata_type == 6
WaveformFileWFMIQ
: Detects IQ waveforms by the presence of IQ-specific metadata fieldsWaveformFileWFMAnalog
: Acts as a fallback for non-digital, non-IQ waveforms2. Metadata System Usability Improvements
set_custom_metadata()
convenience method for easier metadata managementremap()
method with better warnings and documentationTesting
Checklist
Notes