def load(self, filename=None): """Opens a new document. Opens selected document in the current window if it isn't currently showing a document, otherwise the document is opened in a new window. Args: filename: Selected document. If None is provided launches a file dialog to let the user select a file. Default: None. """ if filename is None: filename, _ = QtGui.QFileDialog.getOpenFileName(self, "Open Data File", ".", ";;".join(self._file_filters), all_files_filter) if filename != '': dialog = loaddialog.LoadDialog(self, filename) return_code = dialog.exec_() if return_code == QtGui.QDialog.Accepted: try: values = dialog.get_values() # Load and visualize the opened record QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) self.analysis_label.setText("Loading {}...".format(os.path.basename(filename))) self.analysis_progress_bar.show() stream = rc.read(filename, **values) self.command_stack.push(commands.OpenStream(self, stream)) # Update recent list self.push_recent_list(filename) except Exception as e: error.display_error_dlg(str(e), traceback.format_exc()) finally: self.analysis_progress_bar.hide() self.analysis_label.setText("") QtGui.QApplication.restoreOverrideCursor()
def analysis_single_file_task(filename, **kwargs): """ :param file: :param kwargs: """ # Get debug level debug = kwargs.get('verbosity', 1) # Configure algorithm method = METHOD_MAP.get(kwargs.get('method', DEFAULT_METHOD), ampa.Ampa) alg = method(**kwargs) # Open input file if debug: print "*** Processing file {} ***".format(filename) input_format = INPUT_FORMAT_MAP.get(kwargs.get('input_format', DEFAULT_INPUT_FORMAT)) stream = rc.read(filename, format=input_format, **kwargs) if debug: print "Traces in {}".format(filename) print stream # Pick stream traces for trace in stream.traces: trace.detect(alg, debug=debug, **kwargs) # Export picks ouput_format = OUTPUT_FORMAT_MAP.get(kwargs.get('output_format', DEFAULT_OUTPUT_FORMAT)) extension = OUTPUT_EXTENSION_SET.get(ouput_format, '') basename, _ = os.path.splitext(os.path.basename(filename)) output_path = kwargs.get('destination_path', os.getcwd()) stream_suffix = '_'.join([suffix for tr in stream.traces for suffix in tr.getId().split('.') if suffix != '']) output_filename = "{}_{}{}".format(basename, stream_suffix, extension) stream.export_picks(os.path.join(output_path, output_filename), format=ouput_format, debug=debug)
def analysis_single_file_task(filename, **kwargs): """ :param file: :param kwargs: """ # Get debug level debug = kwargs.get('verbosity', 1) # Configure algorithm method = METHOD_MAP.get(kwargs.get('method', DEFAULT_METHOD), ampa.Ampa) alg = method(**kwargs) # Open input file if debug: print "*** Processing file {} ***".format(filename) input_format = INPUT_FORMAT_MAP.get( kwargs.get('input_format', DEFAULT_INPUT_FORMAT)) stream = rc.read(filename, format=input_format, **kwargs) if debug: print "Traces in {}".format(filename) print stream # Pick stream traces for trace in stream.traces: trace.detect(alg, debug=debug, **kwargs) # Export picks ouput_format = OUTPUT_FORMAT_MAP.get( kwargs.get('output_format', DEFAULT_OUTPUT_FORMAT)) extension = OUTPUT_EXTENSION_SET.get(ouput_format, '') basename, _ = os.path.splitext(os.path.basename(filename)) output_path = kwargs.get('destination_path', os.getcwd()) stream_suffix = '_'.join([ suffix for tr in stream.traces for suffix in tr.getId().split('.') if suffix != '' ]) output_filename = "{}_{}{}".format(basename, stream_suffix, extension) stream.export_picks(os.path.join(output_path, output_filename), format=ouput_format, debug=debug)
def load(self, filename=None): """Opens a new document. Opens selected document in the current window if it isn't currently showing a document, otherwise the document is opened in a new window. Args: filename: Selected document. If None is provided launches a file dialog to let the user select a file. Default: None. """ if filename is None: filename, _ = QtGui.QFileDialog.getOpenFileName( self, "Open Data File", ".", ";;".join(self._file_filters), all_files_filter) if filename != '': dialog = loaddialog.LoadDialog(self, filename) return_code = dialog.exec_() if return_code == QtGui.QDialog.Accepted: try: values = dialog.get_values() # Load and visualize the opened record QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) self.analysis_label.setText("Loading {}...".format( os.path.basename(filename))) self.analysis_progress_bar.show() stream = rc.read(filename, **values) self.command_stack.push(commands.OpenStream(self, stream)) # Update recent list self.push_recent_list(filename) except Exception as e: error.display_error_dlg(str(e), traceback.format_exc()) finally: self.analysis_progress_bar.hide() self.analysis_label.setText("") QtGui.QApplication.restoreOverrideCursor()