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
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.
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)
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)
scan_array_norm = np.roll(scan_array_norm, starting_index)
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
committed
"""
Returns array generator
"""
larr = len(arr)
cursor = 0
while cursor < larr:
yield arr[cursor]
cursor = cursor + 1
def yield_scan_array(arr):
while True: