Skip to content

Commit

Permalink
Merge pull request #2 from lobis/1-only-half-of-values-is-read-from-t…
Browse files Browse the repository at this point in the history
…he-file-recorded-with-wavepro-hd

Fix not reading correct number of bytes
  • Loading branch information
lobis committed May 25, 2023
2 parents 8acad69 + 4553082 commit 2f627b4
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 32 deletions.
15 changes: 14 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: requirements-txt-fixer
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.3.0
hooks:
- id: black
41 changes: 24 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
MIT License
BSD 3-Clause License

Copyright (c) 2022 Luis Antonio Obis Aparicio
Copyright (c) 2023 Luis Antonio Obis Aparicio

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ requires = [
]
build-backend = "hatchling.build"


[project]
name = "lecroyscope"
authors = [
{ name = "Luis Antonio Obis Aparicio", email = "[email protected]" },
]
requires-python = ">=3.8"
description = "An unofficial Python package 🐍📦 to interface with Teledyne LeCroy oscilloscopes and read binary trace files (.trc)"
readme = "README.md"
requires-python = ">=3.8"
license = "BSD-3-Clause"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
]
keywords = [
"lecroy",
"scope",
"oscilloscope",
"vxi11",
"binary",
"trc",
]
dependencies = [
"numpy",
"python-vxi11",
Expand Down
6 changes: 4 additions & 2 deletions src/lecroyscope/reading/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def read(
with open(filename_or_bytes, "r+b") if not isinstance(
filename_or_bytes, bytes
) else BytesIO(filename_or_bytes) as f:

wavedesc_bytes = b"WAVEDESC"
# find "WAVEDESC" and skip those bytes
if isinstance(filename_or_bytes, bytes):
Expand Down Expand Up @@ -112,8 +111,11 @@ def read(
f.read(int(header["trig_time_array"])), dtype=numpy.float64
)

number_of_bytes_to_read = (
int(header["wave_array_count"]) * values_type().itemsize
)
values = numpy.frombuffer(
f.read(int(header["wave_array_count"])), dtype=values_type
f.read(number_of_bytes_to_read), dtype=values_type
)
else:
trigger_times = numpy.array([], dtype=numpy.float64)
Expand Down
4 changes: 4 additions & 0 deletions src/lecroyscope/reading/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def __init__(
+ self.header["horiz_offset"]
)

assert (
self._voltage.shape[-1] == self._time.shape[-1]
), "Time and voltage arrays must have the same length"

def __len__(self):
if not self._header.sequence:
return 1
Expand Down
2 changes: 1 addition & 1 deletion src/lecroyscope/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "0.0.5"
__version__ = "1.0.0"
version = __version__
Binary file added tests/files/issue_1.trc
Binary file not shown.
8 changes: 6 additions & 2 deletions tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ def test_read_header_from_bytes():

def test_read_data_from_file():
for filename, shape in zip(
[files_path / "pulse.trc", files_path / "pulse_sequence.trc"],
[(251,), (20, 251)],
[
files_path / "pulse.trc",
files_path / "pulse_sequence.trc",
files_path / "issue_1.trc",
],
[(502,), (20, 502), (100002,)],
):
(
header_from_file,
Expand Down
16 changes: 10 additions & 6 deletions tests/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,24 @@ def test_trace_channel_from_filename(tmp_path):

def test_read_trace_from_file():
for filename, shape, length, sequence in zip(
[files_path / "pulse.trc", files_path / "pulse_sequence.trc"],
[(251,), (20, 251)],
[1, 20],
[False, True],
[
files_path / "pulse.trc",
files_path / "pulse_sequence.trc",
files_path / "issue_1.trc",
],
[(502,), (20, 502), (100002,)],
[1, 20, 1],
[False, True, False],
):
trace = lecroyscope.Trace(filename)
assert len(trace) == length
assert trace.header_only is False
assert trace.sequence == sequence
assert trace.voltage.shape == shape
assert trace.time.shape == (251,)
assert trace.time.shape == shape[-1:]
assert (trace.voltage.shape[-1],) == trace.time.shape

if not sequence:
if filename == files_path / "pulse.trc":
# check voltage and time scaling is done properly
# test against signal which consists of ~ 0V baseline + sharp pulse at trigger time
# first bins should be ~ 0V since we are on the region before pulse
Expand Down
1 change: 0 additions & 1 deletion tests/test_trace_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def test_trace_group_from_files(tmp_path):
lecroyscope.TraceGroup(*filenames),
lecroyscope.TraceGroup(tmp_path / "C*Trace00001.trc"),
]:

for i, trace in enumerate(trace_group):
assert isinstance(trace, lecroyscope.Trace)
# this checks sorting too! (glob order is not the same across platforms)
Expand Down

0 comments on commit 2f627b4

Please sign in to comment.