Esempio n. 1
0
def test_extract_amplitude_real_data(file_path):
    test_data = pd.read_csv(file_path + '/data/photovoltage_data.csv',
                            skiprows=1)
    lia = LIA(test_data)
    actual_amplitude = lia.extract_signal_amplitude()
    desired_amplitude = (-0.0185371754 - 4.60284137e-11) * ureg.mV
    assert_equal_qt(actual_amplitude, desired_amplitude)
Esempio n. 2
0
def test_with_large_dc():
    test_data = pd.DataFrame({
        'time (ms)': [1, 2, 3, 4, 5, 6],
        'val (V)': 10000 + np.array([1, 0, -1, 0, 1, 0]),
        'Sync': [1, 0, 0, 0, 1, 0]
    })
    lia = LIA(test_data)
    desired_amplitude = 1 * ureg.V / np.sqrt(2)
    actual_amplitude = lia.extract_signal_amplitude(sync_phase_delay=np.pi / 2)
    assert_allclose_qt(actual_amplitude, desired_amplitude, atol=1e-6)
Esempio n. 3
0
def test_extract_minus_pi_2_offset():
    test_data = pd.DataFrame({
        'time (ms)': [1, 2, 3, 4, 5, 6, 7],
        'val (V)': [1, 0, -1, 0, 1, 0, -1],
        'Sync': [1, 0, 0, 0, 1, 0, 0]
    })
    lia = LIA(test_data)
    desired_amplitude = 1 * ureg.V / np.sqrt(2)
    actual_amplitude = lia.extract_signal_amplitude(sync_phase_delay=np.pi / 2)
    assert_allclose_qt(actual_amplitude, desired_amplitude, atol=1e-6)
Esempio n. 4
0
def test_extract_zero_with_offset():
    test_data = pd.DataFrame({
        'time (ms)': [0, 1, 2, 3, 4, 5, 6, 7],
        'val (V)': [1, 1, 1, 1, 1, 1, 1, 1],
        'Sync': [0, 0, 1, 0, 0, 0, 1, 0]
    })
    lia = LIA(test_data)
    desired_amplitude = 0 * ureg.V
    actual_amplitude = lia.extract_signal_amplitude(sync_phase_delay=np.pi)
    assert_allclose_qt(actual_amplitude, desired_amplitude, atol=1e-6)
Esempio n. 5
0
def modulated_photocurrent(data, cond):
    """
    Returns the RMS value of the modulated photocurrent given the system gain and a dataset using lock-in amplification.
    """
    lia = LIA(data=data)
    if 'sync_phase_delay' in cond:
        sync_phase_delay = cond['sync_phase_delay']
    else:
        sync_phase_delay = np.pi
    extracted_voltage = lia.extract_signal_amplitude(
        mode='amplitude', sync_phase_delay=sync_phase_delay)
    extracted_current = (extracted_voltage / cond['gain']).to(ureg.pA)
    return extracted_current
Esempio n. 6
0
def fit_lia(data, n_points=101, fit=True):
    """
    Generates amplitude vs. phase for lock-in-amplifier type data. Optionally fits that phase to a cosine function and returns the fit parameters.

    :param data: pandas DataFrame which contains a 'Sync' column with synchronization points
    """
    def cos_func(x, a=1, phase=0.1):
        return a*np.cos(x - phase)

    ylabel = data.columns[1]

    lia = LIA(data)
    phase_delays = np.linspace(-np.pi, np.pi, n_points)
    test_value = lia.extract_signal_amplitude(sync_phase_delay=0)
    extracted_v_np = np.vectorize(lia.extract_signal_amplitude)
    all_values = np.array([])
    for phase in phase_delays:
        retval = lia.extract_signal_amplitude(sync_phase_delay=phase)
        if isinstance(retval, pint.Quantity):
            retval = retval.m
        all_values = np.append(all_values, retval)

    if fit:
        try:
            (amp, phase), pcov = curve_fit(cos_func, phase_delays, all_values)
            if amp < 0:
                amp *= -1
                phase -= np.pi
            phase = np.mod(phase, 2*np.pi)
        except RuntimeError as e:
            breakpoint()
    else:
        (amp, phase) = (None, None)
    full_data = pd.DataFrame({
            'Phase (rad)': phase_delays,
            ylabel: all_values
            })
    return full_data, (amp, phase)