Skip to content
Snippets Groups Projects
Commit be683e58 authored by Andreas Freise's avatar Andreas Freise
Browse files

moving from shelve to pickle

parent 42810831
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,8 @@ from __future__ import unicode_literals
from pykat import finesse
from pykat.commands import *
import copy
import shelve
#import shelve
import pickle
import sys
import scipy.optimize
......@@ -89,10 +90,12 @@ def main():
print(" current results saved in: {0}".format(tmpresultfile))
# first the current kat file
kat.saveScript(tmpkatfile)
# now the result variables:
tmpfile = shelve.open(tmpresultfile, flag="c")
tmpfile[str('result')]=result
tmpfile.close()
with open(tmpresultfile, 'wb') as handle:
pickle.dump(result, handle)
# now the result variables (former version usuing shelve):
#tmpfile = shelve.open(tmpresultfile, flag="c")
#tmpfile[str('result')]=result
#tmpfile.close()
#---------------------------------------------------------------------------
......
......@@ -9,7 +9,8 @@ import pylab as pl
import scipy
from scipy.optimize import fmin
import numpy as np
import shelve
import pickle
#import shelve
import copy
import sys
......@@ -51,9 +52,11 @@ def main():
# loading data saved by master.py
kat.loadKatFile('asc_base2.kat')
try:
tmpfile = shelve.open(tmpresultfile, flag="c")
result=tmpfile[str('result')]
tmpfile.close()
#tmpfile = shelve.open(tmpresultfile, flag="c")
#result=tmpfile[str('result')]
#tmpfile.close()
with open(tmpresultfile, 'rb') as handle:
result = pickle.load(handle)
except: raise Exception("Could not open temprary results file {0}".format(tmpresultfile))
# overwriting some variables
......@@ -125,9 +128,11 @@ def main():
# first the current kat file
kat.saveScript(tmpkatfile)
# now the result variables:
tmpfile = shelve.open(tmpresultfile)
tmpfile[str('result')]=result
tmpfile.close()
#tmpfile = shelve.open(tmpresultfile)
#tmpfile[str('result')]=result
#tmpfile.close()
with open(tmpresultfile, 'wb') as handle:
pickle.dump(result, handle)
#-----------------------------------------------------------------------------------
......@@ -186,7 +191,7 @@ def asc_phases(tmpkat):
kat.WFS1_I.phase1=x[0]
out = kat.run()
signal = out["WFS1_I"]
print('\r minimising: function value %g ' % signal, end=' ')
print('\r minimising: function value {0:<16g}'.format(float(signal)), end='')
sys.stdout.flush()
return -1*abs(signal)
......@@ -194,7 +199,7 @@ def asc_phases(tmpkat):
kat.WFS2_I.phase1=x[0]
out = kat.run()
signal = out["WFS2_I"]
print('\r minimising: function value %g ' % signal, end=' ')
print('\r minimising: function value {0:<16g}'.format(float(signal)), end='')
sys.stdout.flush()
return -1*abs(signal)
......
......@@ -6,7 +6,7 @@ from __future__ import unicode_literals
from pykat import finesse
from pykat.commands import *
import numpy as np
import shelve
import pickle
import copy
import sys
import shutil
......@@ -48,9 +48,11 @@ def main():
# loading data saved by master.py
kat.loadKatFile('asc_base3.kat')
try:
tmpfile = shelve.open(tmpresultfile)
result=tmpfile[str('result')]
tmpfile.close()
with open(tmpresultfile, 'rb') as handle:
result = pickle.load(handle)
#tmpfile = shelve.open(tmpresultfile)
#result=tmpfile[str('result')]
#tmpfile.close()
except: raise Exception("Could not open temprary results file {0}".format(tmpresultfile))
kat.PDrefl_q.enabled = False
......@@ -103,10 +105,13 @@ def asc_large(tmpkat, mir_name):
shutil.copyfile(tmpfilename, backupname)
print(" current results saved in: {0}".format(tmpfilename))
tmpfile = shelve.open(tmpfilename)
tmpfile[str('out')]=out
tmpfile[str('maxtems')]=done_maxtems
tmpfile.close()
with open(tmpfilename, 'wb') as handle:
pickle.dump({ "out": out, "maxtems": done_maxtems}, handle)
#tmpfile = shelve.open(tmpfilename)
#tmpfile[str('out')]=out
#tmpfile[str('maxtems')]=done_maxtems
#tmpfile.close()
if __name__ == '__main__':
......
......@@ -7,7 +7,7 @@ from pykat import finesse
from pykat.commands import *
import pylab as pl
import numpy as np
import shelve
import pickle
import sys
import matplotlib
......@@ -61,10 +61,13 @@ def asc_large(mir_name):
backupname = "datashelf_{0}.dat.bck".format(mir_name)
try:
tmpfile = shelve.open(tmpfilename)
out=tmpfile[str('out')]
maxtems=tmpfile[str('maxtems')]
tmpfile.close()
#tmpfile = shelve.open(tmpfilename)
#out=tmpfile[str('out')]
#maxtems=tmpfile[str('maxtems')]
#tmpfile.close()
readpickle = pickle.load(open(tmpfilename, "rb"))
out=readpickle['out']
maxtems=readpickle['maxtems']
except: raise Exception("Could not open temprary results file {0}".format(tmpfilename))
fig=pl.figure()
......
......@@ -11,7 +11,7 @@ import pylab as pl
import scipy
from scipy.optimize import minimize_scalar
import numpy as np
import shelve
import pickle
import copy
import sys
......@@ -59,9 +59,11 @@ def main():
# loading data saved by master.py
kat.loadKatFile('asc_base3.kat')
try:
tmpfile = shelve.open(tmpresultfile)
result=tmpfile[str('result')]
tmpfile.close()
with open(tmpresultfile, 'rb') as handle:
result = pickle.load(handle)
#tmpfile = shelve.open(tmpresultfile)
#result=tmpfile[str('result')]
#tmpfile.close()
except: raise Exception("Could not open temprary results file {0}".format(tmpresultfile))
# this does not work yet due to the scale command
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment