Skip to content
scanFunctions.py 2.12 KiB
Newer Older
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 26 11:24:28 2018

@author: martindrech

Auxiliary functions for performing scans in a cleaner way
"""

import numpy as np

Martin Drechsler's avatar
Martin Drechsler committed
def create_scan_array(scan_start, scan_stop, scan_period, first_value, dt, normalized = False, normalization_constant = 0):
    Returns the array that represents one period of the scan, including up and down paths of the triangle.
    The first_value param is were the scan actually starts. The scan_start and scan_top give the range. 
Martin Drechsler's avatar
Martin Drechsler committed
    
    If normalized is true, then it returns the array from 1 to -1 (including up and down paths) multiplied by 
    the value normalization_constant
    """
    scan_start = float(scan_start)
    scan_stop = float(scan_stop)
    scan_period = float(scan_period)
    
    number_of_points = 1 + (scan_period+dt)//(2*dt)
Martin Drechsler's avatar
Martin Drechsler committed
    
    
    scan_array_norm = np.linspace(1* normalization_constant, -1*normalization_constant, int(number_of_points) )
    scan_array_norm = np.concatenate((scan_array_norm, np.flip(scan_array_norm, 0)[1:]))
    
    scan_array = np.linspace(scan_start, scan_stop, int(number_of_points))
    scan_array = np.concatenate((scan_array, np.flip(scan_array, 0)[1:]))
    starting_index = np.abs(scan_array-first_value).argmin()+1
    scan_array = np.roll(scan_array, starting_index)
Martin Drechsler's avatar
Martin Drechsler committed
    scan_array_norm = np.roll(scan_array_norm, starting_index)
Martin Drechsler's avatar
Martin Drechsler committed
    if normalized:
        return scan_array_norm
    else:
        return scan_array

def create_measurement_array(start, stop, steps, back_and_forth=False):
    """
    Simply creates the array of a measurement. 
    """
Martin Drechsler's avatar
Martin Drechsler committed
    return np.linspace(start, stop, steps)


def yield_array(arr):
    larr = len(arr)
    cursor = 0
    while cursor < larr:
        yield arr[cursor]
        cursor = cursor + 1


def yield_scan_array(arr):
    """
    An infinite looping generator
    """
        yield from yield_array(arr)
#%%
#scan_start = 0
#scan_stop = 1
#scan_period = 1
#first_value = .6
#dt = 0.1
#
#a = create_scan_array(scan_start, scan_stop, scan_period, first_value, dt)
#print(a)