Skip to content

Conversation

tekperson
Copy link
Contributor

Proposed Changes

This PR addresses two main areas:

1. WFM Type Detection Fix

  • Fixed issue where digital and IQ waveform files were incorrectly identified as analog waveforms
  • Implemented proper type detection logic in WFM format classes:
    • WaveformFileWFMDigital: Detects digital waveforms by data_type == 6
    • WaveformFileWFMIQ: Detects IQ waveforms by the presence of IQ-specific metadata fields
    • WaveformFileWFMAnalog: Acts as a fallback for non-digital, non-IQ waveforms

2. Metadata System Usability Improvements

  • Enhanced error messages with helpful guidance for custom metadata access
  • 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 with practical examples
  • Enhanced file format compatibility documentation

Testing

  • Verified backwards compatibility maintained
  • Basic functionality tests pass
  • Changes tested locally to ensure proper operation

Checklist

  • Followed CONTRIBUTING guidelines
  • Signed CLA
  • Self-review completed
  • Code follows style guidelines
  • Added comprehensive documentation
  • Updated CHANGELOG.md
  • Basic functionality verified

Notes

  • Maintains 100% backwards compatibility
  • Addresses usability issues identified
  • Ready for review and testing

tekperson added 7 commits May 29, 2025 13:56
…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
@tekperson tekperson requested a review from a team as a code owner September 3, 2025 14:19
Copy link
Collaborator

@nfelt14 nfelt14 left a 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:
Copy link
Collaborator

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:

Suggested change
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Example:
Examples:

raise an AttributeError with helpful guidance on how to add the field.
"""

def __getattr__(self, name: str) -> Any:
Copy link
Collaborator

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?

Copy link
Collaborator

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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):
Copy link
Collaborator

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.
Copy link
Collaborator

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
Copy link
Collaborator

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.

@nfelt14
Copy link
Collaborator

nfelt14 commented Sep 3, 2025

This branch needs to be rebased on top of main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants