prsctrl.measurement.measurement.MeasurementHandler#

class MeasurementHandler(measurement_settings: MeasurementSettings, wavelengths: list[str | int | float], data_queue: Queue, command_queue: Queue, monochromators: Monochromator | list[Monochromator], shutter: Shutter, add_measurement_info_to_metadata: bool = True, compress_data: bool = True)[source]#

Bases: object

Class that performs the actual measurement.

Parameters:
  • monochromator

  • shutter

  • measurement_params

  • signal_to_noise_f – A function that takes the PrsData and the current wavelength and determines whether the signal to noise ratio is already satisfying. If the function returns True, the measurement is stopped early.

  • command_queue – A queue used to receive a “stop” or other signals. Useful when run() is run in another thread

  • data_queue – A queue where the data of a certain wavelength is put in after it has been measured. Useful for live monitoring when run() is run in another thread

  • add_measurement_info_to_metadata

  • compress_data – Whether to use gzip compression on full data file

Methods

add_measurement_mode

Add a Lock-In that records data using the measurement.

auto_determine_gain

Auto-determine the optimum gain value for each pre-amplifier.

prepare

Setup some settings, filling in defaults for missing parameters.

run

Run the measurement.

__annotations__ = {'command_queue': 'Queue', 'data_queue': 'Queue', 'modes': 'dict[str, tuple[LockInHandler, PrsData, Amplifier | None]]', 'target_I_range_V': 'tuple[float, float]'}#
__dict__ = mappingproxy({'__module__': 'prsctrl.measurement.measurement', '__firstlineno__': 98, '__init__': <function MeasurementHandler.__init__>, 'add_measurement_mode': <function MeasurementHandler.add_measurement_mode>, 'prepare': <function MeasurementHandler.prepare>, 'auto_determine_gain': <function MeasurementHandler.auto_determine_gain>, 'run': <function MeasurementHandler.run>, '_auto_sensitivity': <function MeasurementHandler._auto_sensitivity>, '_is_gain_modification_needed_all': <function MeasurementHandler._is_gain_modification_needed_all>, '_is_gain_modification_needed': <function MeasurementHandler._is_gain_modification_needed>, '_auto_gain_all': <function MeasurementHandler._auto_gain_all>, '_auto_gain': <function MeasurementHandler._auto_gain>, '_set_wavelength_and_wait': <function MeasurementHandler._set_wavelength_and_wait>, '_get_data': <function MeasurementHandler._get_data>, '_run': <function MeasurementHandler._run>, '__static_attributes__': ('add_measurement_info_to_metadata', 'auto_gain', 'auto_sensitivity', 'command_queue', 'compress_data', 'data_queue', 'measurement_settings', 'measurement_time_s', 'modes', 'monochromators', 'shutter', 'target_I_range_V', 'timeout_interval', 'timeout_s', 'wait_time_s', 'wavelengths'), '__dict__': <attribute '__dict__' of 'MeasurementHandler' objects>, '__weakref__': <attribute '__weakref__' of 'MeasurementHandler' objects>, '__doc__': None, '__annotations__': {'data_queue': 'Queue', 'command_queue': 'Queue', 'modes': 'dict[str, tuple[LockInHandler, PrsData, Amplifier | None]]', 'target_I_range_V': 'tuple[float, float]'}})#
__firstlineno__ = 98#
__init__(measurement_settings: MeasurementSettings, wavelengths: list[str | int | float], data_queue: Queue, command_queue: Queue, monochromators: Monochromator | list[Monochromator], shutter: Shutter, add_measurement_info_to_metadata: bool = True, compress_data: bool = True)[source]#

Class that performs the actual measurement.

Parameters:
  • monochromator

  • shutter

  • measurement_params

  • signal_to_noise_f – A function that takes the PrsData and the current wavelength and determines whether the signal to noise ratio is already satisfying. If the function returns True, the measurement is stopped early.

  • command_queue – A queue used to receive a “stop” or other signals. Useful when run() is run in another thread

  • data_queue – A queue where the data of a certain wavelength is put in after it has been measured. Useful for live monitoring when run() is run in another thread

  • add_measurement_info_to_metadata

  • compress_data – Whether to use gzip compression on full data file

