From c60cf3533531079f5dcdcf13a3fdd7e9d07f5a82 Mon Sep 17 00:00:00 2001 From: "Michael D. M. Dryden" <mdryden@chem.utoronto.ca> Date: Tue, 5 Aug 2014 17:37:54 -0400 Subject: [PATCH] =?UTF-8?q?Plot=20autosaving=20added=20(completes=20#16).?= =?UTF-8?q?=20Saving=20can=20now=20overwrite=20existing=20files.=20Fixed?= =?UTF-8?q?=20CV/CSWV=20text=20saving=20(#5)=E2=80=94no=20longer=20uses=20?= =?UTF-8?q?numpy's=20text=20saving.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dstatInterface/interface/save.py | 70 ++++++++++++++++++++++++-------- dstatInterface/interface_test.py | 9 ++-- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/dstatInterface/interface/save.py b/dstatInterface/interface/save.py index f472a98..4456d08 100644 --- a/dstatInterface/interface/save.py +++ b/dstatInterface/interface/save.py @@ -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() diff --git a/dstatInterface/interface_test.py b/dstatInterface/interface_test.py index 0b58a69..e6d74e8 100644 --- a/dstatInterface/interface_test.py +++ b/dstatInterface/interface_test.py @@ -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() -- GitLab