hardware_interfaces.analog_digital_converter module

class AnalogDigitalConverter(device_name: str, input_configuration: Union[str, bytes, os.PathLike], samples_to_acquire: int, trigger_source: str, sampling_rate: float, laser_frequency: float, name: str = 'analog to digital converter')[source]

Bases: object

Initialises connection to ADC and sets up timing and triggering properties etc. accordingly.

It is assumed that a National Instruments nidaqmx capable device is used as ADC. This class supports the devices NI USB-6225 (Mass Termination) and PCI-DIO-32HS (NI-6533).

Support for new devices can be added with relative ease (especially when they do not require additional data sorting) by adding a new private method which initialises the device with appropriate settings. Also make sure to update the if clauses in relevant methods.

Parameters
  • device_name (str) –

    Name of the device / ADC. The name can be found and configured in the National Instruments Software: ‘Measurement and Automation Explorer’ (MAX). The device name should also be displayed in a pop-up when plugging in the device.

    • E.g.: “Dev0”, “Dev1” etc.

  • input_configuration (Path) –

    Path to json file which contains configuration of ADC input to physical device

    • I.e. ‘Probe Pixel 0’, ‘Chopper’, ‘Wobbler’

  • samples_to_acquire (int) – Number of samples per channel / input to acquire during one sampling process.

  • acquisition_time (float) – Time needes to acquire all samples in seconds.

  • trigger_source (str) –

    Name of input to which the trigger is connected. For our cases the trigger should generally be a TTL from the Laser.

    • E.g: PFI14, PFI4

  • sampling_rate (float) – Sampling rate of ADC in Hz. This is different for different ADCs and different lasers rep rates. We quote from the nidaqmx documentation: Specifies the sampling rate in samples per channel per second. If you use an external source for the Sample Clock, set this input to the maximum expected rate of that clock. So we would expect that the sampling rate corresponds to the laser frequency. For some reason this causes issues with NI 6225. When adding too many channels the last added channels do not read the held voltage at the sample and hold electronics of the PreAmp. When removing the first channels from the task the last channels start working. This problem can be solved by increasing the sampling rate. We recommend to set it as high as possible (for no particular reason (this is just a hunch)) for NI 6225 this is 250000/number of channels in task. This logic does not apply FPAS (PCI DIO 32HS) where it has to be set to 1e7 Hz. PCI DIO 32HS uses a different timing scheme and also is not technically an ADC but only a digital input/output channel.

  • laser_frequency (float) – Frequency of the laser (or more generally of the trigger) in Hz.

  • name (str, optional) – Name / Identifier to give to this ADC. This is relevant for log statements. Defaults to “analog to digital converter”.

task

Represents a DAQmx Task object, through which all communication with device is managed.

Type

object

product_type

Modelname of device. E.g. “USB-6225 (Mass Termination)”

Type

str

input_configuration

Contains configuration information: [ADC input, physical device identifier, minimum voltage, maximum voltage]. The last two entries are relevant to indicate to the ADC in what range voltage range it needs to convert data. Setting these values incorrectly leads to either a lower (voltage) resolution or a cutoff of the signal.

Type

List

number_of_channels

Number of channels/ADC inputs that are read.

Type

int

data

Array containing data of latest .read() process. If .read() method has not been calles yet, or .set_samples_to_acquire() has been used, this array contains random data!

  • shape: (number_of_channels, samples_to_acquire)

Type

ndarray

entangled_data

(If applicable) Array containing entangled data of FPAS ADC.

  • shape: (128*samples_to_acquire)

Type

ndarray

stream

Object that exposes an input data stream on a DAQmx task. Required to read ADC data directly into numpy array.

Type

object

channel_reader

Object that reads samples from input channels directly into numpy array.

Type

object

pixel_idx

Array holding indices that refer to the rows in the adc data which are MCT Pixels. The array holds all indices of the probe pixels in the first half and the indices of all reference pixel in the second half.

Type

ndarray

probe_pixel_idx

Array holding indices that refer to the rows in the adc data which are MCT Probe Pixels.

Type

ndarray

reference_pixel_idx

Array holding indices that refer to the rows in the adc data which are MCT Reference Pixels

Type

ndarray

index_dict

