Skip to content
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

Issue #10: Provide additional meta data #11

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ To run the tests, run the following command:

```sh
$ pip install tox
$ tox -e pytest
$ tox -e test
```

This will run all the tests for the package and report any issues or failures. Make sure that you have installed the necessary dependencies before running the tests.
Expand Down
9 changes: 6 additions & 3 deletions src/RsWaveform/wv/Load.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def load(self, file: typing.Union[str, typing.IO, Path]) -> ParentStorage:
content = fp.read()

tags = self._split_data_via_tags_meta(content)
samples = int(tags.pop("samples"))
samples = int(tags["samples"])
mwv_segment_count = int(tags.pop("mwv_segment_count", 1))

tags.update(self._split_data_via_tags_waveform(content))
Expand Down Expand Up @@ -135,7 +135,7 @@ def load_meta(self, file: typing.Union[str, typing.IO, Path]) -> ParentStorage:
header_content, _ = self._read_chunks(fp, separators)

tags = self._split_data_via_tags_meta(header_content)
samples = int(tags.pop("samples"))
samples = int(tags["samples"])
tags.update(
self._split_data_via_tags_control_list_width4(header_content, samples)
)
Expand Down Expand Up @@ -257,7 +257,9 @@ def _extract_meta(tags: dict, index: int = 0) -> dict:
marker.update({key: marker_list})
continue
elif key == "samples":
continue
value = int(value)
elif key == "reflevel":
value = float(value)
elif key == "mwv_segment_level_offs":
possible_values = value.split(",")
offset = possible_values[index * 2]
Expand Down Expand Up @@ -415,6 +417,7 @@ def _get_regex_tokens() -> list:
("DATE", r"", r"[\d\-;\:]+"), # Timestamp of waveform
("SAMPLES", r"", r"[\de\-\+]+"), # Sample count
("CLOCK", r"", r"[\d\.e\-\+]+"), # Waveform sampling frequency
("REFLEVEL", r"", r"[\d\.e\-\+]+"), # Reference level for playback
("VECTOR MAX", r"", r"[\d\.\-e\+]+"), # tbd
("LEVEL OFFS", r"", r"([\d\.\-e\+]+),([\d\.\-e\+]+)"),
# Level offset to dBFS
Expand Down
9 changes: 9 additions & 0 deletions src/RsWaveform/wv/Save.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def _write(
self._write_date(fp, data)
self._write_clock(fp, data.storages[0])
self._write_samples(fp, data.storages[0])
self._write_reflevel(fp, data.storages[0])

self._write_control_length(fp, data.storages[0])
self._write_control_list(fp, data.storages[0])
Expand Down Expand Up @@ -79,6 +80,7 @@ def _write_mwv(
self._write_copyright(fp, tmp_storage)
self._write_date(fp, datas)
self._write_samples(fp, tmp_storage)
self._write_reflevel(fp, tmp_storage)

self._write_mwv_segment_count(fp, datas)
self._write_mwv_segment_length(fp, datas.storages)
Expand Down Expand Up @@ -168,6 +170,13 @@ def _write_samples(file: typing.IO, data: Storage):
line = f"{{SAMPLES:{len(data.data)}}}"
file.write(line.encode("utf-8"))

@staticmethod
def _write_reflevel(file: typing.IO, data: Storage):
reflevel = data.meta.get("reflevel")
if reflevel:
line = f"{{REFLEVEL:{reflevel:.6f}}}"
file.write(line.encode("utf-8"))

@staticmethod
def _write_marker(file: typing.IO, data: Storage):
marker_keys = [
Expand Down
2 changes: 1 addition & 1 deletion tests/data/dummy.wv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{TYPE:SMU-WV}{COPYRIGHT:Rohde & Schwarz}{COMMENT:Test waveform file}{LEVEL OFFS:2.220459,0.000000}{DATE:2023-01-05;10:03:52}{CLOCK:100000000.0}{SAMPLES:2}{CONTROL LENGTH:2}{CONTROL LIST WIDTH4-2:#i}{MARKER LIST 1: 0:1;32:0;63:0}{EMPTYTAG-223:# }{WAVEFORM-9:#š33ÍLff}
{TYPE:SMU-WV}{COPYRIGHT:Rohde & Schwarz}{COMMENT:Test waveform file}{LEVEL OFFS:2.220459,0.000000}{DATE:2023-01-05;10:03:52}{CLOCK:100000000.0}{SAMPLES:2}{REFLEVEL:-20.000000}{CONTROL LENGTH:2}{CONTROL LIST WIDTH4-2:#i}{MARKER LIST 1: 0:1;32:0;63:0}{EMPTYTAG-223:# }{WAVEFORM-9:#š33ÍLff}
2 changes: 1 addition & 1 deletion tests/data/dummy_2.wv
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{TYPE:SMU-WV}{COPYRIGHT:Rohde & Schwarz}{COMMENT:Test waveform file}{LEVEL OFFS:2.220459,0.000000}{DATE:2023-01-05;10:03:52}{CLOCK:100000000.0}{SAMPLES:2}{CONTROL LENGTH:2}{CONTROL LIST WIDTH4-2:#i}{MARKER LIST 1: 0:1;32:0;63:0}{EMPTYTAG-223:# }{WAVEFORM-9:#š33ÍLff}
{TYPE:SMU-WV}{COPYRIGHT:Rohde & Schwarz}{COMMENT:Test waveform file}{LEVEL OFFS:2.220459,0.000000}{DATE:2023-01-05;10:03:52}{CLOCK:100000000.0}{SAMPLES:2}{REFLEVEL:-20.000000}{CONTROL LENGTH:2}{CONTROL LIST WIDTH4-2:#i}{MARKER LIST 1: 0:1;32:0;63:0}{EMPTYTAG-223:# }{WAVEFORM-9:#š33ÍLff}
Binary file modified tests/data/dummy_mwv.wv
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/test_wv.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def meta() -> Meta:
"encryption_flag": False,
"rms": 2.220459,
"peak": 0.0,
"samples": 2,
"reflevel": -20.0,
}
)

Expand All @@ -60,6 +62,8 @@ def meta_mwv() -> Meta:
"encryption_flag": False,
"rms": 200.0,
"peak": 200.0,
"samples": 2000,
"reflevel": -10.0,
}
)

Expand Down
Loading