Skip to content

Commit

Permalink
changed PCAP.SAMPLES to have None in fields
Browse files Browse the repository at this point in the history
Thus it will use a `uint32` datatype.
  • Loading branch information
evalott100 committed Jul 11, 2024
1 parent 7c311c5 commit cd0261f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/pandablocks/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,14 @@ def _handle_header_body(self):
name, capture = SAMPLES_FIELD.rsplit(".", maxsplit=1)
fields.insert(
0,
FieldCapture(name, np.dtype("uint32"), capture, 1.0, 0.0, ""),
FieldCapture(
name=name,
type=np.dtype("uint32"),
capture=capture,
scale=None,
offset=None,
units=None,
),
)
self._frame_dtype = np.dtype(
[(f"{f.name}.{f.capture}", f.type) for f in fields]
Expand Down
6 changes: 5 additions & 1 deletion src/pandablocks/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ def mean_callable(data):
return (data[column_name] * field.scale / gate_duration) + field.offset

return mean_callable
elif raw and not field.is_pcap_bits and (field.scale != 1 or field.offset != 0):
elif (
raw
and not field.is_pcap_bits_or_samples
and (field.scale != 1 or field.offset != 0)
):
return lambda data: data[column_name] * field.scale + field.offset
else:
return lambda data: data[column_name]
Expand Down
9 changes: 5 additions & 4 deletions src/pandablocks/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ class FieldCapture:

@property
def raw_mode_dataset_dtype(self) -> np.dtype:
"""We use double for all dtypes, unless the field is a PCAP.BITS."""
"""We use double for all dtypes,
unless the field is a PCAP.BITS or PCAP.SAMPLES."""

if self.is_pcap_bits:
if self.is_pcap_bits_or_samples:
return self.type

if None in (self.scale, self.offset, self.units):
Expand All @@ -257,8 +258,8 @@ def raw_mode_dataset_dtype(self) -> np.dtype:
return np.dtype("float64")

@property
def is_pcap_bits(self) -> bool:
"""Return True if this field is a PCAP.BITS field"""
def is_pcap_bits_or_samples(self) -> bool:
"""Return True if this field is a PCAP.BITS or PCAP.SAMPLES field"""
return self.scale is None and self.offset is None and self.units is None


Expand Down
6 changes: 3 additions & 3 deletions tests/test_hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_field_capture_pcap_bits():
units=None,
)

assert pcap_bits_frame_data.is_pcap_bits
assert pcap_bits_frame_data.is_pcap_bits_or_samples
assert pcap_bits_frame_data.raw_mode_dataset_dtype is np.dtype("uint32")

some_other_frame_data = FieldCapture(
Expand All @@ -83,7 +83,7 @@ def test_field_capture_pcap_bits():
units="",
)

assert not some_other_frame_data.is_pcap_bits
assert not some_other_frame_data.is_pcap_bits_or_samples
assert some_other_frame_data.raw_mode_dataset_dtype is np.dtype("float64")

malformed_frame_data = FieldCapture(
Expand All @@ -95,7 +95,7 @@ def test_field_capture_pcap_bits():
units="",
)

assert not some_other_frame_data.is_pcap_bits
assert not some_other_frame_data.is_pcap_bits_or_samples
with pytest.raises(
ValueError,
match="If any of `scale`, `offset`, or `units` is set, all must be set",
Expand Down

0 comments on commit cd0261f

Please sign in to comment.