Commit 85de1a5c authored by Nick Sauerwein's avatar Nick Sauerwein
Browse files

change tomography to tomopy

parent 115e259c
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
This source diff could not be displayed because it is too large. You can view the blob instead.
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
{
"cells": [
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import cma\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"f = lambda x: sum((x - 5)**2 + np.random.rand(len(x)))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"x0 = [4,3]\n",
"sigma0 = 1"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(3_w,6)-aCMA-ES (mu_w=2.0,w_1=63%) in dimension 2 (seed=1047804, Thu Jul 13 15:59:19 2017)\n",
"Iterat #Fevals function value axis ratio sigma min&max std t[m:s]\n",
" 1 6 1.915005728330327e+00 1.0e+00 1.19e+00 1e+00 1e+00 0:0.0\n",
" 2 12 1.768412126504098e+00 1.5e+00 1.09e+00 9e-01 1e+00 0:0.0\n",
" 3 18 2.588612117582747e+00 1.5e+00 9.16e-01 7e-01 9e-01 0:0.0\n",
" 10 60 1.981730920609638e+00 1.1e+00 3.14e-01 1e-01 2e-01 0:0.0\n",
"termination on maxiter=10 (Thu Jul 13 15:59:19 2017)\n",
"final/bestever f-value = 2.242629e+00 1.279369e+00\n",
"incumbent solution: [4.9449901122462583, 3.9992942217224052]\n",
"std deviation: [0.1608506449321806, 0.14492153349444201]\n"
]
},
{
"data": {
"text/plain": [
"(array([ 4.92294242, 3.99444917]),\n",
" 1.2793694911181586,\n",
" 51,\n",
" 61,\n",
" 10,\n",
" array([ 4.94499011, 4.27656649]),\n",
" array([ 0.16085064, 0.14492153]),\n",
" {'maxiter': 10},\n",
" <cma.CMAEvolutionStrategy at 0x7ff755e59c50>,\n",
" <cma.CMADataLogger at 0x7ff775f05be0>)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cma.fmin(f, x0, sigma0,options = {'bounds': [[3,2],[6,4]], 'tolx': 1e-3, 'maxiter': 10})"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": true,
"hidePrompt": true
},
"outputs": [],
"source": [
"opts = cma.CMAOptions()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" AdaptSigma='CMAAdaptSigmaCSA # or any other CMAAdaptSigmaBase class e.g.\n",
" CMAAdaptSigmaTPA'\n",
" CMA_active='True # negative update, conducted after the original update'\n",
" CMA_cmean='1 # learning rate for the mean value'\n",
" CMA_const_trace='False # normalize trace, value CMA_const_trace=2 normalizes\n",
" sum log eigenvalues to zero'\n",
" CMA_dampsvec_fac='np.Inf # tentative and subject to changes, 0.5 would be a\n",
" \"default\" damping for sigma vector update'\n",
" CMA_dampsvec_fade='0.1 # tentative fading out parameter for sigma vector\n",
" update'\n",
" CMA_diagonal='0*100*N/sqrt(popsize) # nb of iterations with diagonal\n",
" covariance matrix, True for always'\n",
" CMA_eigenmethod='np.linalg.eigh # 0=numpy-s eigh, -1=pygsl, otherwise\n",
" cma.Misc.eig (slower)'\n",
" CMA_elitist='False #v or \"initial\" or True, elitism likely impairs global\n",
" search performance'\n",
" CMA_mirrormethod='1 # 0=unconditional, 1=selective, 2==experimental'\n",
" CMA_mirrors='popsize < 6 # values <0.5 are interpreted as fraction, values >1\n",
" as numbers (rounded), otherwise about 0.16 is used'\n",
" CMA_mu='None # parents selection parameter, default is popsize // 2'\n",
" CMA_on='True # False or 0 for no adaptation of the covariance matrix'\n",
" CMA_rankmu='True # False or 0 for omitting rank-mu update of covariance\n",
" matrix'\n",
" CMA_rankmualpha='0.3 # factor of rank-mu update if mu=1, subject to removal,\n",
" default might change to 0.0'\n",
" CMA_sample_on_sphere_surface='False #v all mutation vectors have the same\n",
" length'\n",
" CMA_stds='None # multipliers for sigma0 in each coordinate, not represented in\n",
" C, makes scaling_of_variables obsolete'\n",
" CMA_teststds='None # factors for non-isotropic initial distr. of C, mainly for\n",
" test purpose, see CMA_stds for production'\n",
" CSA_clip_length_value='None #v untested, [0, 0] means disregarding length\n",
" completely'\n",
" CSA_damp_mueff_exponent='0.5 # zero would mean no dependency of damping on\n",
" mueff, useful with CSA_disregard_length option'\n",
" CSA_dampfac='1 #v positive multiplier for step-size damping, 0.3 is close to\n",
" optimal on the sphere'\n",
" CSA_disregard_length='False #v True is untested'\n",
" CSA_squared='False #v use squared length for sigma-adaptation '\n",
" boundary_handling='BoundTransform # or BoundPenalty, unused when ``bounds in\n",
" (None, [None, None])``'\n",
" bounds='[None, None] # lower (=bounds[0]) and upper domain boundaries, each a\n",
" scalar or a list/vector'\n",
" fixed_variables='None # dictionary with index-value pairs like {0:1.1, 2:0.1}\n",
" that are not optimized'\n",
" ftarget='-inf #v target function value, minimization'\n",
" is_feasible='is_feasible #v a function that computes feasibility, by default\n",
" lambda x, f: f not in (None, np.NaN)'\n",
" maxfevals='inf #v maximum number of function evaluations'\n",
" maxiter='100 + 50 * (N+3)**2 // popsize**0.5 #v maximum number of iterations'\n",
" maxstd='inf #v maximal std in any coordinate direction'\n",
" mean_shift_line_samples='False #v sample two new solutions colinear to previous\n",
" mean shift'\n",
" mindx='0 #v minimal std in any direction, cave interference with tol*'\n",
" minstd='0 #v minimal std in any coordinate direction, cave interference with\n",
" tol*'\n",
" pc_line_samples='False #v two line samples along the evolution path pc'\n",
" popsize='4+int(3*log(N)) # population size, AKA lambda, number of new solution\n",
" per iteration'\n",
" randn='np.random.standard_normal #v randn((lam, N)) must return an np.array of\n",
" shape (lam, N)'\n",
" scaling_of_variables='None # (rather use CMA_stds) scale for each variable,\n",
" sigma0 is interpreted w.r.t. this scale, in that effective_sigma0 =\n",
" sigma0*scaling. Internally the variables are divided by\n",
" scaling_of_variables and sigma is unchanged, default is np.ones(N)'\n",
" seed='None # random number seed'\n",
" signals_filename='cmaes_signals.par # read from this file, e.g. \"stop now\"'\n",
" termination_callback='None #v a function returning True for termination,\n",
" called after each iteration step and could be abused for side effects'\n",
" tolfacupx='1e3 #v termination when step-size increases by tolfacupx\n",
" (diverges). That is, the initial step-size was chosen far too small and\n",
" better solutions were found far away from the initial solution x0'\n",
" tolfun='1e-11 #v termination criterion: tolerance in function value, quite\n",
" useful'\n",
" tolfunhist='1e-12 #v termination criterion: tolerance in function value\n",
" history'\n",
" tolstagnation='int(100 + 100 * N**1.5 / popsize) #v termination if no\n",
" improvement over tolstagnation iterations'\n",
" tolupsigma='1e20 #v sigma/sigma0 > tolupsigma * max(sqrt(eivenvals(C)))\n",
" indicates \"creeping behavior\" with usually minor improvements'\n",
" tolx='1e-11 #v termination criterion: tolerance in x-changes'\n",
" transformation='None # [t0, t1] are two mappings, t0 transforms solutions from\n",
" CMA-representation to f-representation (tf_pheno), t1 is the (optional)\n",
" back transformation, see class GenoPheno'\n",
" typical_x='None # used with scaling_of_variables'\n",
" updatecovwait='None #v number of iterations without distribution update, name\n",
" is subject to future changes'\n",
" verb_append='0 # initial evaluation counter, if append, do not overwrite\n",
" output files'\n",
" verb_disp='100 #v verbosity: display console output every verb_disp iteration'\n",
" verb_filenameprefix='outcmaes # output filenames prefix'\n",
" verb_log='1 #v verbosity: write data to files every verb_log iteration,\n",
" writing can be time critical on fast to evaluate functions'\n",
" verb_plot='0 #v in fmin(): plot() is called every verb_plot iteration'\n",
" verb_time='True #v output timings on console'\n",
" verbose='1 #v verbosity e.v. of initial/final message, -1 is very quiet, -9\n",
" maximally quiet, not yet fully implemented'\n",
" vv='0 #? versatile variable for hacking purposes, value found in\n",
" self.opts[\"vv\"]'\n"
]
}
],
"source": [
"opts.pprint()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -29,6 +29,8 @@ class BladePositioning:
s.maaR(config['pos_R'])
s.mpaL(config['pos_L']+cor(s.getposR()))
print ('cor: ', cor(s.getposR()))
def get_config(self):
config = {}
config['pos_R'] = s.getposR()
......
......@@ -16,7 +16,7 @@ def cor(R):
e_p=np.array([ 847.30650222, 502.90810925])
c_p=np.array([792,528])
e=e_p-c_p
return (np.cos(theta)*e[0]-np.sin(theta)*e[1])*ps2
return np.round((np.cos(theta)*e[0]-np.sin(theta)*e[1])*ps2,6)
#th=R0-np.linspace(0, 360, 100)
......
......@@ -53,15 +53,18 @@ def moverelL(dist):
cmd("MPR1,"+str(int(dist*1000000))+",60000")
def getposR():
ret=np.round(int(cmd("GA0",output=True)[4:-3].replace(",",""))/1000000.,2)
ret=np.round(int(cmd("GA0",output=True)[4:-3].replace(",",""))/1000000.,5)
return ret
def getposL():
ret=np.round(int(cmd("GP1", output=True)[4:-1])/1000000.,2)
ret=np.round(int(cmd("GP1", output=True)[4:-1])/1000000.,6)
return ret
def maaR(angle):
rev=-1
print (angle)
cmd("MAA0,"+str(int(angle*1000000))+","+str(rev)+",60000")
#while cmd("GS0",output=True)[-2]!=str(3):
#print(cmd("GS0",output=True)[-2])
......@@ -75,10 +78,16 @@ def maaR(angle):
def mpaL(pos):
cmd("MPA1,"+str(int(pos*1000000))+",60000")
print ('desired position: ',pos)
assert (not(pos < -5.3507 or pos > 0.522162))
cmd("MPA1,"+str(int(pos*1e6))+",60000")
# while cmd("GS1",output=True)[-2]!=str(3):
# time.sleep(0.2)
while abs(getposL()-pos)>0.009:
while abs(getposL()-pos)>0.001:
print ('current position: ',getposL())
time.sleep(0.2)
def movetoR(angle, direction):
......
......@@ -30,6 +30,8 @@ class FaradayCup:
def get_config(self):
config = {}
config['channel'] = self.channel
config['amplification'] = self.amplification
config['R'] = self.R
return config
def measure(self):
......
......@@ -44,7 +44,8 @@ time: time (datetime object)
im1: first image
im2: second image
'''
mode = {False: 'Off', True: 'On'}
modei = {'Off': False, 'On': True}
class Interferometer:
#mendatory functions
......@@ -71,7 +72,7 @@ class Interferometer:
self.take_data = config['take_data']
self.cam.properties['PixelFormat'] = 'Mono'+str(config['BitsOfImage'])
self.cam.properties['ExposureTimeAbs']=config['ExposureTimeAbs']
self.cam.properties['TriggerMode']=config['TriggerMode']
self.cam.properties['TriggerMode']=mode[config['TriggerMode']]
self.xmin, self.xmax, self.zmin, self.zmax = (config['xmin'], config['xmax'],
config['zmin'], config['zmax'])
self.x0, self.z0 = (config['x0'], config['z0'])
......@@ -84,7 +85,7 @@ class Interferometer:
def get_config(self):
config = {}
config['ExposureTimeAbs'] = self.cam.properties['ExposureTimeAbs']
config['TriggerMode'] = self.cam.properties['TriggerMode']
config['TriggerMode'] = modei[self.cam.properties['TriggerMode']]
config['BitsOfImage'] = int(self.cam.properties['PixelFormat'][4:])
config['xmin'], config['xmax'],config['zmin'], config['zmax']= (self.xmin, self.xmax, self.zmin, self.zmax)
config['x0'], config['z0'] = (self.x0, self.z0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment