def paint_spectrogram(self): """ Function that paints the spectrogram within the main interface and links the interactivity with the main canvas. """ if (self.x1 <= 0) or (self.x2 >= len(self.active_trace.data)): gui_functions.msg_box( "No active window is selected", "Please, select one point the trace and drag along the time axis." ) else: if self.ax1 is not None: self.ax1.cla() self.figura_spectrograma.clf() signal = self.active_trace.data valor = np.asarray([self.x1, self.x2]) * self.fm chunkPlot = signal[int(valor[0]):int(valor[1])] self.ax1 = self.figura_spectrograma.add_subplot(111) self.ax1.cla() self.ax1.specgram(chunkPlot.flatten(), NFFT=128, Fs=self.fm, noverlap=64, cmap='jet') self.ax1.set_ylim(0, 30) self.canvas_specgram.draw()
def submit_current_window(self): """ This function is used to submit the current window to the segmentation table to store the segmented events in the datasets. """ # check which radio button is selected if self.current_label == "": gui_functions.msg_box("Can not submit if no label is selected", "Please, select one or change window.") else: # Get the current information from the data label = self.current_label alumni = self.comments.text() slider = self.qualityslider.value() start, end = str(round(self.x1, 2)), str(round(self.x2, 2)) peakAmpl = str(round(self.peak_to_peak(), 2)) duration = str(abs(float(end) - float(start))) # Check if is overlapping or not. if self.check_overlapping(round(self.x1, 2), round(self.x2, 2)): gui_functions.msg_box("Current window overlap previous one", "Please, move the sliding window.") else: currentRowCount = self.table_trace.rowCount() self.table_trace.insertRow(currentRowCount) self.table_trace.setItem(currentRowCount, 0, QtGui.QTableWidgetItem(start)) self.table_trace.setItem(currentRowCount, 1, QtGui.QTableWidgetItem(end)) self.table_trace.setItem(currentRowCount, 2, QtGui.QTableWidgetItem(label)) self.table_trace.setItem(currentRowCount, 3, QtGui.QTableWidgetItem(peakAmpl)) self.table_trace.setItem(currentRowCount, 4, QtGui.QTableWidgetItem(duration)) self.table_trace.setItem(currentRowCount, 5, QtGui.QTableWidgetItem(str(slider))) self.table_trace.setItem(currentRowCount, 6, QtGui.QTableWidgetItem(alumni)) # now we add the last xticks window self.first_ticked = start self.last_ticked = end # cleaning and redrawing traces. new_job = multiprocessing.Process(target=self.clean_figures(), args=()) new_job.start() redraw = multiprocessing.Process(target=self.redraw_trace(), args=()) redraw.start() time.sleep(2) gc.collect()
def submit_current_trace(self): """Function to save the segmented events in a pickle file. Notice that if no segmented events are selected, the data can not be saved. """ allRows = self.table_trace.rowCount() if self.ax is None or allRows is 0: gui_functions.msg_box("No current events are segmented", "Data can not be submitted") else: segmentation_table = [] segmentation_table.append((self.start_data, self.end_data)) for row in xrange(0, allRows): start_toSave = str(self.table_trace.item(row, 0).text()) end_toSave = str(self.table_trace.item(row, 1).text()) label_toSave = str(self.table_trace.item(row, 2).text()) peak_toSave = str(self.table_trace.item(row, 3).text()) duration_toSave = str(self.table_trace.item(row, 4).text()) slides_toSave = str(self.table_trace.item(row, 5).text()) alumni_toSave = str(self.table_trace.item(row, 6).text()) # Created the segmentation table new = [ start_toSave, end_toSave, label_toSave, peak_toSave, duration_toSave, slides_toSave, alumni_toSave ] segmentation_table.append(new) self.toSave = "%s_%s_%s_%s_%s_%s_%s" % ( self.network, self.station, self.channel, self.location, self.start_data.year, self.day_of_the_year, self.duration) self.segmentation_table = segmentation_table # Clean the figures to free memory and allow further plotting. self.clean_table() self.clean_figures() self.clean_points() self.figura_traza.clf() self.canvas_traza.draw() self.show_save_menu() gc.collect()
def paint_fft(self): """ This function computes the FFT of the selected signal and plot it on the selected space for it. """ if (self.x1 <= 0) or (self.x2 >= len(self.active_trace.data)): gui_functions.msg_box( "No active window is selected", "Please, select one point the trace and drag along the time axis." ) else: if self.ax2 is not None: self.ax2.cla() signal = self.active_trace.data value = np.asarray([self.x1, self.x2]) * self.fm selected = signal[int(value[0]):int(value[1])] # Check it with the masked arrays on some volcanoes. if np.ma.isMaskedArray(selected): xi = np.arange(len(selected)) mask = np.isfinite(selected) selected = np.interp(xi, xi[mask], selected[mask]) y, frq = picos_utils.compute_fft(selected, self.fm) self.ax2 = self.figura_fft.add_subplot(111) self.ax2.cla() self.ax2.set_xlabel('Freq (Hz)') if self.loglogaxis.isChecked(): self.ax2.set_ylabel('log(|Y(freq)|)') self.ax2.semilogy(frq[1:], np.abs(y)[1:], 'r') self.canvas_fft.draw() else: self.ax2.set_ylabel('|Y(freq)|') self.ax2.plot(frq[1:], abs(y)[1:], 'r') self.ax2.set_xlim(0, 20) self.canvas_fft.draw()