Skip to content
Snippets Groups Projects
Commit c60cf353 authored by Michael DM Dryden's avatar Michael DM Dryden
Browse files

Plot autosaving added (completes #16). Saving can now overwrite existing...

Plot autosaving added (completes #16). Saving can now overwrite existing files. Fixed CV/CSWV text saving (#5)—no longer uses numpy's text saving.
parent 34e71876
Branches
Tags
No related merge requests found
......@@ -3,6 +3,7 @@
import gtk, io, os
import numpy as np
from datetime import datetime
def manSave(current_exp):
exp = current_exp
......@@ -78,41 +79,76 @@ def autoSave(current_exp, dir_button, name, expnumber):
path += name
path += str(expnumber)
text(current_exp, path)
text(current_exp, path, auto=True)
def autoPlot(plot, dir_button, name, expnumber):
if name == "":
name = "file"
path = dir_button.get_filename()
path += '/'
path += name
path += str(expnumber)
if path.endswith(".pdf"):
path = path.rstrip(".pdf")
def npy(exp, path):
if path.endswith(".npy"):
path = path.rstrip(".npy")
data = np.array(exp.data)
j = 1
while os.path.exists("".join([path, ".npy"])):
while os.path.exists("".join([path, ".pdf"])):
if j > 1:
path = path[:-len(str(j))]
path += str(j)
j += 1
path += ".pdf"
plot.figure.savefig(path)
def npy(exp, path, auto=False):
if path.endswith(".npy"):
path = path.rstrip(".npy")
data = np.array(exp.data)
if auto == True:
j = 1
while os.path.exists("".join([path, ".npy"])):
if j > 1:
path = path[:-len(str(j))]
path += str(j)
j += 1
np.save(path, data)
def text(exp, path):
def text(exp, path, auto=False):
if path.endswith(".txt"):
path = path.rstrip(".txt")
j = 1
while os.path.exists("".join([path, ".txt"])):
if j > 1:
path = path[:-len(str(j))]
path += str(j)
j += 1
if auto == True:
j = 1
while os.path.exists("".join([path, ".txt"])):
if j > 1:
path = path[:-len(str(j))]
path += str(j)
j += 1
path += ".txt"
file = open(path, 'w')
time = datetime.now()
data = np.array(exp.data)
header = ""
header = "".join(['#', time.isoformat(), "\n#"])
for i in exp.commands:
header += i
np.savetxt(path, data.transpose(), header=header, newline='\n')
file.write("".join([header, '\n']))
for col in zip(*exp.data):
for row in col:
file.write(str(row)+ " ")
file.write('\n')
file.close()
......@@ -522,7 +522,7 @@ class main:
def experiment_done(self):
gobject.source_remove(self.plot_proc) #stop automatic plot update
self.experiment_running_plot() #make sure all data updated on plot
self.databuffer.set_text("")
self.databuffer.place_cursor(self.databuffer.get_start_iter())
self.rawbuffer.insert_at_cursor("\n")
......@@ -531,18 +531,19 @@ class main:
for col in zip(*self.current_exp.data):
for row in col:
self.rawbuffer.insert_at_cursor(str(row)+ "\t")
self.rawbuffer.insert_at_cursor(str(row)+ " ")
self.rawbuffer.insert_at_cursor("\n")
if self.current_exp.data_extra:
for col in zip(*self.current_exp.data_extra):
for row in col:
self.databuffer.insert_at_cursor(str(row)+ "\t")
self.databuffer.insert_at_cursor(str(row)+ " ")
self.databuffer.insert_at_cursor("\n")
if self.autosave_checkbox.get_active():
save_inst = save.autoSave(self.current_exp, self.autosavedir_button, self.autosavename.get_text(), self.expnumber)
save.autoSave(self.current_exp, self.autosavedir_button, self.autosavename.get_text(), self.expnumber)
save.autoPlot(self.plot, self.autosavedir_button, self.autosavename.get_text(), self.expnumber)
self.expnumber += 1
self.spinner.stop()
......
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