How to use set_ca method in fMBT

Best Python code snippet using fMBT_python

scan_parameters_old.py

Source:scan_parameters_old.py Github

copy

Full Screen

1from __future__ import division2import pkg_resources3from audioop import avg4pkg_resources.require('cothread')5pkg_resources.require('matplotlib==1.3.1')6pkg_resources.require('numpy')7import matplotlib.pyplot as pyplot8import numpy9# Stuff you need to import10from cothread.catools import caget, caput, ca_nothing11from cothread.cadef import CAException12import cothread13import time14import datetime15import math16#import matplotlib.pyplot as pyplot17#import numpy18# SIMULATION CODE19'''20values = [10, 4]21standard_dev = [1, 1]22def caput(address, value):23 global values24 global stds25 values[address] = value26def caget(address):27 global values28 global stds29 p = numpy.random.normal(values[0], standard_dev[0])30 q = numpy.random.normal(values[1], standard_dev[1])31 32 ret_res = 1 / (1 + numpy.sqrt((p - 5)**2 + (q - 5)**2))33 34 return ret_res35'''36#-----------------------------------------------------37# This measure_funcs is slightly different to the previous one in measure_obj_func238# in that it not only measures standard dev, but also takes in tuples rather than dictionaries39def measure_funcs(*measurements): # measurements is a collection of tuples, each of length 3, giving address, measurement count, and measurement delay40 function_count = len(measurements)41 counts = function_count * [0]42 results = function_count * [0.0]43 std = function_count * [0.0]44 45 runs = function_count * [True]46 run = True47 48 start_time = time.time()49 50 while run:51 for i in range(function_count):52 if (time.time() - start_time) >= (counts[i] * measurements[i][2]):53 if counts[i] < measurements[i][1]:54 measurement = caget(measurements[i][0])55 results[i] += measurement56 std[i] += measurement**257 counts[i] += 158 else:59 runs[i] = False60 run = False61 for i in range(function_count):62 if runs[i]:63 run = True64 65 for i in range(function_count):66 results[i] = results[i] / counts[i]67 std[i] = std[i] / counts[i]68 std[i] = std[i] - results[i]**269 std[i] = numpy.sqrt(std[i])70 71 return (results, std, counts) # Returns a tuple with the mean of each measurement, and a tuple with the std of each measurement72def write_2d_array(address, data):73 write_file = open(address, 'w+')74 75 write_file.write('{0}'.format(data.shape[0]))76 write_file.write('-')77 write_file.write('{0}'.format(data.shape[1]))78 write_file.write('=')79 80 for i in range(data.shape[0]):81 for j in range(data.shape[1]):82 write_file.write('{0}'.format(data[i][j]))83 write_file.write(',')84 85 #write_file.write(';')86 87 write_file.close()88def read_2d_array(address):89 read_file = open(address, 'r')90 91 content = read_file.read()92 93 width = 094 height = 095 96 run = True97 current = ''98 stage = '/'99 i = 0100 101 while run:102 if stage == '/':103 if content[i] == '-':104 width = int(current)105 current = ''106 stage = '-'107 else:108 current += content[i]109 elif stage == '-':110 if content[i] == '=':111 height = int(current)112 current = ''113 stage = '='114 run = False115 else:116 current += content[i]117 118 i += 1119 120 data = numpy.zeros((width, height))121 122 run = True123 x = 0124 y = 0125 126 for x in range(width):127 for y in range(height):128 run = True129 130 while run:131 if content[i] == ',':132 data[x, y] = current133 run = False134 current = ''135 else:136 current += content[i]137 138 i += 1139 140 141 read_file.close()142 return data143#set_ca = (('LB-PC-VSTR-05:SETI', 1), ('LB-PC-VSTR-06:SETI', 1)) # Address, delay144set_ca = (('LB-PC-VSTR-01:SETI', 0.5), ('LB-PC-VSTR-02:SETI', 0.5)) # Address, delay145#measure_ca = ('CS-DI-XFER-01:LB-03-BR', 5, 0.2) # Address, number, delay146measure_ca = ('LB-DI-EBPM-03:FT:Y', 5, 0.2) # Address, number, delay147# Read initial configuration148initial = [0, 0]149initial[0] = caget(set_ca[0][0])150initial[1] = caget(set_ca[1][0])151boundaries = ((initial[0] - 0.5, initial[0] + 0.5), (initial[1] - 0.5, initial[1] + 0.5))152point_count = (2, 2)153X = numpy.linspace(boundaries[0][0], boundaries[0][1], point_count[0])154Y = numpy.linspace(boundaries[1][0], boundaries[1][1], point_count[1])155x, y = numpy.meshgrid(X, Y)156results = numpy.zeros((point_count[0], point_count[1]))157stds = numpy.zeros((point_count[0], point_count[1]))158for a in range(point_count[0]):159 #caput(set_ca[0][0], X[a])160 #caput(set_ca[1][0], Y[0])161 print 'Set {0} to {1}'.format(set_ca[0][0], X[a])162 cothread.Sleep(set_ca[0][1]) 163 for b in range(point_count[1]):164 #caput(set_ca[1][0], Y[b])165 print 'Set {0} to {1}'.format(set_ca[1][0], Y[b])166 cothread.Sleep(set_ca[1][1])167 168 measurement = measure_funcs(measure_ca)169 results[a][b] = measurement[0][0]170 stds[a][b] = measurement[1][0]171current_time_string = datetime.datetime.fromtimestamp(time.time()).strftime('%Y_%m_%d %H_%M_%S')172write_2d_array('x {0} - {1}.data'.format(current_time_string, set_ca[0][0]), x)173write_2d_array('y {0} - {1}.data'.format(current_time_string, set_ca[1][0]), y)174write_2d_array('results {0} - {1} - {2}.data'.format(current_time_string, set_ca[0][0], set_ca[1][0]), results)175write_2d_array('stds {0} - {1} - {2}.data'.format(current_time_string, set_ca[0][0], set_ca[1][0]), stds)176#rx = read_2d_array('x.data')177#ry = read_2d_array('y.data')178#rres = read_2d_array('results.data')179#rstds = read_2d_array('stds.data')180#Set back to initial position181#caput(set_ca[0][0], initial[0])182#caput(set_ca[1][0], initial[1])183cothread.Sleep(1)184pyplot.figure()185pyplot.subplot(211)186pyplot.pcolormesh(x, y, results)187pyplot.colorbar()188pyplot.xlabel(set_ca[0][0])189pyplot.ylabel(set_ca[1][0])190pyplot.subplot(212)191pyplot.pcolormesh(x, y, stds)192pyplot.colorbar()193pyplot.xlabel(set_ca[0][0])194pyplot.ylabel(set_ca[1][0])...

