diff --git a/src/pandablocks/connections.py b/src/pandablocks/connections.py index 23015521..11a33524 100644 --- a/src/pandablocks/connections.py +++ b/src/pandablocks/connections.py @@ -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] diff --git a/src/pandablocks/hdf.py b/src/pandablocks/hdf.py index 995cc2ab..9633c943 100644 --- a/src/pandablocks/hdf.py +++ b/src/pandablocks/hdf.py @@ -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] diff --git a/src/pandablocks/responses.py b/src/pandablocks/responses.py index 005e4891..f68039de 100644 --- a/src/pandablocks/responses.py +++ b/src/pandablocks/responses.py @@ -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): @@ -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 diff --git a/tests/test_hdf.py b/tests/test_hdf.py index 1503ad7a..3f73ab4b 100644 --- a/tests/test_hdf.py +++ b/tests/test_hdf.py @@ -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( @@ -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( @@ -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",