From 78570badb6de9d0111d42202e6577a3efbab2931 Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 6 Oct 2016 12:05:25 -0700 Subject: [PATCH 1/3] Handle and export 4 channels in .npy and CSV --- TekScopeGUI.py | 57 +++++++++++++++++++++++++++++++++++++++++++++----- instrument.py | 2 +- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/TekScopeGUI.py b/TekScopeGUI.py index c2c6acd..dd9f6e0 100644 --- a/TekScopeGUI.py +++ b/TekScopeGUI.py @@ -34,7 +34,8 @@ def __init__(self): wx.Frame.__init__(self, None, -1, self.title) self.data = [0, 0, 0, 0, 0] - + self.xdata = range(len(self.data)) + self.create_menu() self.create_status_bar() self.create_main_panel() @@ -45,8 +46,10 @@ def create_menu(self): self.menubar = wx.MenuBar() menu_file = wx.Menu() - m_expt = menu_file.Append(-1, "&Save data\tCtrl-S", "Save data to file") + m_expt = menu_file.Append(-1, "&Save data to Numpy\tCtrl-S", "Save data to Numpy file") self.Bind(wx.EVT_MENU, self.on_save_data, m_expt) + m_expt = menu_file.Append(-1, "&Save data to CSV\tCtrl-Shift-S", "Save data to CSVfile") + self.Bind(wx.EVT_MENU, self.on_save_data_csv, m_expt) menu_file.AppendSeparator() m_exit = menu_file.Append(-1, "E&xit\tCtrl-X", "Exit") self.Bind(wx.EVT_MENU, self.on_exit, m_exit) @@ -87,6 +90,13 @@ def create_main_panel(self): self.ch2button = wx.Button(self.panel, -1, "CH2") self.Bind(wx.EVT_BUTTON, self.on_ch2_button, self.ch2button) + self.ch3button = wx.Button(self.panel, -1, "CH3") + self.Bind(wx.EVT_BUTTON, self.on_ch3_button, self.ch3button) + + self.ch4button = wx.Button(self.panel, -1, "CH4") + self.Bind(wx.EVT_BUTTON, self.on_ch4_button, self.ch4button) + + self.refabutton = wx.Button(self.panel, -1, "RefA") self.Bind(wx.EVT_BUTTON, self.on_refa_button, self.refabutton) @@ -115,6 +125,8 @@ def create_main_panel(self): flags = wx.ALIGN_LEFT | wx.ALL | wx.ALIGN_CENTER_VERTICAL self.hbox.Add(self.ch1button, 0, border=3, flag=flags) self.hbox.Add(self.ch2button, 0, border=3, flag=flags) + self.hbox.Add(self.ch3button, 0, border=3, flag=flags) + self.hbox.Add(self.ch4button, 0, border=3, flag=flags) self.hbox.Add(self.refabutton, 0, border=3, flag=flags) self.hbox.Add(self.refbbutton, 0, border=3, flag=flags) self.hbox.Add(self.cb_grid, 0, border=3, flag=flags) @@ -131,12 +143,12 @@ def create_status_bar(self): def draw_figure(self): """ Redraws the figure """ - + # clear the axes and redraw the plot anew self.axes.clear() self.axes.grid(self.cb_grid.IsChecked()) - self.axes.plot(self.data) + self.axes.plot([i*1000 for i in self.xdata], self.data) self.canvas.draw() def on_cb_grid(self, event): @@ -144,18 +156,32 @@ def on_cb_grid(self, event): def on_ch1_button(self, event): self.data = inst.get_data("CH1") + self.xdata = inst.get_xdata() self.draw_figure() def on_ch2_button(self, event): self.data = inst.get_data("CH2") + self.xdata = inst.get_xdata() + self.draw_figure() + + def on_ch3_button(self, event): + self.data = inst.get_data("CH3") + self.xdata = inst.get_xdata() self.draw_figure() + def on_ch4_button(self, event): + self.data = inst.get_data("CH4") + self.xdata = inst.get_xdata() + self.draw_figure() + def on_refa_button(self, event): self.data = inst.get_data("REFA") + self.xdata = inst.get_xdata() self.draw_figure() def on_refb_button(self, event): self.data = inst.get_data("REFB") + self.xdata = inst.get_xdata() self.draw_figure() def on_save_data(self, event): @@ -172,9 +198,30 @@ def on_save_data(self, event): if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() #self.canvas.print_figure(path, dpi=self.dpi) - numpy.save(path, self.data) + numpy.save(path, (self.xdata, self.data)) + self.flash_status_message("Data saved to %s" % path) + + def on_save_data_csv(self, event): + file_choices = "CSV (*.csv)|*.csv" + + dlg = wx.FileDialog( + self, + message="Save data as...", + defaultDir=os.getcwd(), + defaultFile="data", + wildcard=file_choices, + style=wx.SAVE) + + if dlg.ShowModal() == wx.ID_OK: + path = dlg.GetPath() + #self.canvas.print_figure(path, dpi=self.dpi) + out = numpy.zeros((len(self.data), 2)) + for (i,l) in enumerate(zip(self.xdata, self.data)): + out[i,:] = l + numpy.savetxt(path, out) self.flash_status_message("Data saved to %s" % path) + def on_exit(self, event): self.Destroy() diff --git a/instrument.py b/instrument.py index 2b76a26..05181f6 100644 --- a/instrument.py +++ b/instrument.py @@ -96,7 +96,7 @@ def get_xdata(self): self.write("HORIZONTAL:RECORDLENGTH?") time_size = int(self.read(30)) - time = numpy.arange(0,timescale*10,timescale*10/time_size) + time = numpy.arange(0,timescale*10,timescale*10/time_size*2) # For some reason the output was too short compared to the data buffer return time From ce10fad18d8b285239218465e5550ba07fecb934 Mon Sep 17 00:00:00 2001 From: Maxime Date: Thu, 6 Oct 2016 12:23:10 -0700 Subject: [PATCH 2/3] Updated README so to mention wxgtk dependency --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 64b3050..a75f002 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ Requirements: matplotlib numpy -python-usbtmc (installed with pip) +wxgtk (installed for instance from `sudo apt-get install python-wxgtk3.0`) +python-usbtmc (installed with `pip`) pypi.python.org/pypi/python-usbtmc From dfb1f087993ebaf3625410530b1f7538f79833f6 Mon Sep 17 00:00:00 2001 From: "Andrew M. C. Dawes" Date: Tue, 25 Oct 2016 13:17:23 -0700 Subject: [PATCH 3/3] Update README.md --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 64b3050..852a8ef 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,13 @@ Instruments Python code for interacting with our lab instruments via USBTMC -TekScope - Textronix TDS1000-series scopes -RigolDG - Rigol DG4102 Arb Gen. + - TekScope - Textronix TDS1000-series scopes + - RigolDG - Rigol DG4102 Arb Gen. Requirements: - -matplotlib -numpy -python-usbtmc (installed with pip) -pypi.python.org/pypi/python-usbtmc + - matplotlib + - numpy + - python-usbtmc (installed with pip) pypi.python.org/pypi/python-usbtmc + - wxgtk