Dictionary that holds names of different devices/ inputs that are connected to adc as keys and the index of the row in the adc data as value.

Type

dict

References

end()[source]

Stops and ends nidaqmx task.

is_done() → bool[source]

Check if measurement/data acquisition is complete.

Returns

True if acquisition is complete, False if not.

Return type

bool

read(timeout: Optional[float] = None, sort: bool = True) → numpy.ndarray[source]

Reads the data from the buffer, saves it to self.data and returns it.

Once called this method will wait until all samples have become available, so if not all samples have been read into the buffer, this will halt the interpreter. On the other hand, if all samples are already available in the buffer this method is not going to halt the interpreter. For maximum time efficiency use self.start() to write samples into buffer without halting the interpreter. By default, the FPAS ADC data is sorted. This takes about 1 ms per 1000 samples per channel. If this is too slow, set sort parameter to false. The method will then return the entangled data instead. Use self.sort_PCI_DIO_32HS() method to sort data afterwards.

Parameters
  • timeout (float, optional) – Specifies the amount of time in seconds to wait for samples to become available. If the time elapses, the method returns an error and any samples read before the timeout elapsed. If you set timeout to nidaqmx.constants.WAIT_INFINITELY or to -1 the method waits indefinitely. If you set timeout to 0, the method tries once to read the requested samples and returns an error if it is unable to. Defaults to None. This will set the timeout to 1.1 * acquisition time.

  • sort (bool, optional) –

    Only relevant for FPAS ADC. If it is set to True this method returns the sorted data. If it is not it returns the entangled data. This data is additionally accessible through self.entangled_data. Defaults to True.

    Warning

    If set to False, then self.data potentially holds a preallocated ndarray containing random data!

Returns

ADC Data.

  • shape: (self.number_of_channels, self.samples_to_acquire). Shape differs for FPAS ADC if data is requested unsorted.

Return type

ndarray

set_acquisition_time(time: float)[source]

Set time in seconds for which the acquisition should run.

Instead of setting the number of samples that should be acquired, this method takes the time period in seconds for which the acquisition should run and sets the according number of samples that should be acquired per channel.

Parameters

time (float) – time period in seconds for which data should be acquired.

set_samples_to_acquire(samples_to_acquire: int)[source]

Sets the number of samples per channel that should be acquired.

E.g.: If the task is started it will acquire samples_to_acquire samples for each channel and write them into a buffer.

Parameters

samples_to_acquire (int) – Number of samples to acquire per channel.

sort_PCI_DIO_32HS() → numpy.ndarray[source]

Takes the entangled data of the class attribute self.entangled_data from FPAS ADC and sorts it.

This code was translated from a corresponding LabView VI. A ‘bug’ was found in this VI and corrected here (Division by 0xFFFF instead of 0x10000). The FPAS ADC has a total of 144 inputs: 128 of them are pixels the other 16 are open connectors. The FPAS ADC samples with 16bit. To enable maximum transferspeeds 32 bit data is transferred. Each data point can be split into two values. The first 16 binary digits correspond to one value of the ADC the last 16 binary digits are a different value of the ADC. After seperating them they have to be assigned to the corresponding input.

Returns

Sorted data.

  • shape: (144, self.samples_to_aquire), 144 represents the number of inputs (self.number_of_channels).

Return type

ndarray

start()[source]

Starts nidaqmx task and therefore data acquisition.

Technically speaking, it starts nidaqmx task and then starts acquisition once trigger activates. This method will not start the task when the task is still active.

Note

This method will not cause the python interpreter to halt, which is advantageous for processes that need to run simultaneously. To then read the data from the buffer without an acquisition delay, use the self.read() method.

stop()[source]

Stops nidaqmx task and sets task state to False.

This is necessary to call before a new task is started and will be called at the end of the read method.

wait(timeout: float = 10)[source]

Wait for measurement/data acquisition to complete by halting the interpreter.

Parameters

timeout (float, optional) – Specifies the amount of time in seconds to wait for samples to become available. If the time elapses, the method returns an error and any samples read before the timeout elapsed. If you set timeout to nidaqmx.constants. WAIT_INFINITELY or to -1 the method waits indefinitely. If you set timeout to 0, the method tries once to read the requested samples and returns an error if it is unable to. Defaults to 10.

timetest()[source]