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