__module__ = 'prsctrl.measurement.measurement'#
__static_attributes__ = ('add_measurement_info_to_metadata', 'auto_gain', 'auto_sensitivity', 'command_queue', 'compress_data', 'data_queue', 'measurement_settings', 'measurement_time_s', 'modes', 'monochromators', 'shutter', 'target_I_range_V', 'timeout_interval', 'timeout_s', 'wait_time_s', 'wavelengths')#
__weakref__#

list of weak references to the object

_auto_gain(wl_nm, lockin: LockInHandler, data: PrsData, pre_amp: Amplifier | None) bool[source]#
_auto_gain_all(wl_nm)[source]#

Increase or decrease the pre-amp gain if the DC value goes out of the target range.

Note:

Gain is only increased or decreased by max. 1 step during this function! Do not use it to set the initial gain.

_auto_sensitivity(wl)[source]#

Check for a lock-in output overload and increase the sensitivity value until the overload is gone

_get_data(wl: int | float | str, mode_key: str, lockin: LockInHandler, data: PrsData, measurement_duration: int)[source]#

Transfer the data from the lock-in, add it to the PrsData object, calculate the spectrum data and send it via the data queue

_is_gain_modification_needed(lockin: LockInHandler)[source]#
_is_gain_modification_needed_all() bool[source]#

Determine if any measurement mode requires a modification of the amplifier gain setting. :return: True if modification is needed

_run()[source]#

Run a spectrum measurement. self.wavelengths if a list of wavelengths and offsets to measure. Parallelization in the form of multithreading is used to save time: setting the wavelength+waiting and the data transfer+processing are run in separate threads, when all are done the next measurement phase begins. One measurement includes: - Setting the wavelength - Wait until the signal should be stable - Initializing empty data in PrsData objects - Auto-increase sensitivity if necessary - Measure using the lock-in buffer for <measurement time>, for models where only 2values can be stored in the buffer, the phase is measured separately in regular intervals (leading to much less data points) - Transfer the data from the lock-in - Calculate means and errors, send them to the parent thread via the data queue - Check the command for commands

_set_wavelength_and_wait(wl_nm)[source]#

If the wavelength is a number, set the monochromator to that number and make sure the shutter is open. If it is not a number, close the shutter. After that, wait for the wait_time_s until the signal should be stable

add_measurement_mode(mode: str, lockin: LockInAmp, lockin_settings: LockInSettings, data: PrsData, pre_amp: Amplifier | None = None)[source]#

Add a Lock-In that records data using the measurement.

Parameters:
  • mode – key of the measurement mode, eg ‘ref’ or ‘tra’

  • lockin

  • data – PrsData object with no data initialized (it may already contain metadata). Each mode needs its own PrsData object

  • aux_DC – The name of auxiliary input channel the DC signal is connected to on the lock-in

auto_determine_gain(min_DC: float = 0.8, max_DC: float = 9.95, N_test: int = 6, wait_time_s: float = 0.2)[source]#

Auto-determine the optimum gain value for each pre-amplifier.

Sweeps a few points in the spectrum and adjust the gain so that the DC value does not exceed max_DC V, but if possible, stays above min_DC mV.

This function must be called after prepare, all relevant parameters (especially the monochromator bandwidth) must have been set on the devices already.

Parameters:
  • min_DC – The minimum voltage for the DC signal.

  • max_DC – The maximum voltage for the DC signal. If any value crosses this threshold, the gain is reduced, even if this causes other wavelengths to o below min_DC.

  • wait_time_s – Time to wait after setting the wavelength. Small values should be enough since only the DC value is measured.

  • N_test – Target number of wavelengths for which to check the DC value

Raises:

RuntimeError – If prepare() was not called first

command_queue: Queue#
data_queue: Queue#
modes: dict[str, tuple[LockInHandler, PrsData, Amplifier | None]]#
prepare()[source]#

Setup some settings, filling in defaults for missing parameters.

run()[source]#

Run the measurement. You must call prepare() first. run() may be run a separate thread.

target_I_range_V: tuple[float, float]#