Skip to content

Commit

Permalink
#62 raw voltage option in convenience acquisition methods
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbaker committed Jun 26, 2024
1 parent b269f97 commit 34d4d1f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ package_dir =
= src
include_package_data = True
install_requires =
numpy>=1.21.4
numpy>=1.26.2
python_requires = >=3.8

[options.packages.find]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from abc import ABC
from typing import List

from spectrumdevice.measurement import Measurement
from spectrumdevice.measurement import Measurement, RawWaveformType, VoltageWaveformType
from spectrumdevice.devices.abstract_device import AbstractSpectrumDevice
from spectrumdevice.devices.digitiser.digitiser_interface import (
SpectrumDigitiserAnalogChannelInterface,
Expand Down Expand Up @@ -76,14 +76,18 @@ def configure_acquisition(self, settings: AcquisitionSettings) -> None:
if settings.timestamping_enabled:
self.enable_timestamping()

def execute_standard_single_acquisition(self) -> Measurement:
def execute_standard_single_acquisition(self, raw: bool = False) -> Measurement:
"""Carry out a single measurement in standard single mode and return the acquired waveforms.
This method automatically carries out a standard single mode acquisition, including handling the creation
of a `TransferBuffer` and the retrieval of the acquired waveforms. After being called, it will wait until a
trigger event is received before carrying out the acquisition and then transferring and returning the acquired
waveforms. The device must be configured in SPC_REC_STD_SINGLE acquisition mode.
Args:
raw (bool, optional): Set to true to obtain raw (i.e. 16-bit integer) waveforms, instead of floating point
voltage waveforms.
Returns:
measurement (Measurement): A Measurement object. The `.waveforms` attribute of `measurement` will be a list
of 1D NumPy arrays, each array containing the waveform data received on one channel, in channel order.
Expand All @@ -101,11 +105,13 @@ def execute_standard_single_acquisition(self) -> Measurement:
self.define_transfer_buffer()
self.start_transfer()
self.wait_for_transfer_chunk_to_complete()
waveforms = self.get_waveforms()[0]
waveforms: list[RawWaveformType] | list[VoltageWaveformType] = (
self.get_raw_waveforms()[0] if raw else self.get_waveforms()[0]
)
self.stop() # Only strictly required for Mock devices. Should not affect hardware.
return Measurement(waveforms=waveforms, timestamp=self.get_timestamp())

def execute_finite_fifo_acquisition(self, num_measurements: int) -> List[Measurement]:
def execute_finite_fifo_acquisition(self, num_measurements: int, raw: bool = False) -> List[Measurement]:
"""Carry out a finite number of FIFO mode measurements and then stop the acquisitions.
This method automatically carries out a defined number of measurement in Multi FIFO mode, including handling the
Expand All @@ -118,6 +124,8 @@ def execute_finite_fifo_acquisition(self, num_measurements: int) -> List[Measure
Args:
num_measurements (int): The number of measurements to carry out.
raw (bool, optional): Set to true to obtain raw (i.e. 16-bit integer) waveforms, instead of floating point
voltage waveforms.
Returns:
measurements (List[Measurement]): A list of Measurement objects with length `num_measurements`. Each
Measurement object has a `waveforms` attribute containing a list of 1D NumPy arrays. Each array is a
Expand All @@ -133,9 +141,10 @@ def execute_finite_fifo_acquisition(self, num_measurements: int) -> List[Measure
self.execute_continuous_fifo_acquisition()
measurements = []
for _ in range(num_measurements // self.batch_size):
measurements += [
Measurement(waveforms=frame, timestamp=self.get_timestamp()) for frame in self.get_waveforms()
]
waveforms: list[list[RawWaveformType]] | list[list[VoltageWaveformType]] = (
self.get_raw_waveforms() if raw else self.get_waveforms()
)
measurements += [Measurement(waveforms=frame, timestamp=self.get_timestamp()) for frame in waveforms]
self.stop()
return measurements

Expand Down
8 changes: 4 additions & 4 deletions src/spectrumdevice/devices/digitiser/digitiser_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from datetime import datetime
from typing import List, Optional

from numpy import float_, int16, ndarray
from numpy.typing import NDArray
from numpy import ndarray

from spectrumdevice.devices.abstract_device.device_interface import SpectrumDeviceInterface
from spectrumdevice.devices.abstract_device.channel_interfaces import (
SpectrumAnalogChannelInterface,
SpectrumIOLineInterface,
)
from spectrumdevice.measurement import VoltageWaveformType, RawWaveformType
from spectrumdevice.settings import AcquisitionMode, AcquisitionSettings
from spectrumdevice import Measurement
from spectrumdevice.settings.channel import InputImpedance, InputCoupling, InputPath
Expand Down Expand Up @@ -105,11 +105,11 @@ def execute_continuous_fifo_acquisition(self) -> None:
raise NotImplementedError()

@abstractmethod
def get_raw_waveforms(self) -> List[List[NDArray[int16]]]:
def get_raw_waveforms(self) -> List[List[RawWaveformType]]:
raise NotImplementedError()

@abstractmethod
def get_waveforms(self) -> List[List[NDArray[float_]]]:
def get_waveforms(self) -> List[List[VoltageWaveformType]]:
raise NotImplementedError()

@abstractmethod
Expand Down
10 changes: 7 additions & 3 deletions src/spectrumdevice/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
from dataclasses import dataclass
from typing import List, Optional

from numpy import float_
from numpy import float_, int16
from numpy.typing import NDArray


VoltageWaveformType = NDArray[float_]
RawWaveformType = NDArray[int16]


@dataclass
class Measurement:
"""Measurement is a dataclass for storing a set of waveforms generated by a single acquisition, with a timestamp."""

waveforms: List[NDArray[float_]]
"""Contains the acquired waveforms as a list of 1D NumPy arrays"""
waveforms: List[VoltageWaveformType] | List[RawWaveformType]
"""Contains the acquired waveforms as a list of 1D NumPy arrays or either floats or ints"""
timestamp: Optional[datetime]
"""The time at which the acquisition was triggered, as a datetime.datetime object"""

0 comments on commit 34d4d1f

Please sign in to comment.