class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def Open_Geoplot(self): self.fname = QtGui.QFileDialog.getOpenFileName() self.Plot_Function() def Plot_Function(self): #Get values from Options Grid self.grid_length = self.TravL_val.value() self.grid_width = self.GridL_val.value() self.sample_interval = self.TravI_val.value() self.traverse_interval = self.GridI_val.value() self.output = Load_Comp(self.fname, self.grid_length, self.grid_width, self.sample_interval, self.traverse_interval) self.mpl.canvas.ax.clear() print np.shape(self.output) self.mpl.canvas.ax.imshow( self.output, cmap=plt.cm.Greys, extent=[0, self.grid_length, self.grid_width, 0], aspect='equal', interpolation='none', vmin=self.neg_val.value(), vmax=self.pos_val.value()) self.mpl.canvas.draw() def plot_options(self): self.neg_label = QtGui.QLabel('Neg Value', self) self.neg_val = QtGui.QDoubleSpinBox(self) self.neg_val.setRange(-100, 100) self.neg_val.setValue(-1) self.pos_label = QtGui.QLabel('Pos Value', self) self.pos_val = QtGui.QDoubleSpinBox(self) self.pos_val.setRange(-100, 100) self.pos_val.setValue(2) self.TravL_label = QtGui.QLabel('Trav Length', self) self.TravL_val = QtGui.QDoubleSpinBox(self) self.TravL_val.setRange(0, 1000) self.TravL_val.setValue(30) self.TravI_label = QtGui.QLabel('Sample Interval', self) self.TravI_val = QtGui.QDoubleSpinBox(self) self.TravI_val.setValue(0.25) self.GridL_label = QtGui.QLabel('Grid Width', self) self.GridL_val = QtGui.QDoubleSpinBox(self) self.GridL_val.setRange(0, 1000) self.GridL_val.setValue(30) self.GridI_label = QtGui.QLabel('Traverse Interval', self) self.GridI_val = QtGui.QDoubleSpinBox(self) self.GridI_val.setValue(1) self.Scale_label = QtGui.QLabel('Scale Value', self) self.Scale_val = QtGui.QDoubleSpinBox(self) self.Scale_val.setRange(1, 5000) self.Scale_val.setValue(500) self.Clip_label = QtGui.QLabel('Clipping Value', self) self.Clip_val = QtGui.QDoubleSpinBox(self) self.Clip_val.setRange(0.1, 100) self.Clip_val.setValue(15) self.Grid_horizontal_Layout_1.addWidget(self.TravL_label) self.Grid_horizontal_Layout_1.addWidget(self.TravL_val) self.Grid_horizontal_Layout_1.addWidget(self.TravI_label) self.Grid_horizontal_Layout_1.addWidget(self.TravI_val) self.Grid_horizontal_Layout_2.addWidget(self.GridL_label) self.Grid_horizontal_Layout_2.addWidget(self.GridL_val) self.Grid_horizontal_Layout_2.addWidget(self.GridI_label) self.Grid_horizontal_Layout_2.addWidget(self.GridI_val) self.Grid_horizontal_Layout_3 = QtGui.QHBoxLayout() self.Grid_horizontal_Layout_3.setObjectName("Grid_horizontal_Layout_3") self.Options_Grid.addLayout(self.Grid_horizontal_Layout_3, 2, 0, 1, 1) self.Grid_horizontal_Layout_3.addWidget(self.neg_label) self.Grid_horizontal_Layout_3.addWidget(self.neg_val) self.Grid_horizontal_Layout_3.addWidget(self.pos_label) self.Grid_horizontal_Layout_3.addWidget(self.pos_val) self.Grid_horizontal_Layout_4 = QtGui.QHBoxLayout() self.Grid_horizontal_Layout_4.setObjectName("Grid_horizontal_Layout_4") self.Options_Grid.addLayout(self.Grid_horizontal_Layout_4, 3, 0, 1, 1) self.Grid_horizontal_Layout_4.addWidget(self.Scale_label) self.Grid_horizontal_Layout_4.addWidget(self.Scale_val) self.Grid_horizontal_Layout_4.addWidget(self.Clip_label) self.Grid_horizontal_Layout_4.addWidget(self.Clip_val) def Button_Definitions(self): self.firstrun = True self.Open_button = QtGui.QPushButton('Open', self) self.fname = self.Open_button.clicked.connect(self.Open_Geoplot) self.Button_Layout.addWidget(self.Open_button) self.Save_button = QtGui.QPushButton('Save as DXF', self) self.Save_button.clicked.connect(self.dxf_save_button) self.Button_Layout.addWidget(self.Save_button) self.pushButton_plot.clicked.connect(self.Plot_Function) self.pushButton_clear.clicked.connect(self.ClearPlot) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"), self, self.Plot_Function) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard) def dxf_save_button(self): self.dxf_name = QtGui.QFileDialog.getSaveFileName(self) self.Scale = self.Scale_val.value() self.Clip = self.Clip_val.value() QtGui.QMessageBox.about( self, "This May take a second", "Saving DXF's can be slow, please be paient. \n A dialogue will open when finished" ) comp2dxf(self.output, self.dxf_name, self.sample_interval, self.traverse_interval, self.Scale, self.Clip, 'CMP2DXF') QtGui.QMessageBox.about( self, "Thanks for waiting", "Sorry about the wait, DXFengine is slow. \n The DXF has been saved. " ) def __init__(self, parent=None): # initialization of the superclass super(ArchaeoPYMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.Button_Definitions() self.plot_options()
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def Open_Geoplot(self): self.fname = QtGui.QFileDialog.getOpenFileName() def Plot_Function(self): #Get values from Options Grid grid_length = self.TravL_val.value() grid_width = self.GridL_val.value() sample_interval = self.TravI_val.value() traverse_interval = self.GridI_val.value() self.output = Load_Comp(self.fname,grid_length,grid_width,sample_interval,traverse_interval) self.mpl.canvas.ax.clear() print np.shape(self.output) self.mpl.canvas.ax.imshow(self.output,cmap=plt.cm.Greys,extent=[0,grid_length,grid_width,0], aspect='equal',interpolation='none',vmin = self.neg_val.value(), vmax = self.pos_val.value()) self.mpl.canvas.draw() def Plot_Median_Filter(self): grid_length = self.TravL_val.value() grid_width = self.GridL_val.value() sample_interval = self.TravI_val.value() traverse_interval = self.GridI_val.value() self.output = Load_Comp(self.fname,grid_length,grid_width,sample_interval,traverse_interval) self.filter_output = median_filter(self.output) self.mpl.canvas.ax.clear() print np.shape(self.output) self.mpl.canvas.ax.imshow(self.filter_output,cmap=plt.cm.Greys,extent=[0,grid_length,grid_width,0], aspect='equal',interpolation='none',vmin = self.neg_val.value(), vmax = self.pos_val.value()) self.mpl.canvas.draw() def plot_options(self): self.neg_label = QtGui.QLabel('Neg Value', self) self.neg_val = QtGui.QDoubleSpinBox(self) self.neg_val.setRange(-100, 100) self.neg_val.setValue(-1) self.pos_label = QtGui.QLabel('Pos Value', self) self.pos_val = QtGui.QDoubleSpinBox(self) self.pos_val.setRange(-100, 100) self.pos_val.setValue(2) self.TravL_label = QtGui.QLabel('Trav Length', self) self.TravL_val = QtGui.QDoubleSpinBox(self) self.TravL_val.setRange(0, 1000) self.TravL_val.setValue(30) self.TravI_label = QtGui.QLabel('Sample Interval', self) self.TravI_val = QtGui.QDoubleSpinBox(self) self.TravI_val.setValue(0.25) self.GridL_label = QtGui.QLabel('Grid Width', self) self.GridL_val = QtGui.QDoubleSpinBox(self) self.GridL_val.setRange(0, 1000) self.GridL_val.setValue(30) self.GridI_label = QtGui.QLabel('Traverse Interval', self) self.GridI_val = QtGui.QDoubleSpinBox(self) self.GridI_val.setValue(1) self.Grid_horizontal_Layout_1.addWidget(self.TravL_label) self.Grid_horizontal_Layout_1.addWidget(self.TravL_val) self.Grid_horizontal_Layout_1.addWidget(self.TravI_label) self.Grid_horizontal_Layout_1.addWidget(self.TravI_val) self.Grid_horizontal_Layout_2.addWidget(self.GridL_label) self.Grid_horizontal_Layout_2.addWidget(self.GridL_val) self.Grid_horizontal_Layout_2.addWidget(self.GridI_label) self.Grid_horizontal_Layout_2.addWidget(self.GridI_val) self.Grid_horizontal_Layout_3 = QtGui.QHBoxLayout() self.Grid_horizontal_Layout_3.setObjectName("Grid_horizontal_Layout_3") self.Options_Grid.addLayout(self.Grid_horizontal_Layout_3, 2, 0, 1, 1) self.Grid_horizontal_Layout_3.addWidget(self.neg_label) self.Grid_horizontal_Layout_3.addWidget(self.neg_val) self.Grid_horizontal_Layout_3.addWidget(self.pos_label) self.Grid_horizontal_Layout_3.addWidget(self.pos_val) def Button_Definitions(self): self.firstrun=True self.Open_button = QtGui.QPushButton('Open', self) self.fname = self.Open_button.clicked.connect(self.Open_Geoplot) self.Button_Layout.addWidget(self.Open_button) self.pushButton_plot.clicked.connect(self.Plot_Function) self.pushButton_clear.clicked.connect(self.ClearPlot) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"),self, self.Plot_Function) self.Save_button = QtGui.QPushButton('Save as .txt',self) self.Save_button.clicked.connect(self.save_as_txt) self.Button_Layout.addWidget(self.Save_button) self.pushButton = QtGui.QPushButton('Median Filter',self) self.pushButton.clicked.connect(self.Plot_Median_Filter) self.pushButton_clear.clicked.connect(self.ClearPlot) #QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"),self, self.Plot_Function) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"),self, self.copy_to_clipboard) def save_as_txt(self): self.txt_name = QtGui.QFileDialog.getSaveFileName(self) np.savetxt(self.txt_name + '.txt', self.output) def __init__(self, parent = None): # initialization of the superclass super(ArchaeoPYMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.Button_Definitions() self.plot_options()
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() #Clears Legend def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def Open_File(self): self.fname = QtGui.QFileDialog.getOpenFileName() #Opes File with open(self.fname, 'r') as f: self.num_cols = len(f.readline().split(',')) f.seek(0) self.array = np.genfromtxt(f, dtype=float, delimiter=',', skiprows=1, filling_values=np.nan) self.chart_title.clear() #Display file path in GUI self.chart_title.setText(self.fname) #print self.array def regrid(self): #Regrid CMD data array = self.array #set data num_cols = self.num_cols #set number of columns fname = self.fname #set filename if self.hcp_config.isChecked: #set Coil orientation config = 'HCP' else: config = 'VCP' grid = self.grid.text() #set grid(s) to be regridded samples_int = float(self.samples_int.text()) #Sampling Interval samples_start = float( self.samples_start.text()) #Sample starting position samples_stop = float(self.samples_stop.text()) #Sample ending position no_samples = (samples_stop - samples_start + samples_int ) / samples_int #number of amples down the line traverses_start = float( self.trav_start.text()) #Starting traverse number traverses_stop = float(self.trav_stop.text()) #Ending traverse number no_traverses = (traverses_stop - traverses_start + float(self.trav_int.text())) / float( self.trav_int.text()) #Number of traverses #Regrid data regrid_cmd(fname, config, grid, array, num_cols, samples_start, samples_stop, no_samples, traverses_start, traverses_stop, no_traverses) def button_grid(self): #Defines button and layout #self.firstrun=True self.buttons_layout = QtGui.QGridLayout() self.buttons_box = QtGui.QGroupBox() self.buttons_box.setLayout(self.buttons_layout) self.survey_layout = QtGui.QGridLayout() self.survey_box = QtGui.QGroupBox() self.survey_box.setLayout(self.survey_layout) #File Properties self.Grid_horizontal_Layout_2.addWidget(self.buttons_box, 1) string = '<span style=" font-size:10pt;; font-weight:600;">File Settings</span>' self.buttons_layout_text = QtGui.QLabel(string, self) self.buttons = QtGui.QButtonGroup() self.open_button = QtGui.QPushButton('Open', self) self.buttons.addButton(self.open_button) self.open_button.clicked.connect(self.Open_File) self.regrid_button = QtGui.QPushButton('Regrid', self) self.buttons.addButton(self.regrid_button) self.regrid_button.clicked.connect(self.regrid) self.clear_button = QtGui.QPushButton('Clear', self) self.buttons.addButton(self.clear_button) self.clear_button.clicked.connect(self.ClearPlot) self.chart_title = QtGui.QLineEdit(self) self.config_lbl = QtGui.QLabel('Orientation', self) self.hcp_config = QtGui.QRadioButton('HCP', self) self.vcp_config = QtGui.QRadioButton('VCP', self) self.grid = QtGui.QLineEdit(self) self.grid.setText('Enter Grid Number') self.buttons_layout.addWidget(self.buttons_layout_text, 0, 0, 1, 4) self.buttons_layout.addWidget(self.open_button, 1, 0) self.buttons_layout.addWidget(self.regrid_button, 2, 0) self.buttons_layout.addWidget(self.clear_button, 3, 0) self.buttons_layout.addWidget(self.chart_title, 4, 0) self.buttons_layout.addWidget(self.config_lbl, 1, 1) self.buttons_layout.addWidget(self.hcp_config, 2, 1) self.buttons_layout.addWidget(self.vcp_config, 3, 1) self.buttons_layout.addWidget(self.grid, 4, 1) #survey parameters self.Grid_horizontal_Layout_2.addWidget(self.survey_box, 1) string = '<span style=" font-size:10pt;; font-weight:600;">Survey Parameters</span>' self.survey_layout_text = QtGui.QLabel(string, self) self.survey_buttons = QtGui.QButtonGroup() self.samples_start_lbl = QtGui.QLabel('Samples Start Position') self.samples_start = QtGui.QLineEdit(self) self.samples_stop_lbl = QtGui.QLabel('Samples End Position') self.samples_stop = QtGui.QLineEdit(self) self.samples_int_lbl = QtGui.QLabel('Sampling Interval') self.samples_int = QtGui.QLineEdit(self) self.trav_start_lbl = QtGui.QLabel('Traverses Start Position') self.trav_start = QtGui.QLineEdit(self) self.trav_stop_lbl = QtGui.QLabel('Traverses End Position') self.trav_stop = QtGui.QLineEdit(self) self.trav_int_lbl = QtGui.QLabel('Traverse Interval') self.trav_int = QtGui.QLineEdit(self) self.survey_layout.addWidget(self.survey_layout_text, 0, 0, 1, 2) self.survey_layout.addWidget(self.samples_start_lbl, 1, 0) self.survey_layout.addWidget(self.samples_start, 1, 1) self.survey_layout.addWidget(self.samples_stop_lbl, 2, 0) self.survey_layout.addWidget(self.samples_stop, 2, 1) self.survey_layout.addWidget(self.samples_int_lbl, 3, 0) self.survey_layout.addWidget(self.samples_int, 3, 1) self.survey_layout.addWidget(self.trav_start_lbl, 4, 0) self.survey_layout.addWidget(self.trav_start, 4, 1) self.survey_layout.addWidget(self.trav_stop_lbl, 5, 0) self.survey_layout.addWidget(self.trav_stop, 5, 1) self.survey_layout.addWidget(self.trav_int_lbl, 6, 0) self.survey_layout.addWidget(self.trav_int, 6, 1) def __init__(self, parent=None): # initialization of the superclass super(ArchaeoPYMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard) #self.xlabel = QtGui.QInputDialog.getText(self, 'X-axis Label') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.button_grid()
class TraverseMainWindow(QtGui.QMainWindow, Ui_MainWindow): def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def press_open(self): self.fname = QtGui.QFileDialog.getExistingDirectory( self, "Select Project") open_project(self.fname, self) self.statusbar.showMessage("press_open returned") self.repaint() def Open_File(self): self.fname = QtGui.QFileDialog.getOpenFileName() #self.f = open(self.fname, 'rb') with open(self.fname, 'r') as f: num_cols = len(f.readline().split(' ')) - 1 f.seek(0) data = np.genfromtxt(f, names=True, delimiter=' ', dtype=None, filling_values=np.nan, usecols=(range(0, num_cols))) return data #print data #print "beak" #return data #print data #print "break" def top_data(self): #print "beak" self.top_data = self.Open_File() print self.top_data.dtype.names #print data self.top_x = self.top_data.dtype.names #print self.data[self.data.dtype.names[1]] #print self.data[self.data.dtype.names[2]] #return self.top_x self.top_y = self.top_data.dtype.names #return self.top_y self.top_xcombo.clear() self.top_xcombo.addItems(self.top_x) self.top_ycombo.clear() self.top_ycombo.addItems(self.top_y) #Clears Legend #self.legend_definitions() def legend_definitions(self): self.handles = [] self.labels = [] self.colors = itertools.cycle(["b", "g", "r", "c", "m", "y", "b"]) self.markers = itertools.cycle([".", "D", "p", "*", "+"]) self.legend = self.mpl.canvas.fig.legend(self.handles, self.labels, 'upper right') def openInputDialog(self): x_axis, result = QtGui.QInputDialog.getText(self, "X axis", "Specify units") if result: self.x_axis = x_axis y_axis, result = QtGui.QInputDialog.getText(self, "Y axis", "Specify units") if result: self.y_axis = y_axis def button_grid(self): #An Expanding Spacer Item to be used anywhere.. spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.toolbar_grid.addItem(spacerItem, 0, 0, 1, 1) self.toolbar_grid.addItem(spacerItem, 0, 4, 1, 1) #self.Grid_horizontal_Layout_2.addItem(spacerItem, 0) #self.Grid_horizontal_Layout_2.addItem(spacerItem, 4) #Layout for processing toolbbox self.top_plot_layout = QtGui.QGridLayout() self.top_plot_box = QtGui.QGroupBox() self.top_plot_box.setLayout(self.top_plot_layout) self.middle_plot_layout = QtGui.QGridLayout() self.middle_plot_box = QtGui.QGroupBox() self.middle_plot_box.setLayout(self.middle_plot_layout) self.bottom_plot_layout = QtGui.QGridLayout() self.bottom_plot_box = QtGui.QGroupBox() self.bottom_plot_box.setLayout(self.bottom_plot_layout) #Traverse selector grid box self.Grid_horizontal_Layout_2.addWidget(self.top_plot_box, 0) #self.toolbar_grid.addLayout(self.top_plot_layout, 0, 1, 1, 1) string = '<span style=" font-size:14pt;; font-weight:600;">Top Plot</span>' self.top_plot_layout_text = QtGui.QLabel(string, self) #Defines push buttons for top plot self.top_plot_buttons = QtGui.QButtonGroup() self.top_open_button = QtGui.QPushButton('Open', self) self.top_fname = self.top_open_button.clicked.connect(self.top_data) self.top_plot_buttons.addButton(self.top_open_button) self.top_plot_button = QtGui.QPushButton('Plot', self) #self.top_fname = self.top_open_button.clicked.connect(self.Open_File) self.top_plot_buttons.addButton(self.top_plot_button) self.top_clear_button = QtGui.QPushButton('Clear', self) #self.top_fname = self.top_open_button.clicked.connect(self.Open_File) self.top_plot_buttons.addButton(self.top_clear_button) self.top_plot_input = QtGui.QButtonGroup() self.top_units = QtGui.QPushButton('Input Units', self) self.top_units.clicked.connect(self.openInputDialog) #Defines combo boxes for top plot self.top_plot_combo = QtGui.QButtonGroup() self.top_xcombo = QtGui.QComboBox() self.top_xcombo.addItems('X') self.top_xcombo_lbl = QtGui.QLabel('X Values', self) self.top_ycombo = QtGui.QComboBox() self.top_ycombo.addItems('Y') self.top_ycombo_lbl = QtGui.QLabel('Y Values', self) self.top_plot_layout.addWidget(self.top_plot_layout_text, 0, 0, 1, 4) self.top_plot_layout.addWidget(self.top_open_button, 1, 0) self.top_plot_layout.addWidget(self.top_plot_button, 2, 0) self.top_plot_layout.addWidget(self.top_clear_button, 3, 0) self.top_plot_layout.addWidget(self.top_units, 4, 0) self.top_plot_layout.addWidget(self.top_xcombo_lbl, 1, 1) self.top_plot_layout.addWidget(self.top_xcombo, 2, 1) self.top_plot_layout.addWidget(self.top_ycombo_lbl, 3, 1) self.top_plot_layout.addWidget(self.top_ycombo, 4, 1) self.top_plot_layout.addItem(spacerItem, 0, 0, 1, 1) self.top_plot_layout.addItem(spacerItem, 3, 0, 1, 1) #1st Pass Selector Box self.Grid_horizontal_Layout_2.addWidget(self.middle_plot_box, 1) #self.toolbar_grid.addLayout(self.middle_plot_layout, 0, 2, 1, 1) #Title of Box. HTML required to change colour & weight string = '<span style=" font-size:14pt;; font-weight:600;">Middle Plot</span>' self.middle_plot_layout_text = QtGui.QLabel(string, self) self.middle_plot_buttons = QtGui.QButtonGroup() self.middle_open_button = QtGui.QPushButton('Open', self) self.middle_fname = self.middle_open_button.clicked.connect( self.top_data) self.middle_plot_buttons.addButton(self.middle_open_button) self.middle_plot_button = QtGui.QPushButton('Plot', self) #self.middle_fname = self.middle_open_button.clicked.connect(self.Open_File) self.middle_plot_buttons.addButton(self.middle_plot_button) self.middle_clear_button = QtGui.QPushButton('Clear', self) #self.middle_fname = self.middle_open_button.clicked.connect(self.Open_File) self.middle_plot_buttons.addButton(self.middle_clear_button) self.middle_plot_input = QtGui.QButtonGroup() self.middle_units = QtGui.QPushButton('Input Units', self) self.middle_units.clicked.connect(self.openInputDialog) #Defines combo boxes for middle plot self.middle_plot_combo = QtGui.QButtonGroup() self.middle_xcombo = QtGui.QComboBox() self.middle_xcombo.addItems('X') self.middle_xcombo_lbl = QtGui.QLabel('X Values', self) self.middle_ycombo = QtGui.QComboBox() self.middle_ycombo.addItems('Y') self.middle_ycombo_lbl = QtGui.QLabel('Y Values', self) self.middle_plot_layout.addWidget(self.middle_plot_layout_text, 0, 0, 1, 4) self.middle_plot_layout.addWidget(self.middle_open_button, 1, 0) self.middle_plot_layout.addWidget(self.middle_plot_button, 2, 0) self.middle_plot_layout.addWidget(self.middle_clear_button, 3, 0) self.middle_plot_layout.addWidget(self.middle_units, 4, 0) self.middle_plot_layout.addWidget(self.middle_xcombo_lbl, 1, 1) self.middle_plot_layout.addWidget(self.middle_xcombo, 2, 1) self.middle_plot_layout.addWidget(self.middle_ycombo_lbl, 3, 1) self.middle_plot_layout.addWidget(self.middle_ycombo, 4, 1) #Bottom Plot Selector Box self.Grid_horizontal_Layout_2.addWidget(self.bottom_plot_box, 2) #self.toolbar_grid.addLayout(self.bottom_plot_layout, 0, 3, 1, 1) #Title of Box. HTML required to change colour & weight string = '<span style=" font-size:14pt;; font-weight:600;">Bottom Plot</span>' self.bottom_plot_layout_text = QtGui.QLabel(string, self) self.bottom_plot_buttons = QtGui.QButtonGroup() self.bottom_open_button = QtGui.QPushButton('Open', self) self.bottom_fname = self.bottom_open_button.clicked.connect( self.Open_File) self.bottom_plot_buttons.addButton(self.bottom_open_button) self.bottom_plot_button = QtGui.QPushButton('Plot', self) #self.bottom_fname = self.bottom_open_button.clicked.connect(self.Open_File) self.bottom_plot_buttons.addButton(self.bottom_plot_button) self.bottom_clear_button = QtGui.QPushButton('Clear', self) #self.bottom_fname = self.bottom_open_button.clicked.connect(self.Open_File) self.bottom_plot_buttons.addButton(self.bottom_clear_button) self.bottom_plot_input = QtGui.QButtonGroup() self.bottom_units = QtGui.QPushButton('Input Units', self) self.bottom_units.clicked.connect(self.openInputDialog) #Defines combo boxes for bottom plot self.bottom_plot_combo = QtGui.QButtonGroup() self.bottom_xcombo = QtGui.QComboBox() self.bottom_xcombo.addItems('X') self.bottom_xcombo_lbl = QtGui.QLabel('X Values', self) self.bottom_ycombo = QtGui.QComboBox() self.bottom_ycombo.addItems('Y') self.bottom_ycombo_lbl = QtGui.QLabel('Y Values', self) self.bottom_plot_layout.addWidget(self.bottom_plot_layout_text, 0, 0, 1, 4) self.bottom_plot_layout.addWidget(self.bottom_open_button, 1, 0) self.bottom_plot_layout.addWidget(self.bottom_plot_button, 2, 0) self.bottom_plot_layout.addWidget(self.bottom_clear_button, 3, 0) self.bottom_plot_layout.addWidget(self.bottom_units, 4, 0) self.bottom_plot_layout.addWidget(self.bottom_xcombo_lbl, 1, 1) self.bottom_plot_layout.addWidget(self.bottom_xcombo, 2, 1) self.bottom_plot_layout.addWidget(self.bottom_ycombo_lbl, 3, 1) self.bottom_plot_layout.addWidget(self.bottom_ycombo, 4, 1) def Plot_Function(self): ''' Clears Matplotlib Widget Canvas Adds 3 subplots plots Difference Data sharex - shares x axis between subplots ''' #self.legend.remove() #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') self.toolbar_grid.addWidget(self.navi_toolbar) self.top_xval = self.top_data[self.top_data.dtype.names[ self.top_xcombo.currentIndex()]] self.top_yval = self.top_data[self.top_data.dtype.names[ self.top_ycombo.currentIndex()]] self.yval = self.yval - np.median(self.yval) x1 = np.linspace(0.0, 5.0) y1 = np.cos(2 * np.pi * x1) * np.exp(-x1) y2 = np.cos(3 * np.pi * x1) * np.exp(-x1) y3 = np.cos(4 * np.pi * x1) * np.exp(-x1) self.mpl.canvas.fig.clear() self.plot1 = self.mpl.canvas.fig.add_subplot(3, 1, 1) #self.plot1.plot(self.top_xval,self.top_yval) self.plot2 = self.mpl.canvas.fig.add_subplot(3, 1, 2, sharex=self.plot1) self.plot2.plot(x1, y2) self.plot3 = self.mpl.canvas.fig.add_subplot(3, 1, 3, sharex=self.plot1) self.plot3.plot(x1, y3) def keyboard_Definitions(self): QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"), self, self.Plot_Function) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard) def menubar_definitions(self): self.fname = self.Open_button.clicked.connect(self.Open_File) def __init__(self, parent=None): # initialization of the superclass super(TraverseMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Button_layout is a QT desginer Grid Layout. self.keyboard_Definitions() #self.Plot_Function() self.button_grid() self.statusbar.setEnabled(True) self.statusbar.showMessage("Ready")
class TraverseMainWindow(QtGui.QMainWindow, Ui_MainWindow): def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def press_open(self): self.fname = QtGui.QFileDialog.getExistingDirectory(self, "Select Project") open_project(self.fname, self) self.statusbar.showMessage("press_open returned") self.repaint() def Open_File(self): self.fname = QtGui.QFileDialog.getOpenFileName() # self.f = open(self.fname, 'rb') with open(self.fname, "r") as f: num_cols = len(f.readline().split(" ")) - 1 f.seek(0) data = np.genfromtxt( f, names=True, delimiter=" ", dtype=None, filling_values=np.nan, usecols=(range(0, num_cols)) ) return data # print data # print "beak" # return data # print data # print "break" def top_data(self): # print "beak" self.top_data = self.Open_File() print self.top_data.dtype.names # print data self.top_x = self.top_data.dtype.names # print self.data[self.data.dtype.names[1]] # print self.data[self.data.dtype.names[2]] # return self.top_x self.top_y = self.top_data.dtype.names # return self.top_y self.top_xcombo.clear() self.top_xcombo.addItems(self.top_x) self.top_ycombo.clear() self.top_ycombo.addItems(self.top_y) # Clears Legend # self.legend_definitions() def legend_definitions(self): self.handles = [] self.labels = [] self.colors = itertools.cycle(["b", "g", "r", "c", "m", "y", "b"]) self.markers = itertools.cycle([".", "D", "p", "*", "+"]) self.legend = self.mpl.canvas.fig.legend(self.handles, self.labels, "upper right") def openInputDialog(self): x_axis, result = QtGui.QInputDialog.getText(self, "X axis", "Specify units") if result: self.x_axis = x_axis y_axis, result = QtGui.QInputDialog.getText(self, "Y axis", "Specify units") if result: self.y_axis = y_axis def button_grid(self): # An Expanding Spacer Item to be used anywhere.. spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.toolbar_grid.addItem(spacerItem, 0, 0, 1, 1) self.toolbar_grid.addItem(spacerItem, 0, 4, 1, 1) # self.Grid_horizontal_Layout_2.addItem(spacerItem, 0) # self.Grid_horizontal_Layout_2.addItem(spacerItem, 4) # Layout for processing toolbbox self.top_plot_layout = QtGui.QGridLayout() self.top_plot_box = QtGui.QGroupBox() self.top_plot_box.setLayout(self.top_plot_layout) self.middle_plot_layout = QtGui.QGridLayout() self.middle_plot_box = QtGui.QGroupBox() self.middle_plot_box.setLayout(self.middle_plot_layout) self.bottom_plot_layout = QtGui.QGridLayout() self.bottom_plot_box = QtGui.QGroupBox() self.bottom_plot_box.setLayout(self.bottom_plot_layout) # Traverse selector grid box self.Grid_horizontal_Layout_2.addWidget(self.top_plot_box, 0) # self.toolbar_grid.addLayout(self.top_plot_layout, 0, 1, 1, 1) string = '<span style=" font-size:14pt;; font-weight:600;">Top Plot</span>' self.top_plot_layout_text = QtGui.QLabel(string, self) # Defines push buttons for top plot self.top_plot_buttons = QtGui.QButtonGroup() self.top_open_button = QtGui.QPushButton("Open", self) self.top_fname = self.top_open_button.clicked.connect(self.top_data) self.top_plot_buttons.addButton(self.top_open_button) self.top_plot_button = QtGui.QPushButton("Plot", self) # self.top_fname = self.top_open_button.clicked.connect(self.Open_File) self.top_plot_buttons.addButton(self.top_plot_button) self.top_clear_button = QtGui.QPushButton("Clear", self) # self.top_fname = self.top_open_button.clicked.connect(self.Open_File) self.top_plot_buttons.addButton(self.top_clear_button) self.top_plot_input = QtGui.QButtonGroup() self.top_units = QtGui.QPushButton("Input Units", self) self.top_units.clicked.connect(self.openInputDialog) # Defines combo boxes for top plot self.top_plot_combo = QtGui.QButtonGroup() self.top_xcombo = QtGui.QComboBox() self.top_xcombo.addItems("X") self.top_xcombo_lbl = QtGui.QLabel("X Values", self) self.top_ycombo = QtGui.QComboBox() self.top_ycombo.addItems("Y") self.top_ycombo_lbl = QtGui.QLabel("Y Values", self) self.top_plot_layout.addWidget(self.top_plot_layout_text, 0, 0, 1, 4) self.top_plot_layout.addWidget(self.top_open_button, 1, 0) self.top_plot_layout.addWidget(self.top_plot_button, 2, 0) self.top_plot_layout.addWidget(self.top_clear_button, 3, 0) self.top_plot_layout.addWidget(self.top_units, 4, 0) self.top_plot_layout.addWidget(self.top_xcombo_lbl, 1, 1) self.top_plot_layout.addWidget(self.top_xcombo, 2, 1) self.top_plot_layout.addWidget(self.top_ycombo_lbl, 3, 1) self.top_plot_layout.addWidget(self.top_ycombo, 4, 1) self.top_plot_layout.addItem(spacerItem, 0, 0, 1, 1) self.top_plot_layout.addItem(spacerItem, 3, 0, 1, 1) # 1st Pass Selector Box self.Grid_horizontal_Layout_2.addWidget(self.middle_plot_box, 1) # self.toolbar_grid.addLayout(self.middle_plot_layout, 0, 2, 1, 1) # Title of Box. HTML required to change colour & weight string = '<span style=" font-size:14pt;; font-weight:600;">Middle Plot</span>' self.middle_plot_layout_text = QtGui.QLabel(string, self) self.middle_plot_buttons = QtGui.QButtonGroup() self.middle_open_button = QtGui.QPushButton("Open", self) self.middle_fname = self.middle_open_button.clicked.connect(self.top_data) self.middle_plot_buttons.addButton(self.middle_open_button) self.middle_plot_button = QtGui.QPushButton("Plot", self) # self.middle_fname = self.middle_open_button.clicked.connect(self.Open_File) self.middle_plot_buttons.addButton(self.middle_plot_button) self.middle_clear_button = QtGui.QPushButton("Clear", self) # self.middle_fname = self.middle_open_button.clicked.connect(self.Open_File) self.middle_plot_buttons.addButton(self.middle_clear_button) self.middle_plot_input = QtGui.QButtonGroup() self.middle_units = QtGui.QPushButton("Input Units", self) self.middle_units.clicked.connect(self.openInputDialog) # Defines combo boxes for middle plot self.middle_plot_combo = QtGui.QButtonGroup() self.middle_xcombo = QtGui.QComboBox() self.middle_xcombo.addItems("X") self.middle_xcombo_lbl = QtGui.QLabel("X Values", self) self.middle_ycombo = QtGui.QComboBox() self.middle_ycombo.addItems("Y") self.middle_ycombo_lbl = QtGui.QLabel("Y Values", self) self.middle_plot_layout.addWidget(self.middle_plot_layout_text, 0, 0, 1, 4) self.middle_plot_layout.addWidget(self.middle_open_button, 1, 0) self.middle_plot_layout.addWidget(self.middle_plot_button, 2, 0) self.middle_plot_layout.addWidget(self.middle_clear_button, 3, 0) self.middle_plot_layout.addWidget(self.middle_units, 4, 0) self.middle_plot_layout.addWidget(self.middle_xcombo_lbl, 1, 1) self.middle_plot_layout.addWidget(self.middle_xcombo, 2, 1) self.middle_plot_layout.addWidget(self.middle_ycombo_lbl, 3, 1) self.middle_plot_layout.addWidget(self.middle_ycombo, 4, 1) # Bottom Plot Selector Box self.Grid_horizontal_Layout_2.addWidget(self.bottom_plot_box, 2) # self.toolbar_grid.addLayout(self.bottom_plot_layout, 0, 3, 1, 1) # Title of Box. HTML required to change colour & weight string = '<span style=" font-size:14pt;; font-weight:600;">Bottom Plot</span>' self.bottom_plot_layout_text = QtGui.QLabel(string, self) self.bottom_plot_buttons = QtGui.QButtonGroup() self.bottom_open_button = QtGui.QPushButton("Open", self) self.bottom_fname = self.bottom_open_button.clicked.connect(self.Open_File) self.bottom_plot_buttons.addButton(self.bottom_open_button) self.bottom_plot_button = QtGui.QPushButton("Plot", self) # self.bottom_fname = self.bottom_open_button.clicked.connect(self.Open_File) self.bottom_plot_buttons.addButton(self.bottom_plot_button) self.bottom_clear_button = QtGui.QPushButton("Clear", self) # self.bottom_fname = self.bottom_open_button.clicked.connect(self.Open_File) self.bottom_plot_buttons.addButton(self.bottom_clear_button) self.bottom_plot_input = QtGui.QButtonGroup() self.bottom_units = QtGui.QPushButton("Input Units", self) self.bottom_units.clicked.connect(self.openInputDialog) # Defines combo boxes for bottom plot self.bottom_plot_combo = QtGui.QButtonGroup() self.bottom_xcombo = QtGui.QComboBox() self.bottom_xcombo.addItems("X") self.bottom_xcombo_lbl = QtGui.QLabel("X Values", self) self.bottom_ycombo = QtGui.QComboBox() self.bottom_ycombo.addItems("Y") self.bottom_ycombo_lbl = QtGui.QLabel("Y Values", self) self.bottom_plot_layout.addWidget(self.bottom_plot_layout_text, 0, 0, 1, 4) self.bottom_plot_layout.addWidget(self.bottom_open_button, 1, 0) self.bottom_plot_layout.addWidget(self.bottom_plot_button, 2, 0) self.bottom_plot_layout.addWidget(self.bottom_clear_button, 3, 0) self.bottom_plot_layout.addWidget(self.bottom_units, 4, 0) self.bottom_plot_layout.addWidget(self.bottom_xcombo_lbl, 1, 1) self.bottom_plot_layout.addWidget(self.bottom_xcombo, 2, 1) self.bottom_plot_layout.addWidget(self.bottom_ycombo_lbl, 3, 1) self.bottom_plot_layout.addWidget(self.bottom_ycombo, 4, 1) def Plot_Function(self): """ Clears Matplotlib Widget Canvas Adds 3 subplots plots Difference Data sharex - shares x axis between subplots """ # self.legend.remove() # Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() # Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon("home.png"), "Home", self.navi_toolbar.home) # a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon("move.png"), "Pan", self.navi_toolbar.pan) a.setToolTip("Pan axes with left mouse, zoom with right") a = self.navi_toolbar.addAction(self.navi_toolbar._icon("zoom_to_rect.png"), "Zoom", self.navi_toolbar.zoom) a.setToolTip("Zoom to Rectangle") a = self.navi_toolbar.addAction(self.navi_toolbar._icon("filesave.png"), "Save", self.navi_toolbar.save_figure) a.setToolTip("Save the figure") self.toolbar_grid.addWidget(self.navi_toolbar) self.top_xval = self.top_data[self.top_data.dtype.names[self.top_xcombo.currentIndex()]] self.top_yval = self.top_data[self.top_data.dtype.names[self.top_ycombo.currentIndex()]] self.yval = self.yval - np.median(self.yval) x1 = np.linspace(0.0, 5.0) y1 = np.cos(2 * np.pi * x1) * np.exp(-x1) y2 = np.cos(3 * np.pi * x1) * np.exp(-x1) y3 = np.cos(4 * np.pi * x1) * np.exp(-x1) self.mpl.canvas.fig.clear() self.plot1 = self.mpl.canvas.fig.add_subplot(3, 1, 1) # self.plot1.plot(self.top_xval,self.top_yval) self.plot2 = self.mpl.canvas.fig.add_subplot(3, 1, 2, sharex=self.plot1) self.plot2.plot(x1, y2) self.plot3 = self.mpl.canvas.fig.add_subplot(3, 1, 3, sharex=self.plot1) self.plot3.plot(x1, y3) def keyboard_Definitions(self): QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"), self, self.Plot_Function) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard) def menubar_definitions(self): self.fname = self.Open_button.clicked.connect(self.Open_File) def __init__(self, parent=None): # initialization of the superclass super(TraverseMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) # Button_layout is a QT desginer Grid Layout. self.keyboard_Definitions() # self.Plot_Function() self.button_grid() self.statusbar.setEnabled(True) self.statusbar.showMessage("Ready")
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() #Clears Legend self.legend.remove() self.legend_definitions() self.mpl.canvas.draw() def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def Open_File(self): self.fname = QtGui.QFileDialog.getOpenFileName() #Opes File with open(self.fname, 'r') as f: num_cols = len(f.readline().split(' '))-1 f.seek(0) self.data = np.genfromtxt(f, names=True, delimiter=' ',dtype=None,filling_values = np.nan, usecols=(range(0,num_cols))) self.open_handler() def open_handler(self): if self.plot1_selector.isChecked(): #Defines x and y values self.x1 = self.data.dtype.names self.y1 = self.data.dtype.names #Populates combo boxes with header names self.x1combo.clear() self.x1combo.addItems(self.x1) self.y1combo.clear() self.y1combo.addItems(self.y1) if self.plot2_selector.isChecked(): #Defines x and y values self.x2 = self.data.dtype.names self.y2 = self.data.dtype.names #Populates combo boxes with header names self.x2combo.clear() self.x2combo.addItems(self.x2) self.y2combo.clear() self.y2combo.addItems(self.y2) if self.plot3_selector.isChecked(): #Defines x and y values self.x3 = self.data.dtype.names self.y3 = self.data.dtype.names #Populates combo boxes with header names self.x3combo.clear() self.x3combo.addItems(self.x3) self.y3combo.clear() self.y3combo.addItems(self.y3) def Plot_Function(self): #self.mpl.canvas.fig.clear() #self.legend.remove() #Takes x and y values to plot from combo box selection self.x1val = self.data[self.data.dtype.names[self.x1combo.currentIndex()]] self.y1val = self.data[self.data.dtype.names[self.y1combo.currentIndex()]] self.x2val = self.data[self.data.dtype.names[self.x2combo.currentIndex()]] self.y2val = self.data[self.data.dtype.names[self.y2combo.currentIndex()]] self.x3val = self.data[self.data.dtype.names[self.x3combo.currentIndex()]] self.y3val = self.data[self.data.dtype.names[self.y3combo.currentIndex()]] #self.yval = self.yval - np.median(self.yval) self.axes = self.canvas.fig.add_subplot self.plot1 = self.mpl.canvas.fig.add_subplot(3,1,1) self.plot2 = self.mpl.canvas.fig.add_subplot(3,1,2) self.plot3 = self.mpl.canvas.fig.add_subplot(3,1,3) #Calculates stats info of y values #self.stats() #self.plot1 = self.mpl.canvas.fig.add_subplot(3,1,1) #self.plot1.set_xlabel(self.x_units.text()) #self.plot1.set_ylabel(self.y1_units.text(), size=15) self.plot1.axes.set_autoscale_on(True) self.plot1.axes.autoscale_view(True,True,True) self.plot1.plot(self.x1val,self.y1val) #self.plot2 = self.mpl.canvas.fig.add_subplot(3,1,2, sharex=self.plot1) #self.plot2.set_xlabel(self.x_units.text()) #self.plot2.set_ylabel(self.y2_units.text(), size=15) self.plot2.plot(self.x2val,self.y2val) #self.plot3 = self.mpl.canvas.fig.add_subplot(3,1,3, sharex=self.plot1) #self.plot3.set_xlabel(self.x_units.text()) #self.plot3.set_ylabel(self.y3_units.text(),size=15) self.plot3.plot(self.x3val, self.y3val) #temp_scatter = self.mpl.canvas.ax.scatter(self.xval,self.yval, color=self.marker_colour.currentText(),marker=self.marker_style.currentText()) #self.handles.append(temp_scatter) #self.labels.append(self.data.dtype.names[self.ycombo.currentIndex()]) #self.legend = self.mpl.canvas.fig.legend(self.handles,self.labels,'upper right') #self.mpl.canvas.ax.set_ylim(ymin=np.min(self.yval), ymax=(np.max(self.yval))) #self.mpl.canvas.ax.set_xlim(xmin=np.min(self.xval), xmax=np.max(self.xval)) #self.mpl.canvas.ax.set_autoscale_on(True) #self.mpl.canvas.ax.autoscale_view(True,True,True) #self.mpl.canvas.ax.set_xlabel(self.x_units.text(), size = 15) #self.mpl.canvas.ax.set_ylabel(self.y_units.text(), size=15) #self.mpl.canvas.ax.set_title(self.chart_title.text(), size=20) #self.mpl.canvas.ax.axis('auto') #Creates scatter plot #self.mpl.canvas.draw() def legend_definitions(self): #Handles legend self.handles = [] self.labels = [] #self.colors = itertools.cycle(["b","g","r","c","m","y","b"]) #self.markers = itertools.cycle([".","D","p","*","+"]) self.legend = self.mpl.canvas.fig.legend(self.handles,self.labels,'upper right') def stats(self): #Calculates stats info of y values and sends back to UI self.mean = str(np.round(np.mean(self.yval), decimals=3)) self.mean_output.setText(self.mean) self.median = str(np.round(np.median(self.yval), decimals=3)) self.median_output.setText(self.median) self.sd = str(np.round(np.std(self.yval), decimals=3)) self.sd_output.setText(self.sd) def moving_average_buttons(self): #Radio Button Helper if self.rolling_mean_radio.isChecked(): self.moving_mean() else: self.moving_median() def moving_mean(self): self.trend_y= rolling_mean(self.yval, self.moving_avg_window.value()) self.plot_trendline() def moving_median(self): self.trend_y = rolling_median(self.yval, self.moving_avg_window.value()) self.plot_trendline() def polyfit(self): #Calculates Polynomial Fit with Error Estimation #Calculate Poly Fit self.order = self.poly_order.value() self.p = np.polyfit(self.xval, self.yval, self.order) #coefficients print self.order self.trend_y = np.polyval(self.p, self.xval) #fit values self.plot_trendline() #Calculate coeffecient of determination self.residuals = np.subtract(self.yval, self.trend_y) #residuals self.RSS = np.sum(np.square(self.residuals)) #residual sum of squares self.TSS = np.sum(np.square(np.subtract(self.yval, np.mean(self.yval)))) #Sends R-Squared value back to UI self.r_squared = str(np.round(np.subtract(1, np.divide(self.RSS, self.TSS)), decimals=3)) #send back to GUI self.r_squared_output.setText(self.r_squared) #Sends trendline equation back to UI coeff1 = np.round(self.p[0], decimals=10) coeff1 = str(coeff1) coeff2 = np.round(self.p[1], decimals=8) coeff2 = str(coeff2) if self.order == 1: self.fit_equation = coeff1+'x + '+coeff2 self.trendline_equation.setText(self.fit_equation) if self.order == 2: coeff3 = np.round(self.p[2],decimals=3) coeff3 = str(coeff3) self.fit_equation = coeff1+'x^2 + '+coeff2+'x + '+coeff3 self.trendline_equation.setText(self.fit_equation) if self.order == 3: coeff3 = np.round(self.p[2],decimals=5) coeff3 = str(coeff3) coeff4 = np.round(self.p[3],decimals=3) coeff4 = str(coeff4) self.fit_equation = coeff1+'x^3 + '+coeff2+'x^2 + '+coeff3+'x + '+coeff4 self.trendline_equation.setText(self.fit_equation) def plot_trendline(self): #Plots poly-line as solid line self.mpl.canvas.ax.plot(self.xval, self.trend_y, color=self.line_colour.currentText(), linestyle=self.line_style.currentText(), linewidth=self.line_width.value()) self.mpl.canvas.ax.set_ylim(ymin=np.min(self.yval), ymax=(np.max(self.yval))) self.mpl.canvas.ax.set_autoscale_on(True) self.mpl.canvas.ax.autoscale_view(True,True,True) self.mpl.canvas.ax.set_xlabel(self.x_units.text(), size = 15) self.mpl.canvas.ax.set_ylabel(self.y_units.text(), size=15) self.mpl.canvas.ax.set_title(self.chart_title.text(), size=20) #self.mpl.canvas.ax.set_ylabel(self.ytitle, size = 15) #self.mpl.canvas.ax.set_title(self.title, size = 15) #self.handles.append(trendline) #self.handles.append(poly_line) #self.poly_order_title = self.poly_order.text() #self.labels.append(self.poly_order_title + ' Order Polynomial') #self.legend = self.mpl.canvas.fig.legend(self.handles,self.labels,'upper right') self.mpl.canvas.draw() def button_grid(self): #Defines button and layout #self.firstrun=True self.plot_layout = QtGui.QGridLayout() self.plot_box = QtGui.QGroupBox() self.plot_box.setLayout(self.plot_layout) #self.plot2_layout = QtGui.QGridLayout() #self.plot2_box = QtGui.QGroupBox() #self.plot2_box.setLayout(self.plot2_layout) #self.plot3_layout = QtGui.QGridLayout() #self.plot3_box = QtGui.QGroupBox() #self.plot3_box.setLayout(self.plot3_layout) #self.stats_layout = QtGui.QGridLayout() #self.stats_box = QtGui.QGroupBox() #self.stats_box.setLayout(self.stats_layout) #self.plot_layout = QtGui.QGridLayout() #self.plot_box = QtGui.QGroupBox() #self.plot_box.setLayout(self.plot_layout) #File-Plot Options self.Grid_horizontal_Layout_2.addWidget(self.plot_box, 1) string = '<span style=" font-size:12pt;; font-weight:600;">File Options</span>' self.plot_layout_text = QtGui.QLabel(string, self) self.plot_buttons = QtGui.QButtonGroup() self.open_button = QtGui.QPushButton('Open', self) self.plot_buttons.addButton(self.open_button) self.open_button.clicked.connect(self.Open_File) self.plot_button = QtGui.QPushButton('Plot', self) self.plot_buttons.addButton(self.plot_button) self.plot_button.clicked.connect(self.Plot_Function) self.clear_button = QtGui.QPushButton('Clear', self) self.plot_buttons.addButton(self.clear_button) self.clear_button.clicked.connect(self.ClearPlot) self.chart_title = QtGui.QLineEdit(self) self.chart_title.setText("Enter Chart Title") self.plot1_selector = QtGui.QRadioButton('Plot 1', self) self.plot2_selector = QtGui.QRadioButton('Plot 2', self) self.plot3_selector = QtGui.QRadioButton('Plot 3', self) self.x1combo = QtGui.QComboBox() self.x1combo.addItems('X') self.x1_lbl = QtGui.QLabel('Plot 1: X Values --') self.y1combo = QtGui.QComboBox() self.y1combo.addItems('Y') self.y1_lbl = QtGui.QLabel('Plot 1: Y values --') self.x1_units = QtGui.QLineEdit(self) self.x1_units_lbl = QtGui.QLabel("X Units:", self) #self.connect(self.inputDlgBtn, QtCore.SIGNAL("clicked()"), self.openInputDialog) self.y1_units = QtGui.QLineEdit(self) self.y1_units_lbl = QtGui.QLabel("Y Units:", self) self.x2combo = QtGui.QComboBox() self.x2combo.addItems('X') self.x2_lbl = QtGui.QLabel('Plot 2 X Values --') self.y2combo = QtGui.QComboBox() self.y2combo.addItems('Y') self.y2_lbl = QtGui.QLabel('Plot 2 Y values --') self.x2_units = QtGui.QLineEdit(self) self.x2_units_lbl = QtGui.QLabel("X Units:", self) #self.connect(self.inputDlgBtn, QtCore.SIGNAL("clicked()"), self.openInputDialog) self.y2_units = QtGui.QLineEdit(self) self.y2_units_lbl = QtGui.QLabel("Y Units:", self) self.x3combo = QtGui.QComboBox() self.x3combo.addItems('X') self.x3_lbl = QtGui.QLabel('Plot 3 X Values --') self.y3combo = QtGui.QComboBox() self.y3combo.addItems('Y') self.y3_lbl = QtGui.QLabel('Plot 3 Y values --') self.x3_units = QtGui.QLineEdit(self) self.x3_units_lbl = QtGui.QLabel("X Units:", self) #self.connect(self.inputDlgBtn, QtCore.SIGNAL("clicked()"), self.openInputDialog) self.y3_units = QtGui.QLineEdit(self) self.y3_units_lbl = QtGui.QLabel("Y Units:", self) self.plot_layout.addWidget(self.plot_layout_text, 0,0,1,4) self.plot_layout.addWidget(self.plot1_selector, 1,0) self.plot_layout.addWidget(self.plot2_selector, 2,0) self.plot_layout.addWidget(self.plot3_selector, 3,0) self.plot_layout.addWidget(self.open_button, 1,1) self.plot_layout.addWidget(self.plot_button, 2,1) self.plot_layout.addWidget(self.clear_button, 3,1) self.plot_layout.addWidget(self.chart_title, 4,1) self.plot_layout.addWidget(self.x1_lbl, 1,2) self.plot_layout.addWidget(self.x1combo, 2,2) self.plot_layout.addWidget(self.y1_lbl, 3,2) self.plot_layout.addWidget(self.y1combo, 4,2) self.plot_layout.addWidget(self.x1_units_lbl, 1,3) self.plot_layout.addWidget(self.x1_units, 2,3) self.plot_layout.addWidget(self.y1_units_lbl, 3,3) self.plot_layout.addWidget(self.y1_units, 4,3) self.plot_layout.addWidget(self.x2_lbl, 1,4) self.plot_layout.addWidget(self.x2combo, 2,4) self.plot_layout.addWidget(self.y2_lbl, 3,4) self.plot_layout.addWidget(self.y2combo, 4,4) self.plot_layout.addWidget(self.x2_units_lbl, 1,5) self.plot_layout.addWidget(self.x2_units, 2,5) self.plot_layout.addWidget(self.y2_units_lbl, 3,5) self.plot_layout.addWidget(self.y2_units, 4,5) self.plot_layout.addWidget(self.x3_lbl, 1,6) self.plot_layout.addWidget(self.x3combo, 2,6) self.plot_layout.addWidget(self.y3_lbl, 3,6) self.plot_layout.addWidget(self.y3combo, 4,6) self.plot_layout.addWidget(self.x3_units_lbl, 1,7) self.plot_layout.addWidget(self.x3_units, 2,7) self.plot_layout.addWidget(self.y3_units_lbl, 3,7) self.plot_layout.addWidget(self.y3_units, 4,7) #Plotting Properties '''self.Grid_horizontal_Layout_2.addWidget(self.plot_box, 1) string = '<span style=" font-size:12pt;; font-weight:600;">Plot Settings</span>' self.plot_layout_text = QtGui.QLabel(string, self) self.plot_buttons = QtGui.QButtonGroup() self.marker_style = QtGui.QComboBox() self.marker_style.addItems(('.', 'o', 'v', '^', '*', 'D', 'd')) self.marker_style_lbl = QtGui.QLabel('Marker Style', self) self.marker_colour = QtGui.QComboBox() self.marker_colour.addItems(('0.25', '0.5', '0.75', 'k', 'b', 'g', 'r', 'c', 'y', 'm')) self.marker_colour_lbl = QtGui.QLabel('Marker Colour', self) self.line_style = QtGui.QComboBox() self.line_style.addItems(('-', '--', ':','_')) self.line_style_lbl = QtGui.QLabel('Line Style', self) self.line_width = QtGui.QSpinBox() self.line_width.setRange(1,10) self.line_width_lbl = QtGui.QLabel('Line Width', self) self.line_colour = QtGui.QComboBox() self.line_colour.addItems(('r','b','g','c','y','m','0.25','0.5','0.75','k')) self.line_colour_lbl = QtGui.QLabel('Line Colour', self) self.plot_layout.addWidget(self.plot_layout_text, 0,0,1,4) self.plot_layout.addWidget(self.line_style_lbl, 1,0) self.plot_layout.addWidget(self.line_style, 1,1) self.plot_layout.addWidget(self.line_width_lbl, 2,0) self.plot_layout.addWidget(self.line_width, 2,1) self.plot_layout.addWidget(self.line_colour_lbl, 3,0) self.plot_layout.addWidget(self.line_colour,3,1) self.plot_layout.addWidget(self.marker_style_lbl, 1,2) self.plot_layout.addWidget(self.marker_style, 1,3) self.plot_layout.addWidget(self.marker_colour_lbl, 2,2) self.plot_layout.addWidget(self.marker_colour, 2,3) #Stats Properties self.Grid_horizontal_Layout_2.addWidget(self.stats_box, 1) string = '<span style=" font-size:12pt;; font-weight:600;">Stats Settings</span>' self.stats_layout_text = QtGui.QLabel(string, self) self.mean_output_lbl = QtGui.QLabel("Data Mean") self.mean_output = QtGui.QLineEdit(self) self.median_output_lbl = QtGui.QLabel("Data Median") self.median_output = QtGui.QLineEdit(self) self.sd_lbl = QtGui.QLabel("Std Deviation") self.sd_output = QtGui.QLineEdit(self) self.stats_buttons = QtGui.QButtonGroup() self.poly_label = QtGui.QLabel('Poly Fit') #self.poly_fit = QtGui.QRadioButton('Poly Fit', self) self.poly_order_text = QtGui.QLabel('Order', self) self.poly_order = QtGui.QSpinBox(self) self.poly_order.setRange(1, 10) self.poly_plot_button = QtGui.QPushButton('Plot', self) self.stats_buttons.addButton(self.poly_plot_button) self.poly_plot_button.clicked.connect(self.polyfit) self.rolling_mean_radio = QtGui.QRadioButton('Rolling Mean', self) self.rolling_median_radio = QtGui.QRadioButton('Rolling Median', self) self.moving_avg_window_text = QtGui.QLabel('Window') self.moving_avg_window = QtGui.QSpinBox(self) self.moving_avg_window.setRange(1,1000) self.moving_avg_plot = QtGui.QPushButton('Plot', self) self.moving_avg_plot.clicked.connect(self.moving_average_buttons) self.trendline_lbl = QtGui.QLabel("Trendline Equation") self.trendline_equation = QtGui.QLineEdit(self) self.r_squared_lbl = QtGui.QLabel("R Squared") self.r_squared_output = QtGui.QLineEdit(self) self.stats_layout.addWidget(self.stats_layout_text, 0,0,1,4) self.stats_layout.addWidget(self.mean_output_lbl, 1,0) self.stats_layout.addWidget(self.mean_output, 1,1) self.stats_layout.addWidget(self.median_output_lbl, 1,2) self.stats_layout.addWidget(self.median_output, 1,3) self.stats_layout.addWidget(self.sd_lbl, 1,4) self.stats_layout.addWidget(self.sd_output, 1,5) self.stats_layout.addWidget(self.poly_label, 2,0) self.stats_layout.addWidget(self.poly_order_text, 2,1) self.stats_layout.addWidget(self.poly_order, 2,2) self.stats_layout.addWidget(self.poly_plot_button,2,3) self.stats_layout.addWidget(self.rolling_mean_radio, 3,0) self.stats_layout.addWidget(self.rolling_median_radio, 3,1) self.stats_layout.addWidget(self.moving_avg_window_text,3,2) self.stats_layout.addWidget(self.moving_avg_window, 3,3) self.stats_layout.addWidget(self.moving_avg_plot, 3,4) self.stats_layout.addWidget(self.trendline_lbl, 5,0) self.stats_layout.addWidget(self.trendline_equation, 5,1) self.stats_layout.addWidget(self.r_squared_lbl, 5,2) self.stats_layout.addWidget(self.r_squared_output, 5,3)''' def __init__(self, parent = None): # initialization of the superclass super(ArchaeoPYMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"),self, self.copy_to_clipboard) #self.xlabel = QtGui.QInputDialog.getText(self, 'X-axis Label') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.button_grid()
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def Open_Geoplot(self): self.fname = QtGui.QFileDialog.getOpenFileName() self.Plot_Function() def Plot_Function(self): #Get values from Options Grid self.grid_length = self.TravL_val.value() self.grid_width = self.GridL_val.value() self.sample_interval = self.TravI_val.value() self.traverse_interval = self.GridI_val.value() self.output = Load_Comp(self.fname,self.grid_length,self.grid_width,self.sample_interval,self.traverse_interval) self.mpl.canvas.ax.clear() print np.shape(self.output) self.mpl.canvas.ax.imshow(self.output,cmap=plt.cm.Greys,extent=[0,self.grid_length,self.grid_width,0], aspect='equal',interpolation='none',vmin = self.neg_val.value(), vmax = self.pos_val.value()) self.mpl.canvas.draw() def plot_options(self): self.neg_label = QtGui.QLabel('Neg Value', self) self.neg_val = QtGui.QDoubleSpinBox(self) self.neg_val.setRange(-100, 100) self.neg_val.setValue(-1) self.pos_label = QtGui.QLabel('Pos Value', self) self.pos_val = QtGui.QDoubleSpinBox(self) self.pos_val.setRange(-100, 100) self.pos_val.setValue(2) self.TravL_label = QtGui.QLabel('Trav Length', self) self.TravL_val = QtGui.QDoubleSpinBox(self) self.TravL_val.setRange(0, 1000) self.TravL_val.setValue(30) self.TravI_label = QtGui.QLabel('Sample Interval', self) self.TravI_val = QtGui.QDoubleSpinBox(self) self.TravI_val.setValue(0.25) self.GridL_label = QtGui.QLabel('Grid Width', self) self.GridL_val = QtGui.QDoubleSpinBox(self) self.GridL_val.setRange(0, 1000) self.GridL_val.setValue(30) self.GridI_label = QtGui.QLabel('Traverse Interval', self) self.GridI_val = QtGui.QDoubleSpinBox(self) self.GridI_val.setValue(1) self.Scale_label = QtGui.QLabel('Scale Value', self) self.Scale_val =QtGui.QDoubleSpinBox(self) self.Scale_val.setRange(1, 5000) self.Scale_val.setValue(500) self.Clip_label = QtGui.QLabel('Clipping Value', self) self.Clip_val = QtGui.QDoubleSpinBox(self) self.Clip_val.setRange(0.1, 100) self.Clip_val.setValue(15) self.Grid_horizontal_Layout_1.addWidget(self.TravL_label) self.Grid_horizontal_Layout_1.addWidget(self.TravL_val) self.Grid_horizontal_Layout_1.addWidget(self.TravI_label) self.Grid_horizontal_Layout_1.addWidget(self.TravI_val) self.Grid_horizontal_Layout_2.addWidget(self.GridL_label) self.Grid_horizontal_Layout_2.addWidget(self.GridL_val) self.Grid_horizontal_Layout_2.addWidget(self.GridI_label) self.Grid_horizontal_Layout_2.addWidget(self.GridI_val) self.Grid_horizontal_Layout_3 = QtGui.QHBoxLayout() self.Grid_horizontal_Layout_3.setObjectName("Grid_horizontal_Layout_3") self.Options_Grid.addLayout(self.Grid_horizontal_Layout_3, 2, 0, 1, 1) self.Grid_horizontal_Layout_3.addWidget(self.neg_label) self.Grid_horizontal_Layout_3.addWidget(self.neg_val) self.Grid_horizontal_Layout_3.addWidget(self.pos_label) self.Grid_horizontal_Layout_3.addWidget(self.pos_val) self.Grid_horizontal_Layout_4 = QtGui.QHBoxLayout() self.Grid_horizontal_Layout_4.setObjectName("Grid_horizontal_Layout_4") self.Options_Grid.addLayout(self.Grid_horizontal_Layout_4, 3, 0, 1, 1) self.Grid_horizontal_Layout_4.addWidget(self.Scale_label) self.Grid_horizontal_Layout_4.addWidget(self.Scale_val) self.Grid_horizontal_Layout_4.addWidget(self.Clip_label) self.Grid_horizontal_Layout_4.addWidget(self.Clip_val) def Button_Definitions(self): self.firstrun=True self.Open_button = QtGui.QPushButton('Open', self) self.fname = self.Open_button.clicked.connect(self.Open_Geoplot) self.Button_Layout.addWidget(self.Open_button) self.Save_button = QtGui.QPushButton('Save as DXF',self) self.Save_button.clicked.connect(self.dxf_save_button) self.Button_Layout.addWidget(self.Save_button) self.pushButton_plot.clicked.connect(self.Plot_Function) self.pushButton_clear.clicked.connect(self.ClearPlot) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"),self, self.Plot_Function) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"),self, self.copy_to_clipboard) def dxf_save_button(self): self.dxf_name = QtGui.QFileDialog.getSaveFileName(self) self.Scale = self.Scale_val.value() self.Clip = self.Clip_val.value() QtGui.QMessageBox.about(self, "This May take a second", "Saving DXF's can be slow, please be paient. \n A dialogue will open when finished") comp2dxf(self.output,self.dxf_name,self.sample_interval,self.traverse_interval,self.Scale,self.Clip, 'CMP2DXF') QtGui.QMessageBox.about(self, "Thanks for waiting", "Sorry about the wait, DXFengine is slow. \n The DXF has been saved. ") def __init__(self, parent = None): # initialization of the superclass super(ArchaeoPYMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.Button_Definitions() self.plot_options()
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() #Clears Legend def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def Open_File(self): self.fname = QtGui.QFileDialog.getOpenFileName() #Opes File with open(self.fname, 'r') as f: self.num_cols = len(f.readline().split(',')) f.seek(0) self.array = np.genfromtxt(f, dtype=float, delimiter=',', skiprows=1, filling_values=np.nan) self.chart_title.clear() #Display file path in GUI self.chart_title.setText(self.fname) #print self.array def regrid(self): #Regrid CMD data array = self.array #set data num_cols = self.num_cols #set number of columns fname = self.fname #set filename if self.hcp_config.isChecked: #set Coil orientation config = 'HCP' else: config = 'VCP' grid = self.grid.text() #set grid(s) to be regridded samples_int = float(self.samples_int.text()) #Sampling Interval samples_start = float(self.samples_start.text()) #Sample starting position samples_stop = float(self.samples_stop.text()) #Sample ending position no_samples = (samples_stop - samples_start + samples_int) / samples_int #number of amples down the line traverses_start = float(self.trav_start.text()) #Starting traverse number traverses_stop = float(self.trav_stop.text()) #Ending traverse number no_traverses = (traverses_stop - traverses_start + float(self.trav_int.text())) / float(self.trav_int.text()) #Number of traverses #Regrid data regrid_cmd(fname, config, grid, array, num_cols, samples_start, samples_stop, no_samples, traverses_start, traverses_stop, no_traverses) def button_grid(self): #Defines button and layout #self.firstrun=True self.buttons_layout = QtGui.QGridLayout() self.buttons_box = QtGui.QGroupBox() self.buttons_box.setLayout(self.buttons_layout) self.survey_layout = QtGui.QGridLayout() self.survey_box = QtGui.QGroupBox() self.survey_box.setLayout(self.survey_layout) #File Properties self.Grid_horizontal_Layout_2.addWidget(self.buttons_box, 1) string = '<span style=" font-size:10pt;; font-weight:600;">File Settings</span>' self.buttons_layout_text = QtGui.QLabel(string, self) self.buttons = QtGui.QButtonGroup() self.open_button = QtGui.QPushButton('Open', self) self.buttons.addButton(self.open_button) self.open_button.clicked.connect(self.Open_File) self.regrid_button = QtGui.QPushButton('Regrid', self) self.buttons.addButton(self.regrid_button) self.regrid_button.clicked.connect(self.regrid) self.clear_button = QtGui.QPushButton('Clear', self) self.buttons.addButton(self.clear_button) self.clear_button.clicked.connect(self.ClearPlot) self.chart_title = QtGui.QLineEdit(self) self.config_lbl = QtGui.QLabel('Orientation', self) self.hcp_config = QtGui.QRadioButton('HCP', self) self.vcp_config = QtGui.QRadioButton('VCP', self) self.grid = QtGui.QLineEdit(self) self.grid.setText('Enter Grid Number') self.buttons_layout.addWidget(self.buttons_layout_text, 0,0,1,4) self.buttons_layout.addWidget(self.open_button, 1,0) self.buttons_layout.addWidget(self.regrid_button, 2,0) self.buttons_layout.addWidget(self.clear_button, 3,0) self.buttons_layout.addWidget(self.chart_title, 4,0) self.buttons_layout.addWidget(self.config_lbl, 1,1) self.buttons_layout.addWidget(self.hcp_config, 2,1) self.buttons_layout.addWidget(self.vcp_config, 3,1) self.buttons_layout.addWidget(self.grid, 4,1) #survey parameters self.Grid_horizontal_Layout_2.addWidget(self.survey_box, 1) string = '<span style=" font-size:10pt;; font-weight:600;">Survey Parameters</span>' self.survey_layout_text = QtGui.QLabel(string, self) self.survey_buttons = QtGui.QButtonGroup() self.samples_start_lbl = QtGui.QLabel('Samples Start Position') self.samples_start = QtGui.QLineEdit(self) self.samples_stop_lbl = QtGui.QLabel('Samples End Position') self.samples_stop = QtGui.QLineEdit(self) self.samples_int_lbl = QtGui.QLabel('Sampling Interval') self.samples_int = QtGui.QLineEdit(self) self.trav_start_lbl = QtGui.QLabel('Traverses Start Position') self.trav_start = QtGui.QLineEdit(self) self.trav_stop_lbl = QtGui.QLabel('Traverses End Position') self.trav_stop = QtGui.QLineEdit(self) self.trav_int_lbl = QtGui.QLabel('Traverse Interval') self.trav_int = QtGui.QLineEdit(self) self.survey_layout.addWidget(self.survey_layout_text, 0,0,1,2) self.survey_layout.addWidget(self.samples_start_lbl, 1,0) self.survey_layout.addWidget(self.samples_start, 1,1) self.survey_layout.addWidget(self.samples_stop_lbl, 2,0) self.survey_layout.addWidget(self.samples_stop, 2,1) self.survey_layout.addWidget(self.samples_int_lbl, 3,0) self.survey_layout.addWidget(self.samples_int,3,1) self.survey_layout.addWidget(self.trav_start_lbl, 4,0) self.survey_layout.addWidget(self.trav_start, 4,1) self.survey_layout.addWidget(self.trav_stop_lbl, 5,0) self.survey_layout.addWidget(self.trav_stop, 5,1) self.survey_layout.addWidget(self.trav_int_lbl, 6,0) self.survey_layout.addWidget(self.trav_int, 6,1) def __init__(self, parent = None): # initialization of the superclass super(ArchaeoPYMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"),self, self.copy_to_clipboard) #self.xlabel = QtGui.QInputDialog.getText(self, 'X-axis Label') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.button_grid()
class ModellerMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def definitions(self): self.s3 = "" self.bucket = "" self.project_code = "" self.overwrite = False self.file_list = "" self.tempfile = "" def cleanup(self): print 'closing' #Defines 2D Res modelling component of UI window: what parameters the user can select. def enable_2DRes(self): #Enable / Disable relevant survey Parameters self.doubleSpinBox_traverselength.setEnabled(True) #Length of traverse (relative units) self.doubleSpinBox_traverselength.setValue(10.0) #Sets the default value for traverse length to be 10 (relative units) self.doubleSpinBox_traverselength.setSingleStep(1.0) self.doubleSpinBox_samplingint.setEnabled(True) self.doubleSpinBox_samplingint.setValue(0.1) self.doubleSpinBox_samplingint.setSingleStep(0.05) #Disables magnetometry parameters--irrelevant for res modelling self.doubleSpinBox_traverseint.setDisabled(True) #self.doubleSpinBox_ylength self.doubleSpinBox_fieldinclination.setDisabled(True) #Enable / Disable instrument parameters self.comboBox_array.setEnabled(True) self.doubleSpinBox_a.setEnabled(True) self.doubleSpinBox_a.setValue(1.0) self.doubleSpinBox_a.setSingleStep(0.1) self.doubleSpinBox_a1.setEnabled(True) self.doubleSpinBox_a1.setValue(1.0) self.doubleSpinBox_a1.setSingleStep(0.1) self.doubleSpinBox_a2.setEnabled(True) self.doubleSpinBox_a2.setValue(1.0) self.doubleSpinBox_a2.setSingleStep(0.1) self.doubleSpinBox_lowersensor.setDisabled(True) self.doubleSpinBox_uppersensor.setDisabled(True) #Enable / Disable Feature Parameters self.comboBox_conductivity.setEnabled(True) self.doubleSpinBox_depth.setEnabled(True) self.doubleSpinBox_depth.setValue(1.0) self.doubleSpinBox_depth.setSingleStep(0.1) self.doubleSpinBox_magsus.setDisabled(True) self.doubleSpinBox_length.setDisabled(True) self.doubleSpinBox_width.setDisabled(True) self.doubleSpinBox_strike.setDisabled(True) self.doubleSpinBox_depthextent.setDisabled(True) #Modifys ComboBox self.comboBox_array.clear() self.comboBox_array.addItems(('TP Long','TP Broad','W Long','W Broad','SQ Alpha','SQ Beta', 'SQ Gamma', 'TZ Long', 'TZ Broad', 'TZ Theta')) def enable_2DRespseudo(self): #Enable / Disable relevant survey Parameters self.doubleSpinBox_traverselength.setEnabled(True) #Length of traverse (relative units) self.doubleSpinBox_traverselength.setValue(10.0) #Sets the default value for traverse length to be 10 (relative units) self.doubleSpinBox_traverselength.setSingleStep(1.0) self.doubleSpinBox_samplingint.setEnabled(True) self.doubleSpinBox_samplingint.setValue(1.0) self.doubleSpinBox_samplingint.setSingleStep(2.0) #Disables magnetometry parameters--irrelevant for res modelling self.doubleSpinBox_traverseint.setDisabled(True) self.doubleSpinBox_fieldinclination.setDisabled(True) #Enable / Disable instrument parameters self.comboBox_array.setEnabled(True) self.doubleSpinBox_a.setEnabled(True) self.doubleSpinBox_a.setValue(0.5) self.doubleSpinBox_a.setSingleStep(0.5) self.doubleSpinBox_a1.setEnabled(True) self.doubleSpinBox_a1.setValue(10.0) self.doubleSpinBox_a1.setSingleStep(0.5) self.doubleSpinBox_a2.setEnabled(True) self.doubleSpinBox_a2.setValue(0.5) self.doubleSpinBox_a2.setSingleStep(0.1) self.doubleSpinBox_lowersensor.setDisabled(True) self.doubleSpinBox_uppersensor.setDisabled(True) #Enable / Disable Feature Parameters self.comboBox_conductivity.setEnabled(True) self.doubleSpinBox_depth.setEnabled(True) self.doubleSpinBox_depth.setValue(1.0) self.doubleSpinBox_depth.setSingleStep(0.1) self.doubleSpinBox_magsus.setDisabled(True) self.doubleSpinBox_length.setDisabled(True) self.doubleSpinBox_width.setDisabled(True) self.doubleSpinBox_strike.setDisabled(True) self.doubleSpinBox_depthextent.setDisabled(True) #Modifys ComboBox self.comboBox_array.clear() self.comboBox_array.addItems(('TP Long','TP Broad','W Long','W Broad','SQ Alpha','SQ Beta', 'SQ Gamma')) def enable_3DRes(self): #Enable / Disable relevant survey Parameters self.doubleSpinBox_traverselength.setEnabled(True) self.doubleSpinBox_traverseint.setEnabled(True) self.doubleSpinBox_samplingint.setEnabled(True) self.doubleSpinBox_fieldinclination.setDisabled(True) #Enable / Disable instrument parameters self.comboBox_array.setEnabled(True) self.doubleSpinBox_a.setEnabled(True) self.doubleSpinBox_a1.setEnabled(True) self.doubleSpinBox_a2.setEnabled(True) self.doubleSpinBox_lowersensor.setDisabled(True) self.doubleSpinBox_uppersensor.setDisabled(True) #Enable / Disable Feature Parameters self.comboBox_conductivity.setEnabled(True) self.doubleSpinBox_depth.setEnabled(True) self.doubleSpinBox_length.setEnabled(True) self.doubleSpinBox_width.setEnabled(True) self.doubleSpinBox_depthextent.setEnabled(True) self.doubleSpinBox_magsus.setDisabled(True) self.doubleSpinBox_strike.setDisabled(True) #Modifys ComboBox self.comboBox_array.clear() self.comboBox_array.addItems(('TP Long','TP Broad','W Long','W Broad','SQ Alpha','SQ Beta', 'SQ Gamma', 'TZ Long', 'TZ Broad', 'TZ Theta')) def enable_3DMag(self): #Enable / Disable relevant survey Parameters self.doubleSpinBox_traverselength.setEnabled(True) self.doubleSpinBox_traverseint.setEnabled(True) self.doubleSpinBox_samplingint.setEnabled(True) self.doubleSpinBox_fieldinclination.setEnabled(True) #Enable / Disable instrument parameters self.comboBox_array.setEnabled(True) self.doubleSpinBox_lowersensor.setEnabled(True) self.doubleSpinBox_uppersensor.setEnabled(True) self.doubleSpinBox_a.setDisabled(True) self.doubleSpinBox_a1.setDisabled(True) self.doubleSpinBox_a2.setDisabled(True) #Enable / Disable Feature Parameters self.doubleSpinBox_depth.setEnabled(True) self.doubleSpinBox_length.setEnabled(True) self.doubleSpinBox_width.setEnabled(True) self.doubleSpinBox_depthextent.setEnabled(True) self.doubleSpinBox_magsus.setEnabled(True) self.doubleSpinBox_strike.setEnabled(True) self.comboBox_conductivity.setDisabled(True) #Modifys ComboBox self.comboBox_array.clear() self.comboBox_array.addItems(('Vertical', 'Total', 'Horizontal X', 'Horizontal Y')) def enable_2DMag(self): #Enable / Disable relevant survey Parameters self.doubleSpinBox_traverselength.setEnabled(True) self.doubleSpinBox_traverseint.setEnabled(True) self.doubleSpinBox_samplingint.setEnabled(True) self.doubleSpinBox_fieldinclination.setEnabled(True) #Enable / Disable instrument parameters self.comboBox_array.setEnabled(True) self.doubleSpinBox_lowersensor.setEnabled(True) self.doubleSpinBox_uppersensor.setEnabled(True) self.doubleSpinBox_a.setDisabled(True) self.doubleSpinBox_a1.setDisabled(True) self.doubleSpinBox_a2.setDisabled(True) #Enable / Disable Feature Parameters self.doubleSpinBox_depth.setEnabled(True) self.doubleSpinBox_length.setEnabled(True) self.doubleSpinBox_width.setEnabled(True) self.doubleSpinBox_depthextent.setEnabled(True) self.doubleSpinBox_magsus.setEnabled(True) self.doubleSpinBox_strike.setEnabled(True) self.comboBox_conductivity.setDisabled(True) #Modifys ComboBox self.comboBox_array.clear() self.comboBox_array.addItems(('Vertical', 'Total', 'Horizontal X', 'Horizontal Y')) def tar_data_files(self, output_name, files): if not os.path.isfile(output_name): tar = tarfile.open(output_name, "w:gz") for name in files: arcname = os.path.basename(name) tar.add(name,arcname=arcname) tar.close() def put_file(self, file_path, cloud_path): k = Key(self.bucket) string = str(self.project_code) + '/' + cloud_path print string if self.bucket.get_key(string) == None or self.overwrite: k.key = string k.set_contents_from_filename(file_path) def Warning_Dialog(self, title, text): message = QtGui.QMessageBox.warning(self,str(title),str(text)) def display_points(self, x, y): print 'display updating with Northings/Eastings' # self.Eastings = GPSMainWindow.data[:,1] # self.Northings = GPSMainWindow.data[:,0] self.mpl.canvas.ax.clear() self.mpl.canvas.ax.axis('equal') print 'canvas cleared' print len(x), 'points' self.mpl.canvas.ax.plot(x,y, 'o', ms=1, color='black') # reset the axes limits self.mpl.canvas.ax.set_xlim(xmin=np.min(x), xmax=(np.max(x))) self.mpl.canvas.ax.set_ylim(ymin=np.min(y), ymax=(np.max(y))) self.mpl.canvas.ax.grid(True) self.mpl.canvas.draw() print 'canvas drawn' def display_b_points(self): print 'display updating with Northings/Eastings' # self.Eastings = GPSMainWindow.data[:,1] # self.Northings = GPSMainWindow.data[:,0] self.mpl.canvas.ax.clear() self.mpl.canvas.ax.axis('equal') print 'canvas cleared' self.mpl.canvas.ax.plot(self.sens1[:,1],self.sens1[:,2], 'o', ms=1, color='red') self.mpl.canvas.ax.plot(self.sens2[:,1],self.sens2[:,2], 'o', ms=1, color='blue') self.mpl.canvas.ax.plot(self.sens3[:,1],self.sens3[:,2], 'o', ms=1, color='green') self.mpl.canvas.ax.plot(self.sens4[:,1],self.sens4[:,2], 'o', ms=1, color='yellow') # reset the axes limits #self.mpl.canvas.ax.set_xlim(xmin=np.min(self.sens1[:,1]), xmax=(np.max(self.sens1[:,1]))) #self.mpl.canvas.ax.set_ylim(ymin=np.min(self.sens1[:,2]), ymax=(np.max(self.sens1[:,2]))) self.mpl.canvas.ax.grid(True) self.mpl.canvas.draw() print 'canvas drawn' def MagRes2D3Dtoggle(self): print 'Toggled' if self.radioButton_mag.isChecked(): if self.radioButton_2d.isChecked(): self.ClearPlot() self.enable_2DMag() else: self.ClearPlot() self.enable_3DMag() else: if self.radioButton_2d.isChecked(): self.ClearPlot() self.enable_2DRes() elif self.radioButton_3d.isChecked(): self.ClearPlot() self.enable_3DRes() else: self.ClearPlot() self.enable_2DRespseudo() print self.radioButton_mag.isChecked(),self.radioButton_res.isChecked() def CalculateFields(self): if self.radioButton_mag.isChecked(): if self.radioButton_2d.isChecked(): self.calculate_2DMag() else: self.calculate_3DMag() else: if self.radioButton_2d.isChecked(): self.calculate_2DRes() elif self.radioButton_3d.isChecked(): self.calculate_3DRes() else: self.calculate_2DRespseudo() def calculate_2DRes(self): array = ['tp_long','tp_broad','wenner_long','wenner_broad','square_a','square_b','square_g','trap_l','trap_b','trap_t'][self.comboBox_array.currentIndex()] a = self.doubleSpinBox_a.value() a1 = self.doubleSpinBox_a1.value() a2 = self.doubleSpinBox_a2.value() stop = self.doubleSpinBox_traverselength.value()/2.0 sample = self.doubleSpinBox_samplingint.value() x = np.arange(-stop,stop+sample,sample) conductivity = [1.0e+6,1.0e-6][self.comboBox_conductivity.currentIndex()] contrast = (conductivity - 1.0)/(1 + (2* conductivity)) z = self.doubleSpinBox_depth.value() output = res2D(array, a, a1, a2, x, contrast, z) #Defines variables for saving self.x = x self.y = output self.header = "array, a, a1, a2, conductivity, z \n " + str(array) + ',' + str(a) + ',' + str(a1) + ',' + str(a2) + ',' + str(conductivity) + ',' + str(z) + "\n" self.xtitle = 'Relative Position (x)' self.ytitle = 'Relative Response' self.title = 'Resistivity Profile with ' + str(array) + ' over ' + str(conductivity) + ' ohm/m sphere.' self.plot_2d() def calculate_2DRespseudo(self): array = ['tp_long','tp_broad','wenner_long','wenner_broad','square_a','square_b','square_g'][self.comboBox_array.currentIndex()] a = self.doubleSpinBox_a.value() a1 = self.doubleSpinBox_a1.value() a2 = self.doubleSpinBox_a2.value() array_range = np.arange(a, a1 + a2, a2) stop = self.doubleSpinBox_traverselength.value()/2.0 sample = self.doubleSpinBox_samplingint.value() x = np.arange(-stop,stop+sample,sample) conductivity = [1.0e+6,1.0e-6][self.comboBox_conductivity.currentIndex()] contrast = (conductivity - 1.0)/(1 + (2* conductivity)) z = self.doubleSpinBox_depth.value() self.output = res2Dpseudo(array, array_range, x, contrast, z) self.xtitle = 'Relative Position (x)' self.ytitle = 'Relative Depth' self.title = 'Resistivity Pseudosection With ' + str(array) + ' Over ' + str(conductivity) + ' Ohm/m Sphere.' self.arrayrange = array_range #Defines variables for saving #self.x = x #self.y = output #self.header = "array, a, a1, a2, conductivity, z \n " + str(array) + ',' + str(a) + ',' + str(a1) + ',' + str(a2) + ',' + str(conductivity) + ',' + str(z) + "\n" self.plot_2dpseudo() def calculate_3DRes(self): array = ['tp_long','tp_broad','wenner_long','wenner_broad','square_a','square_b','square_g','trap_l','trap_b','trap_t'][self.comboBox_array.currentIndex()] a = self.doubleSpinBox_a.value() a1 = self.doubleSpinBox_a1.value() a2 = self.doubleSpinBox_a2.value() stop = self.doubleSpinBox_traverselength.value() xsample = self.doubleSpinBox_samplingint.value() ysample = self.doubleSpinBox_traverseint.value() x = np.arange(stop,stop+xsample,xsample) y = np.arange(-stop,stop+ysample,ysample) conductivity = [1.0e+6,1.0e-6][self.comboBox_conductivity.currentIndex()] contrast = (conductivity - 1.0)/(1 + (2* conductivity)) z = self.doubleSpinBox_depth.value() #Depth to top of bounding box z1 = self.doubleSpinBox_depthextent.value() #Depth to bottom of bounding box output = res2D(array, a, a1, a2, x, contrast, z) #Defines variables for saving self.x = x self.y = output self.header = "array, a, a1, a2, conductivity, z \n " + str(array) + ',' + str(a) + ',' + str(a1) + ',' + str(a2) + ',' + str(conductivity) + ',' + str(z) + "\n" self.xtitle = 'Relative Position (x)' self.ytitle = 'Relative Response' self.title = 'Resistivity Pseudosection with ' + str(array) + ' over ' + str(conductivity) + ' ohm/m sphere.' self.plot_2d() def save_csv(self): fname = QtGui.QFileDialog.getSaveFileName(self, 'Save File', '*.csv') print fname, str(fname) output_text = np.column_stack((self.x,self.y)) np.savetxt(str(fname),output_text,fmt ='%1.2f',delimiter=',', header = self.header) def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() def plot_2d(self): self.mpl.canvas.ax.plot(self.x,self.y) self.mpl.canvas.ax.axis('auto') #self.mpl.canvas.ax.set_xlim(xmin=np.min(self.x), xmax=(np.max(self.x))) self.mpl.canvas.ax.set_ylim(ymin=np.min(self.y), ymax=(np.max(self.y))) self.mpl.canvas.ax.set_autoscale_on(True) self.mpl.canvas.ax.autoscale_view(True,True,True) self.mpl.canvas.ax.set_xlabel(self.xtitle, size = 15) self.mpl.canvas.ax.set_ylabel(self.ytitle, size = 15) self.mpl.canvas.ax.set_title(self.title, size = 15) self.mpl.canvas.draw() def plot_2dpseudo(self): self.ClearPlot() temp = np.flipud(self.output) self.mpl.canvas.ax.imshow(temp, interpolation='none', cmap=plt.cm.Greys,aspect='auto',origin='upper') self.mpl.canvas.ax.set_xlabel(self.xtitle, size = 15) self.mpl.canvas.ax.set_ylabel(self.ytitle, size = 15) self.mpl.canvas.ax.set_title(self.title, size = 15) self.cb = plt.colorbar(self.mpl.canvas.ax.imshow(self.output,cmap=plt.cm.Greys), ticks=self.arrayrange) #self.mpl.canvas.colorbar(self.mpl.canvas.ax.imshow(self.output,cmap=plt.cm.Greys), ticks=self.arrayrange) self.mpl.canvas.draw() def Button_Definitions(self): self.firstrun=True QtCore.QObject.connect(self.radioButton_mag, QtCore.SIGNAL("toggled(bool)"), self.MagRes2D3Dtoggle) QtCore.QObject.connect(self.radioButton_2d, QtCore.SIGNAL("toggled(bool)"), self.MagRes2D3Dtoggle) self.pushButton_plot.clicked.connect(self.CalculateFields) self.pushButton_clear.clicked.connect(self.ClearPlot) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"),self, self.CalculateFields) self.action_Save_Data.triggered.connect(self.save_csv) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+S"),self, self.save_csv) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"),self, self.copy_to_clipboard) # Buttons in Toolbar #self.push_put_data.clicked.connect(self.put_cloud_data) #self.push_load_field.clicked.connect(self.load_field) #self.Push_cor_GNSS.clicked.connect(self.load_cloud_points) #self.Push_cor_GNSS.clicked.connect(self.Process_GNSS) #self.Push_display_barty_points.clicked.connect(self.calculate_barty_locs) # self.Push_Desample.clicked.connect(self.remove_collinears) # self.Push_Greyscale.clicked.connect(self.Grid_Data) # self.Push_ZMT.clicked.connect(self.ZMT) # self.Push_Calibrate.clicked.connect(self.calibrate) # self.Push_Despike.clicked.connect(self.Despike) # self.Push_Export.clicked.connect(self.import_NMEA) # Buttons in Menu # self.actionOpen_File.triggered.connect(self.data_SourceFile) # self.actionDisplay_GreyScale.triggered.connect(self.Grid_Data) #QtCore.QObject.connect(self.mplactionQuit, QtCore.SIGNAL('triggered()'), QtGui.qApp, QtCore.SLOT("quit()")) def __init__(self, parent = None): # initialization of the superclass super(ModellerMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) #self.navi_toolbar.clear() # Add the x,y location widget at the right side of the toolbar # The stretch factor is 1 which means any resizing of the toolbar # will resize this label instead of the buttons. # self.navi_toolbar.locLabel = QtGui.QLabel( "", self ) # self.navi_toolbar.locLabel.setAlignment(QtCore.Qt.AlignLeft) # self.navi_toolbar.locLabel.setSizePolicy( # QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, # QtGui.QSizePolicy.Expanding)) # labelAction = self.navi_toolbar.addWidget(self.navi_toolbar.locLabel) # labelAction.setVisible(True) #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.Button_Definitions() #Run Radio Toggle Code to grey / allow relevant options self.radioButton_2d.click() self.radioButton_res.click() self.MagRes2D3Dtoggle()
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() # Clears Legend self.legend.remove() self.legend_definitions() self.mpl.canvas.draw() def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def Open_File(self): self.fname = QtGui.QFileDialog.getOpenFileName() # Opes File with open(self.fname, "r") as f: num_cols = len(f.readline().split(",")) f.seek(0) self.data = np.genfromtxt( f, names=True, delimiter=",", dtype=None, filling_values=np.nan, usecols=(range(0, num_cols)) ) print self.data # Defines x and y values self.x = self.data.dtype.names print self.x self.y = self.data.dtype.names # Populates combo boxes with header names self.xcombo.clear() self.xcombo.addItems(self.x) self.ycombo.clear() self.ycombo.addItems(self.y) # Clears Legend self.legend_definitions() """ def Save_Stats(self): self.f = open(self.fname, 'rb') data = np.genfromtxt(self.f, skip_header=1) fname = QtGui.QFileDialog.getSaveFileName(self, 'Save File', '*.csv') output_text = np.column_stack((self.x,self.y)) np.savetxt(str(fname),output_text,fmt ='%1.2f',delimiter=',', header = self.header) """ def Plot_Function(self): self.legend.remove() # Takes x and y values to plot from combo box selection self.xval = self.data[self.data.dtype.names[self.xcombo.currentIndex()]] self.yval = self.data[self.data.dtype.names[self.ycombo.currentIndex()]] # self.yval = self.yval - np.median(self.yval) # Calculates stats info of y values self.stats() temp_scatter = self.mpl.canvas.ax.scatter( self.xval, self.yval, color=self.marker_colour.currentText(), marker=self.marker_style.currentText(), s=self.marker_size.value(), ) self.handles.append(temp_scatter) self.labels.append(self.data.dtype.names[self.ycombo.currentIndex()]) self.legend = self.mpl.canvas.fig.legend(self.handles, self.labels, "upper right") self.mpl.canvas.ax.set_ylim(ymin=np.min(self.yval), ymax=(np.max(self.yval))) self.mpl.canvas.ax.set_xlim(xmin=np.min(self.xval), xmax=np.max(self.xval)) self.mpl.canvas.ax.set_autoscale_on(True) self.mpl.canvas.ax.autoscale_view(True, True, True) self.mpl.canvas.ax.set_xlabel(self.x_units.text(), size=15) self.mpl.canvas.ax.set_ylabel(self.y_units.text(), size=15) self.mpl.canvas.ax.set_title(self.chart_title.text(), size=20) # self.mpl.canvas.ax.axis('auto') # Creates scatter plot self.mpl.canvas.draw() def legend_definitions(self): # Handles legend self.handles = [] self.labels = [] # self.colors = itertools.cycle(["b","g","r","c","m","y","b"]) # self.markers = itertools.cycle([".","D","p","*","+"]) self.legend = self.mpl.canvas.fig.legend(self.handles, self.labels, "upper right") def stats(self): # Calculates stats info of y values and sends back to UI self.min = str(np.round(np.min(self.yval), decimals=3)) self.min_output.setText(self.min) self.max = str(np.round(np.max(self.yval), decimals=3)) self.max_output.setText(self.max) self.mean = str(np.round(np.mean(self.yval), decimals=3)) self.mean_output.setText(self.mean) self.median = str(np.round(np.median(self.yval), decimals=3)) self.median_output.setText(self.median) self.sd = str(np.round(np.std(self.yval), decimals=3)) self.sd_output.setText(self.sd) def moving_average_buttons(self): # Radio Button Helper if self.rolling_mean_radio.isChecked(): self.moving_mean() else: self.moving_median() def moving_mean(self): self.trend_y = rolling_mean(self.yval, self.moving_avg_window.value()) self.plot_trendline() def moving_median(self): self.trend_y = rolling_median(self.yval, self.moving_avg_window.value()) self.plot_trendline() def savgol_filter(self): self.trend_y = scipy.signal.savgol_filter(self.yval, self.savgol_window.value(), self.savgol_order.value()) self.plot_trendline() def fit_manager(self): if self.data_trend.isChecked(): self.fit_y = self.yval print self.fit_y self.polyfit() print "Data!" elif self.savgol_trend.isChecked(): self.fit_y = self.trend_y = scipy.signal.savgol_filter( self.yval, self.savgol_window.value(), self.savgol_order.value() ) print self.fit_y self.polyfit() print "Savgol!" def polyfit(self): # Calculates Polynomial Fit with Error Estimation # Calculate Poly Fit self.order = self.poly_order.value() self.p = np.polyfit(self.xval, self.fit_y, self.order) # coefficients self.trend_y = np.polyval(self.p, self.xval) # fit values self.plot_trendline() """if self.data_trend.isChecked(): self.p = np.polyfit(self.xval, self.yval, self.order) #coefficients self.trend_y = np.polyval(self.p, self.xval) #fit values self.plot_trendline() if self.avg_trend.isChecked(): self.rm_y= rolling_mean(self.yval, self.moving_avg_window.value()) self.rm_y = np.ma.masked_invalid(self.rm_y) print np.shape(self.rm_y) print self.rm_y print np.shape(self.xval) self.p = np.polyfit(self.xval, self.rm_y, self.order) #coefficients self.trend_y = np.polyval(self.p, self.xval) #fit values self.plot_trendline()""" # Calculate coeffecient of determination self.residuals = np.subtract(self.yval, self.trend_y) # residuals self.RSS = np.sum(np.square(self.residuals)) # residual sum of squares self.TSS = np.sum(np.square(np.subtract(self.yval, np.mean(self.yval)))) # Sends R-Squared value back to UI self.r_squared = str(np.round(np.subtract(1, np.divide(self.RSS, self.TSS)), decimals=3)) # send back to GUI self.r_squared_output.setText(self.r_squared) # Sends trendline equation back to UI coeff1 = np.round(self.p[0], decimals=10) coeff1 = str(coeff1) coeff2 = np.round(self.p[1], decimals=8) coeff2 = str(coeff2) if self.order == 1: self.fit_equation = coeff1 + "x + " + coeff2 self.trendline_equation.setText(self.fit_equation) if self.order == 2: coeff3 = np.round(self.p[2], decimals=3) coeff3 = str(coeff3) self.fit_equation = coeff1 + "x^2 + " + coeff2 + "x + " + coeff3 self.trendline_equation.setText(self.fit_equation) if self.order == 3: coeff3 = np.round(self.p[2], decimals=10) coeff3 = str(coeff3) coeff4 = np.round(self.p[3], decimals=3) coeff4 = str(coeff4) self.fit_equation = coeff1 + "x^3 + " + coeff2 + "x^2 + " + coeff3 + "x + " + coeff4 self.trendline_equation.setText(self.fit_equation) def plot_histogram(self): self.ClearPlot() self.yval = self.data[self.data.dtype.names[self.ycombo.currentIndex()]] self.mpl.canvas.ax.hist(self.yval, self.bins.value()) self.mpl.canvas.ax.set_xlabel("Value - mS/m", size=15) self.mpl.canvas.ax.set_ylabel("Frequency", size=15) self.mpl.canvas.ax.set_title(self.chart_title.text() + " Histogram. Bins = " + str(self.bins.value()), size=20) self.mpl.canvas.draw() def plot_trendline(self): # Plots poly-line as solid line self.mpl.canvas.ax.plot( self.xval, self.trend_y, color=self.line_colour.currentText(), linestyle=self.line_style.currentText(), linewidth=self.line_width.value(), ) self.mpl.canvas.ax.set_ylim(ymin=np.min(self.yval), ymax=(np.max(self.yval))) self.mpl.canvas.ax.set_autoscale_on(True) self.mpl.canvas.ax.autoscale_view(True, True, True) self.mpl.canvas.ax.set_xlabel(self.x_units.text(), size=15) self.mpl.canvas.ax.set_ylabel(self.y_units.text(), size=15) self.mpl.canvas.ax.set_title(self.chart_title.text(), size=20) # self.mpl.canvas.ax.set_ylabel(self.ytitle, size = 15) # self.mpl.canvas.ax.set_title(self.title, size = 15) # self.handles.append(trendline) # self.handles.append(poly_line) # self.poly_order_title = self.poly_order.text() # self.labels.append(self.poly_order_title + ' Order Polynomial') # self.legend = self.mpl.canvas.fig.legend(self.handles,self.labels,'upper right') self.mpl.canvas.draw() def button_grid(self): # Defines button and layout # self.firstrun=True self.buttons_layout = QtGui.QGridLayout() self.buttons_box = QtGui.QGroupBox() self.buttons_box.setLayout(self.buttons_layout) self.stats_layout = QtGui.QGridLayout() self.stats_box = QtGui.QGroupBox() self.stats_box.setLayout(self.stats_layout) self.plot_layout = QtGui.QGridLayout() self.plot_box = QtGui.QGroupBox() self.plot_box.setLayout(self.plot_layout) self.curvefit_layout = QtGui.QGridLayout() self.curvefit_box = QtGui.QGroupBox() self.curvefit_box.setLayout(self.curvefit_layout) # File Properties self.Grid_horizontal_Layout_2.addWidget(self.buttons_box, 1) string = '<span style=" font-size:10pt;; font-weight:600;">File Settings</span>' self.buttons_layout_text = QtGui.QLabel(string, self) self.buttons = QtGui.QButtonGroup() self.open_button = QtGui.QPushButton("Open", self) self.buttons.addButton(self.open_button) self.open_button.clicked.connect(self.Open_File) self.plot_button = QtGui.QPushButton("Plot", self) self.buttons.addButton(self.plot_button) self.plot_button.clicked.connect(self.Plot_Function) self.clear_button = QtGui.QPushButton("Clear", self) self.buttons.addButton(self.clear_button) self.clear_button.clicked.connect(self.ClearPlot) self.chart_title = QtGui.QLineEdit(self) self.chart_title.setText("Enter Chart Title") self.xcombo = QtGui.QComboBox() self.xcombo.addItems("X") self.x_lbl = QtGui.QLabel("X Values --") self.ycombo = QtGui.QComboBox() self.ycombo.addItems("Y") self.y_lbl = QtGui.QLabel("Y values --") self.x_units = QtGui.QLineEdit(self) self.x_units_lbl = QtGui.QLabel("Input X Units:", self) # self.connect(self.inputDlgBtn, QtCore.SIGNAL("clicked()"), self.openInputDialog) self.y_units = QtGui.QLineEdit(self) self.y_units_lbl = QtGui.QLabel("Input Y Units:", self) self.buttons_layout.addWidget(self.buttons_layout_text, 0, 0, 1, 4) self.buttons_layout.addWidget(self.open_button, 1, 0) self.buttons_layout.addWidget(self.plot_button, 2, 0) self.buttons_layout.addWidget(self.clear_button, 3, 0) self.buttons_layout.addWidget(self.chart_title, 4, 0) self.buttons_layout.addWidget(self.x_lbl, 1, 1) self.buttons_layout.addWidget(self.xcombo, 2, 1) self.buttons_layout.addWidget(self.y_lbl, 3, 1) self.buttons_layout.addWidget(self.ycombo, 4, 1) self.buttons_layout.addWidget(self.x_units_lbl, 1, 3) self.buttons_layout.addWidget(self.x_units, 2, 3) self.buttons_layout.addWidget(self.y_units_lbl, 3, 3) self.buttons_layout.addWidget(self.y_units, 4, 3) # Plotting Properties self.Grid_horizontal_Layout_2.addWidget(self.plot_box, 1) string = '<span style=" font-size:10pt;; font-weight:600;">Plot Settings</span>' self.plot_layout_text = QtGui.QLabel(string, self) self.plot_buttons = QtGui.QButtonGroup() self.marker_style = QtGui.QComboBox() self.marker_style.addItems((".", "o", "v", "^", "*", "D", "d")) self.marker_style_lbl = QtGui.QLabel("Marker Style", self) self.marker_colour = QtGui.QComboBox() self.marker_size_lbl = QtGui.QLabel("Marker Size", self) self.marker_size = QtGui.QSpinBox() self.marker_size.setRange(1, 1000) self.marker_size.setValue(30) self.marker_colour.addItems(("0.25", "0.5", "0.75", "k", "b", "g", "r", "c", "y", "m")) self.marker_colour_lbl = QtGui.QLabel("Marker Colour", self) self.line_style = QtGui.QComboBox() self.line_style.addItems(("-", "--", ":", "_")) self.line_style_lbl = QtGui.QLabel("Line Style", self) self.line_width = QtGui.QSpinBox() self.line_width.setRange(1, 10) self.line_width_lbl = QtGui.QLabel("Line Width", self) self.line_colour = QtGui.QComboBox() self.line_colour.addItems(("r", "b", "g", "c", "y", "m", "0.25", "0.5", "0.75", "k")) self.line_colour_lbl = QtGui.QLabel("Line Colour", self) self.plot_layout.addWidget(self.plot_layout_text, 0, 0, 1, 2) self.plot_layout.addWidget(self.line_style_lbl, 1, 0) self.plot_layout.addWidget(self.line_style, 1, 1) self.plot_layout.addWidget(self.line_width_lbl, 2, 0) self.plot_layout.addWidget(self.line_width, 2, 1) self.plot_layout.addWidget(self.line_colour_lbl, 3, 0) self.plot_layout.addWidget(self.line_colour, 3, 1) self.plot_layout.addWidget(self.marker_style_lbl, 4, 0) self.plot_layout.addWidget(self.marker_style, 4, 1) self.plot_layout.addWidget(self.marker_size_lbl, 5, 0) self.plot_layout.addWidget(self.marker_size, 5, 1) self.plot_layout.addWidget(self.marker_colour_lbl, 6, 0) self.plot_layout.addWidget(self.marker_colour, 6, 1) self.Grid_horizontal_Layout_2.addWidget(self.curvefit_box, 1) string = '<span style=" font-size:10pt;; font-weight:600;">Filtering/Fitting Settings</span>' self.curvefit_layout_text = QtGui.QLabel(string, self) self.curvefit_buttons = QtGui.QButtonGroup() self.curvefit_buttons = QtGui.QButtonGroup() self.poly_label = QtGui.QLabel("Poly Fit:") # self.poly_fit = QtGui.QRadioButton('Poly Fit', self) self.data_trend = QtGui.QRadioButton("Of Data:", self) self.savgol_trend = QtGui.QRadioButton("Filtered Data:", self) self.poly_order_text = QtGui.QLabel("Order", self) self.poly_order = QtGui.QSpinBox(self) self.poly_order.setRange(1, 10) self.poly_plot_button = QtGui.QPushButton("Plot", self) self.curvefit_buttons.addButton(self.poly_plot_button) self.poly_plot_button.clicked.connect(self.fit_manager) self.rolling_mean_radio = QtGui.QRadioButton("Rolling Mean", self) self.rolling_median_radio = QtGui.QRadioButton("Rolling Median", self) self.moving_avg_window_text = QtGui.QLabel("Window") self.moving_avg_window = QtGui.QSpinBox(self) self.moving_avg_window.setRange(1, 1000) self.moving_avg_plot = QtGui.QPushButton("Plot", self) self.moving_avg_plot.clicked.connect(self.moving_average_buttons) self.savgol_lbl = QtGui.QLabel("Savgol-Golay Filter: ", self) self.savgol_window_lbl = QtGui.QLabel("Window Length", self) self.savgol_window = QtGui.QSpinBox(self) self.savgol_window.setRange(1, 100) self.savgol_window.setValue(5) self.savgol_order_lbl = QtGui.QLabel("Poly Order", self) self.savgol_order = QtGui.QSpinBox(self) self.savgol_order.setRange(-4, 4) self.savgol_order.setValue(2) self.savgol_plot = QtGui.QPushButton("Plot", self) self.savgol_plot.clicked.connect(self.savgol_filter) self.trendline_lbl = QtGui.QLabel("Trendline Equation") self.trendline_equation = QtGui.QLineEdit(self) self.r_squared_lbl = QtGui.QLabel("R Squared") self.r_squared_output = QtGui.QLineEdit(self) self.curvefit_layout.addWidget(self.curvefit_layout_text, 0, 0, 1, 4) self.curvefit_layout.addWidget(self.poly_label, 1, 0) self.curvefit_layout.addWidget(self.data_trend, 1, 1) self.curvefit_layout.addWidget(self.savgol_trend, 1, 2) self.curvefit_layout.addWidget(self.poly_order_text, 1, 3) self.curvefit_layout.addWidget(self.poly_order, 1, 4) self.curvefit_layout.addWidget(self.poly_plot_button, 1, 5) self.curvefit_layout.addWidget(self.rolling_mean_radio, 2, 0) self.curvefit_layout.addWidget(self.rolling_median_radio, 2, 1) self.curvefit_layout.addWidget(self.moving_avg_window_text, 2, 2) self.curvefit_layout.addWidget(self.moving_avg_window, 2, 3) self.curvefit_layout.addWidget(self.moving_avg_plot, 2, 4) self.curvefit_layout.addWidget(self.savgol_lbl, 3, 0) self.curvefit_layout.addWidget(self.savgol_window_lbl, 3, 1) self.curvefit_layout.addWidget(self.savgol_window, 3, 2) self.curvefit_layout.addWidget(self.savgol_order_lbl, 3, 3) self.curvefit_layout.addWidget(self.savgol_order, 3, 4) self.curvefit_layout.addWidget(self.savgol_plot, 3, 5) self.curvefit_layout.addWidget(self.trendline_lbl, 4, 0) self.curvefit_layout.addWidget(self.trendline_equation, 4, 1) self.curvefit_layout.addWidget(self.r_squared_lbl, 4, 2) self.curvefit_layout.addWidget(self.r_squared_output, 4, 3) # Stats Properties self.Grid_horizontal_Layout_2.addWidget(self.stats_box, 1) string = '<span style=" font-size:10pt;; font-weight:600;">Stats</span>' self.stats_layout_text = QtGui.QLabel(string, self) self.min_output_lbl = QtGui.QLabel("Data Min:") self.min_output = QtGui.QLineEdit(self) self.max_output_lbl = QtGui.QLabel("Data Max:") self.max_output = QtGui.QLineEdit(self) self.mean_output_lbl = QtGui.QLabel("Data Mean:") self.mean_output = QtGui.QLineEdit(self) self.median_output_lbl = QtGui.QLabel("Data Median:") self.median_output = QtGui.QLineEdit(self) self.sd_lbl = QtGui.QLabel("Std Deviation:") self.sd_output = QtGui.QLineEdit(self) self.bins_lbl = QtGui.QLabel("Histogram Bins:") self.bins = QtGui.QSpinBox(self) self.bins.setRange(1, 1000) self.bins.setValue(50) self.histogram = QtGui.QPushButton("Plot", self) self.histogram.clicked.connect(self.plot_histogram) self.stats_layout.addWidget(self.stats_layout_text, 0, 0, 1, 4) self.stats_layout.addWidget(self.min_output_lbl, 1, 0) self.stats_layout.addWidget(self.min_output, 1, 1) self.stats_layout.addWidget(self.max_output_lbl, 2, 0) self.stats_layout.addWidget(self.max_output, 2, 1) self.stats_layout.addWidget(self.mean_output_lbl, 3, 0) self.stats_layout.addWidget(self.mean_output, 3, 1) self.stats_layout.addWidget(self.median_output_lbl, 4, 0) self.stats_layout.addWidget(self.median_output, 4, 1) self.stats_layout.addWidget(self.sd_lbl, 5, 0) self.stats_layout.addWidget(self.sd_output, 5, 1) self.stats_layout.addWidget(self.bins_lbl, 6, 0) self.stats_layout.addWidget(self.bins, 6, 1) self.stats_layout.addWidget(self.histogram, 6, 2) def __init__(self, parent=None): # initialization of the superclass super(ArchaeoPYMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) # Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() # Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon("home.png"), "Home", self.navi_toolbar.home) # a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon("move.png"), "Pan", self.navi_toolbar.pan) a.setToolTip("Pan axes with left mouse, zoom with right") a = self.navi_toolbar.addAction(self.navi_toolbar._icon("zoom_to_rect.png"), "Zoom", self.navi_toolbar.zoom) a.setToolTip("Zoom to Rectangle") a = self.navi_toolbar.addAction(self.navi_toolbar._icon("filesave.png"), "Save", self.navi_toolbar.save_figure) a.setToolTip("Save the figure") QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard) # self.xlabel = QtGui.QInputDialog.getText(self, 'X-axis Label') # Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.button_grid()
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def Open_File(self): self.fname = QtGui.QFileDialog.getOpenFileName() self.Image2Float() def Image2Float(self): self.f = open(self.fname, 'rb') self.image = io.imread(self.f) self.array = img_as_float(self.image) def Plot_Original_Image(self): self.mpl.canvas.ax.clear() self.mpl.canvas.ax.imshow(self.image) self.mpl.canvas.draw() def Plot_Function(self): self.output = cannyfilter(self.array) #Updated to imported module as necessary self.mpl.canvas.ax.clear() self.mpl.canvas.ax.imshow(self.output, cmap=plt.cm.gray) self.mpl.canvas.draw() def Button_Definitions(self): self.firstrun=True self.Open_button = QtGui.QPushButton('Open', self) self.fname = self.Open_button.clicked.connect(self.Open_File) self.fname = self.Open_button.clicked.connect(self.Plot_Original_Image) self.Button_Layout.addWidget(self.Open_button) self.pushButton_plot.clicked.connect(self.Plot_Function) self.pushButton_clear.clicked.connect(self.ClearPlot) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"),self, self.Plot_Function) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"),self, self.copy_to_clipboard) def __init__(self, parent = None): # initialization of the superclass super(ArchaeoPYMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.Button_Definitions()
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() #Clears Legend self.legend.remove() self.legend_definitions() self.mpl.canvas.draw() def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def Open_File(self): self.fname = QtGui.QFileDialog.getOpenFileName() #Opes File with open(self.fname, 'r') as f: num_cols = len(f.readline().split(' '))-1 f.seek(0) self.data = np.genfromtxt(f, names=True, delimiter=' ',dtype=None,filling_values = np.nan, usecols=(range(0,num_cols))) #Defines x and y values self.x = self.data.dtype.names self.y = self.data.dtype.names self.z = self.data.dtype.names #Populates combo boxes with header names self.xcombo.clear() self.xcombo.addItems(self.x) self.ycombo.clear() self.ycombo.addItems(self.y) self.zcombo.clear() self.zcombo.addItems(self.z) #Clears Legend #self.legend_definitions() ''' def Save_Stats(self): self.f = open(self.fname, 'rb') data = np.genfromtxt(self.f, skip_header=1) fname = QtGui.QFileDialog.getSaveFileName(self, 'Save File', '*.csv') output_text = np.column_stack((self.x,self.y)) np.savetxt(str(fname),output_text,fmt ='%1.2f',delimiter=',', header = self.header) ''' def grid_data(self): self.mpl.canvas.ax.clear() #Takes x and y values to plot from combo box selection self.xval = self.data[self.data.dtype.names[self.xcombo.currentIndex()]] self.yval = self.data[self.data.dtype.names[self.ycombo.currentIndex()]] self.zval = self.data[self.data.dtype.names[self.zcombo.currentIndex()]] self.x_int = float(self.xint_box.text()) self.y_int = float(self.yint_box.text()) #xi = np.arange(np.min(self.xval), np.max(self.xval), self.x_int) #yi = np.arange(np.min(self.yval), np.max(self.yval), self.y_int) #zi = griddata(self.xval, self.yval, self.zval, xi, yi, interp='nn') #print np.shape(zi) #self.mpl.canvas.ax.axis('auto') #Creates scatter plot self.mpl.canvas.ax.imshow(zi) self.mpl.canvas.draw() np.savetxt('test.txt', zi, delimiter=' ') def save_data(self): self.save_fname = QtGui.QFileDialog.getSaveFileName(self, 'Save Gridded Data', selectedFilter='*.txt') def stats(self): #Calculates stats info of y values and sends back to UI self.mean = str(np.round(np.mean(self.yval), decimals=3)) self.mean_output.setText(self.mean) self.median = str(np.round(np.median(self.yval), decimals=3)) self.median_output.setText(self.median) self.sd = str(np.round(np.std(self.yval), decimals=3)) self.sd_output.setText(self.sd) def moving_average_buttons(self): #Radio Button Helper if self.rolling_mean_radio.isChecked(): self.moving_mean() else: self.moving_median() def moving_mean(self): self.trend_y= rolling_mean(self.yval, self.moving_avg_window.value()) self.plot_trendline() def moving_median(self): self.trend_y = rolling_median(self.yval, self.moving_avg_window.value()) self.plot_trendline() def button_grid(self): #Defines button and layout #self.firstrun=True self.buttons_layout = QtGui.QGridLayout() self.buttons_box = QtGui.QGroupBox() self.buttons_box.setLayout(self.buttons_layout) self.stats_layout = QtGui.QGridLayout() self.stats_box = QtGui.QGroupBox() self.stats_box.setLayout(self.stats_layout) self.plot_layout = QtGui.QGridLayout() self.plot_box = QtGui.QGroupBox() self.plot_box.setLayout(self.plot_layout) #File Properties self.Grid_horizontal_Layout_2.addWidget(self.buttons_box, 1) string = '<span style=" font-size:12pt;; font-weight:600;">File Settings</span>' self.buttons_layout_text = QtGui.QLabel(string, self) self.buttons = QtGui.QButtonGroup() self.open_button = QtGui.QPushButton('Open', self) self.buttons.addButton(self.open_button) self.open_button.clicked.connect(self.Open_File) self.grid_button = QtGui.QPushButton('Grid', self) self.buttons.addButton(self.grid_button) self.grid_button.clicked.connect(self.grid_data) self.clear_button = QtGui.QPushButton('Clear', self) self.buttons.addButton(self.clear_button) self.clear_button.clicked.connect(self.ClearPlot) self.chart_title = QtGui.QLineEdit(self) self.chart_title.setText("Enter Chart Title") self.xy_units = QtGui.QLineEdit(self) self.xy_units.setText("X/Y Units") self.z_units = QtGui.QLineEdit(self) self.z_units.setText("Z Units") self.xcombo = QtGui.QComboBox() self.xcombo.addItems('X') self.x_lbl = QtGui.QLabel('X Values --') self.ycombo = QtGui.QComboBox() self.ycombo.addItems('Y') self.y_lbl = QtGui.QLabel('Y values --') self.zcombo = QtGui.QComboBox() self.zcombo.addItems('Z') self.z_lbl = QtGui.QLabel('Z values --') self.xint_lbl = QtGui.QLabel('X Interval') self.xint_box = QtGui.QLineEdit() self.yint_lbl = QtGui.QLabel('Y Interval') self.yint_box = QtGui.QLineEdit() self.buttons_layout.addWidget(self.buttons_layout_text, 0,0,1,4) self.buttons_layout.addWidget(self.open_button, 1,0) self.buttons_layout.addWidget(self.grid_button, 2,0) self.buttons_layout.addWidget(self.clear_button, 3,0) self.buttons_layout.addWidget(self.chart_title, 4,0) self.buttons_layout.addWidget(self.xy_units, 5,0) self.buttons_layout.addWidget(self.z_units, 6,0) self.buttons_layout.addWidget(self.x_lbl, 1,1) self.buttons_layout.addWidget(self.xcombo, 2,1) self.buttons_layout.addWidget(self.y_lbl, 3,1) self.buttons_layout.addWidget(self.ycombo, 4,1) self.buttons_layout.addWidget(self.z_lbl, 5,1) self.buttons_layout.addWidget(self.zcombo, 6,1) self.buttons_layout.addWidget(self.xint_lbl, 1,2) self.buttons_layout.addWidget(self.xint_box, 2,2) self.buttons_layout.addWidget(self.yint_lbl, 3,2) self.buttons_layout.addWidget(self.yint_box, 4,2) def __init__(self, parent = None): # initialization of the superclass super(ArchaeoPYMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"),self, self.copy_to_clipboard) #self.xlabel = QtGui.QInputDialog.getText(self, 'X-axis Label') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.button_grid()
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def Open_Geoplot(self): self.fname = QtGui.QFileDialog.getOpenFileName( self, "Load CMPe", "C:\Geoplot\COMP", 'Geoplot CMP FIle (*.cmp)') self.grid_length = self.TravL_val.value() self.grid_width = self.GridL_val.value() self.sample_interval = self.TravI_val.value() self.traverse_interval = self.GridI_val.value() self.output = Load_Comp(self.fname, self.grid_length, self.grid_width, self.sample_interval, self.traverse_interval) self.mean = np.nanmean(self.output) self.std = np.nanstd(self.output) #Set PLotting ranges to be +- 1 SD self.neg_val.setValue(self.mean - self.std) self.pos_val.setValue(self.mean + self.std) def Save_image(self): self.o_fname = QtGui.QFileDialog.getSaveFileName( self, "Save Image", "", 'PNG Image FIle (*.png)') print self.output, self.pos_val.value(), self.neg_val.value( ), self.o_fname, self.TravI_val.value(), self.GridI_val.value() array2image(self.output, self.pos_val.value(), self.neg_val.value(), self.o_fname, self.TravI_val.value(), self.GridI_val.value()) def Plot_Function(self): #Get values from Options Grid self.mpl.canvas.ax.clear() print np.shape(self.output) self.mpl.canvas.ax.imshow( self.output, cmap=plt.cm.Greys, extent=[0, self.grid_length, self.grid_width, 0], aspect='equal', interpolation='none', vmin=self.neg_val.value(), vmax=self.pos_val.value()) self.mpl.canvas.draw() def plot_options(self): self.neg_label = QtGui.QLabel('Neg Value', self) self.neg_val = QtGui.QDoubleSpinBox(self) self.neg_val.setRange(-2047, 2047) self.neg_val.setValue(-1) self.pos_label = QtGui.QLabel('Pos Value', self) self.pos_val = QtGui.QDoubleSpinBox(self) self.pos_val.setRange(-2047, 2047) self.pos_val.setValue(2) self.TravL_label = QtGui.QLabel('Trav Length', self) self.TravL_val = QtGui.QDoubleSpinBox(self) self.TravL_val.setRange(0, 1000) self.TravL_val.setValue(30) self.TravI_label = QtGui.QLabel('Sample Interval', self) self.TravI_val = QtGui.QDoubleSpinBox(self) self.TravI_val.setDecimals(3) self.TravI_val.setValue(0.125) self.GridL_label = QtGui.QLabel('Grid Width', self) self.GridL_val = QtGui.QDoubleSpinBox(self) self.GridL_val.setRange(0, 1000) self.GridL_val.setValue(30) self.GridI_label = QtGui.QLabel('Traverse Interval', self) self.GridI_val = QtGui.QDoubleSpinBox(self) self.GridI_val.setValue(1) self.Grid_horizontal_Layout_1.addWidget(self.TravL_label) self.Grid_horizontal_Layout_1.addWidget(self.TravL_val) self.Grid_horizontal_Layout_1.addWidget(self.TravI_label) self.Grid_horizontal_Layout_1.addWidget(self.TravI_val) self.Grid_horizontal_Layout_2.addWidget(self.GridL_label) self.Grid_horizontal_Layout_2.addWidget(self.GridL_val) self.Grid_horizontal_Layout_2.addWidget(self.GridI_label) self.Grid_horizontal_Layout_2.addWidget(self.GridI_val) self.Grid_horizontal_Layout_3 = QtGui.QHBoxLayout() self.Grid_horizontal_Layout_3.setObjectName("Grid_horizontal_Layout_3") self.Options_Grid.addLayout(self.Grid_horizontal_Layout_3, 2, 0, 1, 1) self.Grid_horizontal_Layout_3.addWidget(self.neg_label) self.Grid_horizontal_Layout_3.addWidget(self.neg_val) self.Grid_horizontal_Layout_3.addWidget(self.pos_label) self.Grid_horizontal_Layout_3.addWidget(self.pos_val) def Button_Definitions(self): self.firstrun = True self.Open_button = QtGui.QPushButton('Open', self) self.fname = self.Open_button.clicked.connect(self.Open_Geoplot) self.Button_Layout.addWidget(self.Open_button) self.Save_button = QtGui.QPushButton('Save', self) self.o_fname = self.Save_button.clicked.connect(self.Save_image) self.Button_Layout.addWidget(self.Save_button) self.pushButton_plot.clicked.connect(self.Plot_Function) self.pushButton_clear.clicked.connect(self.ClearPlot) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"), self, self.Plot_Function) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard) def __init__(self, parent=None): # initialization of the superclass super(ArchaeoPYMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.Button_Definitions() self.plot_options()
class ArchaeoPYMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" #Clears matplotlib plotting widget def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() #Copies image to clipboard def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def Open_File(self): self.fname = QtGui.QFileDialog.getOpenFileName() self.Image2Float() #Converts image to an array of floating points def Image2Float(self): self.f = open(self.fname, 'rb') self.image = io.imread(self.f) self.array = img_as_float(self.image) #Displays the original, opened image def Plot_Original_Image(self): self.mpl.canvas.ax.clear() self.mpl.canvas.ax.imshow(self.image) self.mpl.canvas.draw() #Applies the imported scikit image algorithm #Good be updated to select the processing algorithm from a menu..... def Plot_Function(self): self.output = adapteq( self.array) #Updated to imported module as necessary self.mpl.canvas.ax.clear() self.mpl.canvas.ax.imshow(self.output, cmap=plt.cm.gray) self.mpl.canvas.draw() def Button_Definitions(self): self.firstrun = True self.Open_button = QtGui.QPushButton('Open', self) self.fname = self.Open_button.clicked.connect(self.Open_File) self.fname = self.Open_button.clicked.connect(self.Plot_Original_Image) self.Button_Layout.addWidget(self.Open_button) self.pushButton_plot.clicked.connect(self.Plot_Function) self.pushButton_clear.clicked.connect(self.ClearPlot) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"), self, self.Plot_Function) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard) def __init__(self, parent=None): # initialization of the superclass super(ArchaeoPYMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) self.navi_toolbar.clear() #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.Button_Definitions()
class ModellerMainWindow(QtGui.QMainWindow, Ui_MainWindow): """Customization for Qt Designer created window""" def definitions(self): self.s3 = "" self.bucket = "" self.project_code = "" self.overwrite = False self.file_list = "" self.tempfile = "" def cleanup(self): print 'closing' #Defines 2D Res modelling component of UI window: what parameters the user can select. def enable_2DRes(self): #Enable / Disable relevant survey Parameters self.doubleSpinBox_xlength.setEnabled( True) #Length of traverse (relative units) self.doubleSpinBox_xlength.setValue( 10.0 ) #Sets the default value for traverse length to be 10 (relative units) self.doubleSpinBox_xlength.setSingleStep(1.0) self.doubleSpinBox_xsample.setEnabled(True) self.doubleSpinBox_xsample.setValue(0.1) self.doubleSpinBox_xsample.setSingleStep(0.05) #Disables magnetometry parameters--irrelevant for res modelling self.doubleSpinBox_ylength.setDisabled(True) self.doubleSpinBox_ysample.setDisabled(True) self.doubleSpinBox_fieldinclination.setDisabled(True) #Enable / Disable instrument parameters self.comboBox_array.setEnabled(True) self.doubleSpinBox_a.setEnabled(True) self.doubleSpinBox_a.setValue(1.0) self.doubleSpinBox_a.setSingleStep(0.1) self.doubleSpinBox_a1.setEnabled(True) self.doubleSpinBox_a1.setValue(1.0) self.doubleSpinBox_a1.setSingleStep(0.1) self.doubleSpinBox_a2.setEnabled(True) self.doubleSpinBox_a2.setValue(1.0) self.doubleSpinBox_a2.setSingleStep(0.1) self.doubleSpinBox_lowersensor.setDisabled(True) self.doubleSpinBox_uppersensor.setDisabled(True) self.doubleSpinBox_ylength.setDisabled(True) self.doubleSpinBox_ysample.setDisabled(True) #Enable / Disable Feature Parameters self.comboBox_conductivity.setEnabled(True) self.doubleSpinBox_depth.setEnabled(True) self.doubleSpinBox_depth.setValue(1.0) self.doubleSpinBox_depth.setSingleStep(0.1) self.doubleSpinBox_magsus.setDisabled(True) self.doubleSpinBox_length.setDisabled(True) self.doubleSpinBox_width.setDisabled(True) self.doubleSpinBox_strike.setDisabled(True) self.doubleSpinBox_depthextent.setDisabled(True) #Modifys ComboBox self.comboBox_array.clear() self.comboBox_array.addItems( ('TP Long', 'TP Broad', 'W Long', 'W Broad', 'SQ Alpha', 'SQ Beta', 'SQ Gamma', 'TZ Long', 'TZ Broad', 'TZ Theta')) def enable_2DRespseudo(self): #Enable / Disable relevant survey Parameters self.doubleSpinBox_xlength.setEnabled( True) #Length of traverse (relative units) self.doubleSpinBox_xlength.setValue( 10.0 ) #Sets the default value for traverse length to be 10 (relative units) self.doubleSpinBox_xlength.setSingleStep(1.0) self.doubleSpinBox_xsample.setEnabled(True) self.doubleSpinBox_xsample.setValue(0.1) self.doubleSpinBox_xsample.setSingleStep(0.05) #Disables magnetometry parameters--irrelevant for res modelling self.doubleSpinBox_ylength.setDisabled(True) self.doubleSpinBox_ysample.setDisabled(True) self.doubleSpinBox_fieldinclination.setDisabled(True) #Enable / Disable instrument parameters self.comboBox_array.setEnabled(True) self.doubleSpinBox_a.setEnabled(True) self.doubleSpinBox_a.setValue(0.5) self.doubleSpinBox_a.setSingleStep(0.5) self.doubleSpinBox_a1.setEnabled(True) self.doubleSpinBox_a1.setValue(10.0) self.doubleSpinBox_a1.setSingleStep(0.5) self.doubleSpinBox_a2.setEnabled(True) self.doubleSpinBox_a2.setValue(0.5) self.doubleSpinBox_a2.setSingleStep(0.1) self.doubleSpinBox_lowersensor.setDisabled(True) self.doubleSpinBox_uppersensor.setDisabled(True) self.doubleSpinBox_ylength.setDisabled(True) self.doubleSpinBox_ysample.setDisabled(True) #Enable / Disable Feature Parameters self.comboBox_conductivity.setEnabled(True) self.doubleSpinBox_depth.setEnabled(True) self.doubleSpinBox_depth.setValue(1.0) self.doubleSpinBox_depth.setSingleStep(0.1) self.doubleSpinBox_magsus.setDisabled(True) self.doubleSpinBox_length.setDisabled(True) self.doubleSpinBox_width.setDisabled(True) self.doubleSpinBox_strike.setDisabled(True) self.doubleSpinBox_depthextent.setDisabled(True) #Modifys ComboBox self.comboBox_array.clear() self.comboBox_array.addItems( ('TP Long', 'TP Broad', 'W Long', 'W Broad', 'SQ Alpha', 'SQ Beta', 'SQ Gamma')) def enable_3DRes(self): #Enable / Disable relevant survey Parameters self.doubleSpinBox_xlength.setEnabled( True) #Length of traverse (relative units) self.doubleSpinBox_xlength.setValue( 10.0 ) #Sets the default value for traverse length to be 10 (relative units) self.doubleSpinBox_xlength.setSingleStep(1.0) self.doubleSpinBox_xsample.setEnabled(True) self.doubleSpinBox_xsample.setValue(0.1) self.doubleSpinBox_xsample.setSingleStep(0.05) self.doubleSpinBox_ylength.setEnabled( True) #Length of traverse (relative units) self.doubleSpinBox_ylength.setValue( 10.0 ) #Sets the default value for traverse length to be 10 (relative units) self.doubleSpinBox_ylength.setSingleStep(1.0) self.doubleSpinBox_ysample.setEnabled(True) self.doubleSpinBox_ysample.setValue(0.1) self.doubleSpinBox_ysample.setSingleStep(0.05) self.doubleSpinBox_fieldinclination.setDisabled(True) #Enable / Disable instrument parameters self.comboBox_array.setEnabled(True) self.doubleSpinBox_a.setEnabled(True) self.doubleSpinBox_a1.setEnabled(True) self.doubleSpinBox_a2.setEnabled(True) self.doubleSpinBox_lowersensor.setDisabled(True) self.doubleSpinBox_uppersensor.setDisabled(True) #Enable / Disable Feature Parameters self.comboBox_conductivity.setEnabled(True) self.doubleSpinBox_depth.setEnabled(True) self.doubleSpinBox_depth.setSingleStep(0.5) self.doubleSpinBox_length.setEnabled(True) self.doubleSpinBox_length.setValue(1.0) self.doubleSpinBow_length.setSingleStep(0.5) self.doubleSpinBox_width.setEnabled(True) self.doubleSpinBox_width.setValue(1.0) self.doubleSpinBox_width.setValue(0.5) self.doubleSpinBox_depthextent.setEnabled(True) self.doubleSpinBox_depthextent.setValue(1.0) self.doubleSpinBox_SingleStep(0.5) self.doubleSpinBox_magsus.setDisabled(True) self.doubleSpinBox_strike.setDisabled(True) #Modifys ComboBox self.comboBox_array.clear() self.comboBox_array.addItems( ('TP Long', 'TP Broad', 'W Long', 'W Broad', 'SQ Alpha', 'SQ Beta', 'SQ Gamma', 'TZ Long', 'TZ Broad', 'TZ Theta')) def enable_3DMag(self): #Enable / Disable relevant survey Parameters self.doubleSpinBox_traverselength.setEnabled(True) self.doubleSpinBox_traverseint.setEnabled(True) self.doubleSpinBox_samplingint.setEnabled(True) self.doubleSpinBox_fieldinclination.setEnabled(True) #Enable / Disable instrument parameters self.comboBox_array.setEnabled(True) self.doubleSpinBox_lowersensor.setEnabled(True) self.doubleSpinBox_uppersensor.setEnabled(True) self.doubleSpinBox_a.setDisabled(True) self.doubleSpinBox_a1.setDisabled(True) self.doubleSpinBox_a2.setDisabled(True) #Enable / Disable Feature Parameters self.doubleSpinBox_depth.setEnabled(True) self.doubleSpinBox_length.setEnabled(True) self.doubleSpinBox_width.setEnabled(True) self.doubleSpinBox_depthextent.setEnabled(True) self.doubleSpinBox_magsus.setEnabled(True) self.doubleSpinBox_strike.setEnabled(True) self.comboBox_conductivity.setDisabled(True) #Modifys ComboBox self.comboBox_array.clear() self.comboBox_array.addItems( ('Vertical', 'Total', 'Horizontal X', 'Horizontal Y')) def enable_2DMag(self): #Enable / Disable relevant survey Parameters self.doubleSpinBox_traverselength.setEnabled(True) self.doubleSpinBox_traverseint.setEnabled(True) self.doubleSpinBox_samplingint.setEnabled(True) self.doubleSpinBox_fieldinclination.setEnabled(True) #Enable / Disable instrument parameters self.comboBox_array.setEnabled(True) self.doubleSpinBox_lowersensor.setEnabled(True) self.doubleSpinBox_uppersensor.setEnabled(True) self.doubleSpinBox_a.setDisabled(True) self.doubleSpinBox_a1.setDisabled(True) self.doubleSpinBox_a2.setDisabled(True) #Enable / Disable Feature Parameters self.doubleSpinBox_depth.setEnabled(True) self.doubleSpinBox_length.setEnabled(True) self.doubleSpinBox_width.setEnabled(True) self.doubleSpinBox_depthextent.setEnabled(True) self.doubleSpinBox_magsus.setEnabled(True) self.doubleSpinBox_strike.setEnabled(True) self.comboBox_conductivity.setDisabled(True) #Modifys ComboBox self.comboBox_array.clear() self.comboBox_array.addItems( ('Vertical', 'Total', 'Horizontal X', 'Horizontal Y')) def Warning_Dialog(self, title, text): message = QtGui.QMessageBox.warning(self, str(title), str(text)) def MagRes2D3Dtoggle(self): print 'Toggled' if self.radioButton_mag.isChecked(): if self.radioButton_2d.isChecked(): self.ClearPlot() self.enable_2DMag() else: self.ClearPlot() self.enable_3DMag() else: if self.radioButton_2d.isChecked(): self.ClearPlot() self.enable_2DRes() elif self.radioButton_3d.isChecked(): self.ClearPlot() self.enable_3DRes() else: self.ClearPlot() self.enable_2DRespseudo() print self.radioButton_mag.isChecked(), self.radioButton_res.isChecked( ) def CalculateFields(self): if self.radioButton_mag.isChecked(): if self.radioButton_2d.isChecked(): self.calculate_2DMag() else: self.calculate_3DMag() else: if self.radioButton_2d.isChecked(): self.calculate_2DRes() elif self.radioButton_3d.isChecked(): self.calculate_3DRes() else: self.calculate_2DRespseudo() def calculate_2DRes(self): #Assign user input to be run through 2DRes Algorithms array = [ 'tp_long', 'tp_broad', 'wenner_long', 'wenner_broad', 'square_a', 'square_b', 'square_g', 'trap_l', 'trap_b', 'trap_t' ][self.comboBox_array.currentIndex()] a = self.doubleSpinBox_a.value() a1 = self.doubleSpinBox_a1.value() a2 = self.doubleSpinBox_a2.value() #Create an array of x positions stop = self.doubleSpinBox_xlength.value() / 2.0 sample = self.doubleSpinBox_xsample.value() x = np.arange(-stop, stop + sample, sample) conductivity = [ 1.0e+6, 1.0e-6 ][self.comboBox_conductivity.currentIndex()] #Sphere Conductivity contrast = (conductivity - 1.0) / (1 + (2 * conductivity) ) #Contrast Factor z = self.doubleSpinBox_depth.value() #Sphere Depth output = res2D(array, a, a1, a2, x, contrast, z) #Send to res2D #Defines variables for saving self.x = x self.y = output self.header = "array, a, a1, a2, conductivity, z \n " + str( array) + ',' + str(a) + ',' + str(a1) + ',' + str(a2) + ',' + str( conductivity) + ',' + str(z) + "\n" self.xtitle = 'Relative Position (x)' self.ytitle = 'Relative Response' self.title = 'Resistivity Profile with ' + str(array) + ' over ' + str( conductivity) + ' ohm/m sphere.' self.plot_2d() def calculate_2DRespseudo(self): #Assign user input to be run through 2DRes Algorithms array = [ 'tp_long', 'tp_broad', 'wenner_long', 'wenner_broad', 'square_a', 'square_b', 'square_g' ][self.comboBox_array.currentIndex()] a = self.doubleSpinBox_a.value() a1 = self.doubleSpinBox_a1.value() a2 = self.doubleSpinBox_a2.value() array_range = np.arange(a, a1 + a2, a2) #Create an array of x positions stop = self.doubleSpinBox_xlength.value() / 2.0 sample = self.doubleSpinBox_xsample.value() x = np.arange(-stop, stop + sample, sample) conductivity = [ 1.0e+6, 1.0e-6 ][self.comboBox_conductivity.currentIndex()] #Sphere Conductivity contrast = (conductivity - 1.0) / (1 + (2 * conductivity) ) #Contrast Factor z = self.doubleSpinBox_depth.value() #Sphere Depth self.output = res2Dpseudo(array, array_range, x, contrast, z) self.xtitle = 'Relative Position (x)' self.ytitle = 'Relative Depth' self.title = 'Resistivity Pseudosection With ' + str( array) + ' Over ' + str(conductivity) + ' Ohm/m Sphere.' self.arrayrange = array_range #Defines variables for saving #self.x = x #self.y = output #self.header = "array, a, a1, a2, conductivity, z \n " + str(array) + ',' + str(a) + ',' + str(a1) + ',' + str(a2) + ',' + str(conductivity) + ',' + str(z) + "\n" self.plot_2dpseudo() def calculate_3DRes(self): #NOT YET IMPLEMENTED!!!! #Assign user input to be run through 3DRes Algorithms array = [ 'tp_long', 'tp_broad', 'wenner_long', 'wenner_broad', 'square_a', 'square_b', 'square_g', 'trap_l', 'trap_b', 'trap_t' ][self.comboBox_array.currentIndex()] a = self.doubleSpinBox_a.value() a1 = self.doubleSpinBox_a1.value() a2 = self.doubleSpinBox_a2.value() #Greate grid of x and y positions x_length = self.doubleSpinBox_xlength.value() x_step = self.doubleSpinBox_xsample.value() x_grid_pos = np.arange(np.divide(x_step, 2.0), x_length, x_step) y_length = self.doubleSpinBox_ylength.value() y_step = self.doubleSpinBox_ysample.value() y_grid_pos = np.arange(np.divide(y_step, 2.0), y_length, y_step) xgrid, ygrid = np.meshgrid(x_grid_pos, y_grid_pos) #Fill Bounding Box with Spheres conductivity = [1.0e+6, 1.0e-6][self.comboBox_conductivity.currentIndex()] contrast = (conductivity - 1.0) / (1 + (2 * conductivity)) z = self.doubleSpinBox_depth.value() #Depth to top of bounding box z1 = self.doubleSpinBox_depthextent.value( ) #Depth to bottom of bounding box #output = res2D(array, a, a1, a2, x, contrast, z) #Defines variables for saving #self.x = x #self.y = output #self.header = "array, a, a1, a2, conductivity, z \n " + str(array) + ',' + str(a) + ',' + str(a1) + ',' + str(a2) + ',' + str(conductivity) + ',' + str(z) + "\n" #self.xtitle = 'Relative Position (x)' #self.ytitle = 'Relative Response' #self.title = 'Resistivity Pseudosection with ' + str(array) + ' over ' + str(conductivity) + ' ohm/m sphere.' #self.plot_2d() def save_csv(self): fname = QtGui.QFileDialog.getSaveFileName(self, 'Save File', '*.csv') print fname, str(fname) output_text = np.column_stack((self.x, self.y)) np.savetxt(str(fname), output_text, fmt='%1.2f', delimiter=',', header=self.header) def copy_to_clipboard(self): pixmap = QtGui.QPixmap.grabWidget(self.mpl.canvas) QtGui.QApplication.clipboard().setPixmap(pixmap) def ClearPlot(self): self.mpl.canvas.ax.clear() self.mpl.canvas.draw() def plot_2d(self): self.mpl.canvas.ax.plot(self.x, self.y) self.mpl.canvas.ax.axis('auto') #self.mpl.canvas.ax.set_xlim(xmin=np.min(self.x), xmax=(np.max(self.x))) self.mpl.canvas.ax.set_ylim(ymin=np.min(self.y), ymax=(np.max(self.y))) self.mpl.canvas.ax.set_autoscale_on(True) self.mpl.canvas.ax.autoscale_view(True, True, True) self.mpl.canvas.ax.set_xlabel(self.xtitle, size=15) self.mpl.canvas.ax.set_ylabel(self.ytitle, size=15) self.mpl.canvas.ax.set_title(self.title, size=15) self.mpl.canvas.draw() def plot_2dpseudo(self): self.ClearPlot() temp = np.flipud(self.output) self.mpl.canvas.ax.imshow(temp, interpolation='none', cmap=plt.cm.Greys, aspect='auto', origin='upper') self.mpl.canvas.ax.set_xlabel(self.xtitle, size=15) self.mpl.canvas.ax.set_ylabel(self.ytitle, size=15) self.mpl.canvas.ax.set_title(self.title, size=15) self.cb = plt.colorbar(self.mpl.canvas.ax.imshow(self.output, cmap=plt.cm.Greys), ticks=self.arrayrange) #self.mpl.canvas.colorbar(self.mpl.canvas.ax.imshow(self.output,cmap=plt.cm.Greys), ticks=self.arrayrange) self.mpl.canvas.draw() def Button_Definitions(self): self.firstrun = True QtCore.QObject.connect(self.radioButton_mag, QtCore.SIGNAL("toggled(bool)"), self.MagRes2D3Dtoggle) QtCore.QObject.connect(self.radioButton_2d, QtCore.SIGNAL("toggled(bool)"), self.MagRes2D3Dtoggle) self.pushButton_plot.clicked.connect(self.CalculateFields) self.pushButton_clear.clicked.connect(self.ClearPlot) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+P"), self, self.CalculateFields) self.action_Save_Data.triggered.connect(self.save_csv) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+S"), self, self.save_csv) QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard) # Buttons in Toolbar #self.push_put_data.clicked.connect(self.put_cloud_data) #self.push_load_field.clicked.connect(self.load_field) #self.Push_cor_GNSS.clicked.connect(self.load_cloud_points) #self.Push_cor_GNSS.clicked.connect(self.Process_GNSS) #self.Push_display_barty_points.clicked.connect(self.calculate_barty_locs) # self.Push_Desample.clicked.connect(self.remove_collinears) # self.Push_Greyscale.clicked.connect(self.Grid_Data) # self.Push_ZMT.clicked.connect(self.ZMT) # self.Push_Calibrate.clicked.connect(self.calibrate) # self.Push_Despike.clicked.connect(self.Despike) # self.Push_Export.clicked.connect(self.import_NMEA) # Buttons in Menu # self.actionOpen_File.triggered.connect(self.data_SourceFile) # self.actionDisplay_GreyScale.triggered.connect(self.Grid_Data) #QtCore.QObject.connect(self.mplactionQuit, QtCore.SIGNAL('triggered()'), QtGui.qApp, QtCore.SLOT("quit()")) def __init__(self, parent=None): # initialization of the superclass super(ModellerMainWindow, self).__init__(parent) # setup the GUI --> function generated by pyuic4 self.setupUi(self) #Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self) #self.navi_toolbar.clear() # Add the x,y location widget at the right side of the toolbar # The stretch factor is 1 which means any resizing of the toolbar # will resize this label instead of the buttons. # self.navi_toolbar.locLabel = QtGui.QLabel( "", self ) # self.navi_toolbar.locLabel.setAlignment(QtCore.Qt.AlignLeft) # self.navi_toolbar.locLabel.setSizePolicy( # QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, # QtGui.QSizePolicy.Expanding)) # labelAction = self.navi_toolbar.addWidget(self.navi_toolbar.locLabel) # labelAction.setVisible(True) #Adds Buttons a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home', self.navi_toolbar.home) #a.setToolTip('returns axes to original position') a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan', self.navi_toolbar.pan) a.setToolTip('Pan axes with left mouse, zoom with right') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom', self.navi_toolbar.zoom) a.setToolTip('Zoom to Rectangle') a = self.navi_toolbar.addAction( self.navi_toolbar._icon('filesave.png'), 'Save', self.navi_toolbar.save_figure) a.setToolTip('Save the figure') #Button_layout is a QT desginer Grid Layout. self.toolbar_grid.addWidget(self.navi_toolbar) self.Button_Definitions() #Run Radio Toggle Code to grey / allow relevant options self.radioButton_2d.click() self.radioButton_res.click() self.MagRes2D3Dtoggle()