Full Screen

Full Screen

scan_simulation_old.py

Source:scan_simulation_old.py Github

copy

Full Screen

1from __future__ import division2import pkg_resources3from audioop import avg4pkg_resources.require('cothread')5pkg_resources.require('matplotlib==1.3.1')6import matplotlib.pyplot as plt7 8 #Stuff you need to import9from cothread.catools import caget, caput, ca_nothing10from cothread.cadef import CAException11import time12import matplotlib.pyplot as pyplot13from matplotlib import cm14import numpy15# SIMULATION CODE16values = [0, 0]17standard_dev = [0.1, 0.1]18def caput(address, value):19 global values20 global stds21 values[address] = value22def caget(address):23 global values24 global stds25 p = numpy.random.normal(values[0], standard_dev[0])26 q = numpy.random.normal(values[1], standard_dev[1])27 28 ret_res = 1 / (1 + numpy.sqrt((p - 5)**2 + (q - 5)**2))29 30 return ret_res31#-----------------------------------------------------32# This measure_funcs is slightly different to the previous one in measure_obj_func233# in that it not only measures standard dev, but also takes in tuples rather than dictionaries34def measure_funcs(*measurements): # measurements is a collection of tuples, each of length 3, giving address, measurement count, and measurement delay35 function_count = len(measurements)36 counts = function_count * [0] 37 results = function_count * [0.0] # zeros for measurements to be taken38 std = function_count * [0.0] # zeros for std dev to be taken39 40 runs = function_count * [True] # list of run operations41 run = True #current run42 43 start_time = time.time() # start the timer44 45 while run:46 for i in range(function_count):47 if (time.time() - start_time) >= (counts[i] * measurements[i][2]): #make sure to leave enough time 48 if counts[i] < measurements[i][1]: #????49 measurement = caget(measurements[i][0]) #get 'efficiency'50 results[i] += measurement #add new measurement for mean to be calculated 51 std[i] += measurement**2 #add squares of std for calculation later52 counts[i] += 1 #increase count number53 else:54 runs[i] = False #55 run = False56 for i in range(function_count):57 if runs[i]:58 run = True59 60 for i in range(function_count):61 results[i] = results[i] / counts[i] #mean results62 std[i] = std[i] / counts[i]63 std[i] = std[i] - results[i]**264 std[i] = numpy.sqrt(std[i]) #final std65 66 return (results, std, counts) # Returns a tuple with the mean of each measurement, and a tuple with the std of each measurement67set_ca = ((0, 0.00001), (1, 0.00001)) # Address, delay68measure_ca = ('a', 10, 0.00001)69boundaries = ((0, 10), (0, 10))70point_count = (100, 100)71X = numpy.linspace(boundaries[0][0], boundaries[0][1], point_count[0])72Y = numpy.linspace(boundaries[1][0], boundaries[1][1], point_count[1])73x, y = numpy.meshgrid(X, Y)74results = numpy.zeros((point_count[0], point_count[1]))75stds = numpy.zeros((point_count[0], point_count[1]))76for a in range(point_count[0]):77 caput(set_ca[0][0], X[a])78 time.sleep(set_ca[0][1])79 print a80 for b in range(point_count[1]):81 caput(set_ca[1][0], Y[b])82 time.sleep(set_ca[1][1])83 84 measurement = measure_funcs(measure_ca)85 results[a][b] = measurement[0][0]86 stds[a][b] = measurement[1][0]87pyplot.figure()88pyplot.subplot(211)89pyplot.pcolormesh(x, y, results, cmap=cm.plasma)90pyplot.colorbar()91pyplot.subplot(212)92pyplot.pcolormesh(x, y, stds, cmap=cm.plasma)93pyplot.colorbar()...

Full Screen

Full Screen

arithmetic.py

Source:arithmetic.py Github

copy

Full Screen

...7 X = pd.DataFrame(8 data=data9 )10 return X11def set_ca(X):12 ca = prince.CA(13 n_components=2,14 n_iter=3,15 copy=True,16 check_input=True,17 engine='auto',18 random_state=4219 )20 ca = ca.fit(X)21 return ca22if __name__ == '__main__':23 data = json.loads(sys.argv[1])24 X = set_data(data)25 ca = set_ca(X)26 col = ca.column_coordinates(X).values27 pow = ca.row_coordinates(X).values...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful