diff --git a/src/python_spectrometer/daq/simulator.py b/src/python_spectrometer/daq/simulator.py index e85fc8804550ae7849ff48037d5d7b439651d8a6..3c09e046e52799c0f811041050c27e56aaf83daf 100644 --- a/src/python_spectrometer/daq/simulator.py +++ b/src/python_spectrometer/daq/simulator.py @@ -1,17 +1,23 @@ """Provides a simulation backend for data acquisition. +The :meth:`DAQ.acquire` method of DAQs in this module accepts a +``delay`` keyword argument which introduces a delay in between yields +to simulate a finite data acquisition time. If True (default), delays +by the amount of time it would take to actually acquire data with the +given settings; if float delays by the given amount. + Examples -------- >>> import python_spectrometer as pyspeck >>> import tempfile >>> speck = pyspeck.Spectrometer(pyspeck.daq.QoptColoredNoise(), ... savepath=tempfile.mkdtemp()) ->>> speck.take('a test', fs=10e3) #doctest: +ELLIPSIS +>>> speck.take('a test', fs=10e3) ... >>> speck.block_until_ready() # for doctest Add an artificial time delay to mimick finite data acquisition time: ->>> speck.take('delayed', n_avg=3, delay=True) #doctest: +ELLIPSIS +>>> speck.take('delayed', n_avg=3, delay=True) ... """ @@ -19,6 +25,7 @@ from __future__ import annotations import copy import dataclasses +import inspect import sys import time from collections.abc import Callable @@ -121,8 +128,9 @@ class QoptColoredNoise(DAQ): Attributes ---------- spectral_density : Callable[[NDArray, ...], NDArray] - A function that generates the power spectral density for given frequencies. - Defaults to white noise with scale parameter ``S_0``. + A function that generates the power spectral density for given + frequencies. Defaults to white noise with scale parameter + ``S_0``. See Also -------- @@ -148,13 +156,7 @@ class QoptColoredNoise(DAQ): @with_delay def acquire(self, *, n_avg: int, fs: float, n_pts: int, **settings) -> AcquisitionGenerator[DAQ.DTYPE]: - """Executes a measurement and yields the resulting timetrace. - - Optionally set a delay to simulate a finite data acquisition - time. If True, delays by the amount of time it would take to - actually acquire data with the given settings; if float delay - by the given amount. - """ + """Executes a measurement and yields the resulting timetrace.""" for _ in range(n_avg): yield qopt.noise.fast_colored_noise( partial( @@ -171,10 +173,10 @@ class QoptColoredNoise(DAQ): class DemodulatorQoptColoredNoise(QoptColoredNoise): """Simulates demodulated noisy data for lock-in measurements. - Extends QoptColoredNoise to demodulate the simulated signal using complex - IQ-demodulation, similar to a lock-in amplifier. This provides a realistic - simulation of demodulated signals as would be measured in experiments - using lock-in amplification techniques. + Extends QoptColoredNoise to demodulate the simulated signal using + complex IQ-demodulation, similar to a lock-in amplifier. This + provides a realistic simulation of demodulated signals as would be + measured in experiments using lock-in amplification techniques. """ DTYPE = np.complexfloating @@ -182,8 +184,8 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): def demodulate(signal: np.ndarray, IQ: np.ndarray, **settings) -> np.ndarray: """Demodulate signal using the provided IQ reference. - Performs complex demodulation by multiplying the signal with the IQ reference - and applying an RC filter. Removes high-pass filtering by ignoring f_min. + Performs complex demodulation by multiplying the signal with + the IQ reference and applying an RC filter. Parameters ---------- @@ -194,10 +196,6 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): **settings : Settings for RC filter, including filter parameters - Returns - ------- - numpy.ndarray - Filtered, demodulated signal """ # Don't highpass filter settings = copy.deepcopy(settings) @@ -212,10 +210,10 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): r"""Simulate demodulated noisy data. Generates simulated data and performs IQ demodulation, mimicking - the behavior of a lock-in amplifier. Can simulate either just input noise - or noise in the full signal path. + the behavior of a lock-in amplifier. Can simulate either just + input noise or noise in the full signal path. - See Ref. [1]_ for an introduction to Lock-in amplification. + See [1]_ for an introduction to Lock-in amplification. Parameters ---------- @@ -225,8 +223,6 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): Modulation frequency. filter_order : int, optional RC filter order used to filter the demodulated signal. - delay : bool | float, optional - Simulate a realistic data acquisition duration. modulate_signal : bool, optional Add the simulated noise to the modulation signal to mimic noise picked up by a Lock-In signal travelling through some @@ -243,7 +239,8 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): x(t) = s(t) + \delta(t) - with $s(t)$ the output signal and $\delta(t)$ the noise. + with :math:`s(t)` the output signal and :math:`\delta(t)` + the noise. filter_method : See :func:`~qutil:qutil.signal_processing.real_space.RC_filter`. @@ -254,7 +251,7 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): References ---------- - .. [1]: https://www.zhinst.com/europe/en/resources/principles-of-lock-in-detection + .. [1] https://www.zhinst.com/europe/en/resources/principles-of-lock-in-detection """ t = np.arange(0, settings['n_pts'] / settings['fs'], 1 / settings['fs']) @@ -273,4 +270,3 @@ class DemodulatorQoptColoredNoise(QoptColoredNoise): @deprecated("Use QoptColoredNoise instead") class qopt_colored_noise(QoptColoredNoise): ... -