Source code for nirfmxvna.iq_results

"""Provides methods to fetch and read the IQ measurement results."""

import functools

import nirfmxvna.attributes as attributes
import nirfmxvna.enums as enums
import nirfmxvna.errors as errors
import nirfmxvna.internal._helper as _helper


def _raise_if_disposed(f):
    """From https://stackoverflow.com/questions/5929107/decorators-with-parameters."""

    @functools.wraps(f)
    def aux(*xs, **kws):
        meas_obj = xs[0]  # parameter 0 is 'self' which is the measurement object
        if meas_obj._signal_obj.is_disposed:
            raise Exception("Cannot access a disposed Vna signal configuration")
        return f(*xs, **kws)

    return aux


[docs] class IQResults(object): """Provides methods to fetch and read the IQ measurement results.""" def __init__(self, signal_obj): """Provides methods to fetch and read the IQ measurement results.""" self._signal_obj = signal_obj self._session_function_lock = signal_obj._session_function_lock self._interpreter = signal_obj._interpreter
[docs] @_raise_if_disposed def get_correction_state(self, selector_string): r"""Gets the error correction state of the VNA IQ measurement. Use "iq<*n*>" as the selector string to read this attribute. +-----------------------+---------------------------------------------------------------------------------------------------------------------+ | Name (Value) | Description | +=======================+=====================================================================================================================+ | None (0) | Error correction is not applied. | +-----------------------+---------------------------------------------------------------------------------------------------------------------+ | Corrected (1) | Error correction is applied without interpolation using the error terms from the calset. | +-----------------------+---------------------------------------------------------------------------------------------------------------------+ | Interpolated (2) | Error correction is applied with error terms for at least one sweep point interpolated from the calset error terms. | +-----------------------+---------------------------------------------------------------------------------------------------------------------+ | Settings Modified (3) | Settings during the measurment differ from those used during calibration. | +-----------------------+---------------------------------------------------------------------------------------------------------------------+ Args: selector_string (string): Pass an empty string. Returns: Tuple (attr_val, error_code): attr_val (enums.IQCorrectionState): Returns the error correction state of the VNA IQ measurement. error_code (int): Returns the status code of this method. The status code either indicates success or describes a warning condition. """ try: self._session_function_lock.enter_read_lock() updated_selector_string = _helper.validate_and_update_selector_string( selector_string, self._signal_obj ) attr_val, error_code = self._interpreter.get_attribute_i32( updated_selector_string, attributes.AttributeID.IQ_RESULTS_CORRECTION_STATE.value ) attr_val = enums.IQCorrectionState(attr_val) except (KeyError, ValueError): raise errors.DriverTooNewError() # type: ignore finally: self._session_function_lock.exit_read_lock() return attr_val, error_code
[docs] @_raise_if_disposed def fetch_data(self, selector_string, timeout, data): r""" Args: selector_string (string): timeout (float): data (numpy.complex64): Returns: Tuple (x0, dx, error_code): x0 (float): dx (float): error_code (int): Returns the status code of this method. The status code either indicates success or describes a warning condition. """ try: self._session_function_lock.enter_read_lock() _helper.validate_not_none(selector_string, "selector_string") updated_selector_string = _helper.validate_and_update_selector_string( selector_string, self._signal_obj ) x0, dx, error_code = self._interpreter.iq_fetch_data( updated_selector_string, timeout, data ) finally: self._session_function_lock.exit_read_lock() return x0, dx, error_code