def __on_select_table_name_complete(self, work_result): """ Removes worker thread, returns results or handles error if no result is returned. """ self.parent.remove_worker_by_jid(work_result.job_id) result = work_result.result if not result: err_log( "Something went wrong while requesting meta-data on a table..." ) return parameters = result['parameters'] self.parameter_list.clear() for par in parameters: item = QtWidgets.QListWidgetItem(par) item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) item.setCheckState(QtCore.Qt.Unchecked) self.parameter_list.addItem(item) self.run_button.setEnabled(True) # Check for errors.. self.__on_output_name_change()
def __init__(self, molecule_id): """ :param molecule_id: HITRAN MoleculeId of the molecule to retrieve xsc meta data for the specified molecule. """ if len(CrossSectionMeta.__MOLECULE_METAS) == 0: self.molecule_id = molecule_id self.metas = [] self.api = CrossSectionApi() self.cache = JsonCache(".xscm", self.api.request_xsc_meta, timedelta(days=1.0)) if not self.cache.ok(): err_log("Failed to load xscm from cache.") else: xsc_meta_objects = self.cache.data() CrossSectionMeta.add_meta_objects(xsc_meta_objects) CrossSectionMeta.create_alias_list(xsc_meta_objects) CrossSectionMeta.create_name_list(xsc_meta_objects) if self.molecule_id in CrossSectionMeta.__MOLECULE_METAS: self.metas = CrossSectionMeta.__MOLECULE_METAS[ self.molecule_id] else: self.molecule_id = molecule_id if molecule_id in CrossSectionMeta.__MOLECULE_METAS: self.metas = CrossSectionMeta.__MOLECULE_METAS[molecule_id] else: self.metas = ()
def __on_run_button_click(self): """ Creates a HapiWorker to run the Select query. """ selected_params = self.get_select_parameters() table_name = self.get_select_table_name() new_table_name = self.get_output_table_name() expression = self.get_select_expression() parsed_expression = DSL.parse_expression(expression) if parsed_expression == None and expression.strip() != '': err_log('Invalid select expression.') return if table_name == new_table_name: err_log( 'Cannot have select output table be the same as the input table' ) return self.run_button.setDisabled(True) args = HapiWorker.echo(ParameterNames=selected_params, TableName=table_name, DestinationTableName=new_table_name, Conditions=parsed_expression) worker = HapiWorker(WorkRequest.SELECT, args, self.__on_run_done) self.parent.workers.append(worker) worker.start()
def populate_data_names(self): """ Retrieve data file names from users data folder for display in the Graphing Window. """ try: list( map(lambda name: self.data_name.addItem(name), get_all_data_names())) except Exception as e: err_log("Failed to populate data names, encountered error \'{}\'". format(str(e)))
def __on_output_name_change(self): """ """ try: output_name = self.output_name.text() if output_name.strip() == '': self.run_button.setDisabled(True) err_log('Select output table cannot be empty') else: self.run_button.setEnabled(True) except Exception as e: debug('fug: ' + str(e))
def __on_run_done(self, work_result): """ Handles user feedback on success or failure of select function. """ self.run_button.setEnabled(True) self.parent.remove_worker_by_jid(work_result.job_id) result = work_result.result if not result: err_log('Error running select..') return try: if 'all_tables' in result: all_tables = result['all_tables'] self.parent.populate_table_lists(all_tables) else: text = 'Error running select: \'' + str(result) + '\'' err_log(text) # if self.table: # self.table.close_table() # self.table.close() # QWidget().setLayout(self.table_container.layout()) # # self.table = HapiTableView(self, new_table_name) # layout = QtWidgets.QGridLayout(self.table_container) # layout.addWidget(self.table) # self.table_container.setLayout(layout) log('Select successfully ran.') except Exception as e: err_log('Error running select.') debug(e)
def callback(work_result): self.remove_worker_by_jid(work_result.job_id) result = work_result.result if result is None: return self.plot_name.setText(self.data_name.currentText()) if 'parameters' not in result: self.set_graph_buttons_enabled(True) return if not result['xsc']: for param in GraphingWidget.parameters_required_to_graph: if param not in result['parameters']: err_log('Table does not contain required parameters.') return self.numin.setValue(result['numin']) self.numax.setValue(result['numax']) self.set_graph_buttons_enabled(True) # Cross sections can only be graphed as cross sections if result['xsc'] is not None: self.set_xsc_mode(True) self.graph_type.clear() self.graph_type.addItems([GraphingWidget.XSC_STRING]) else: # Normal tables can be graphed as anything other than a cross section self.set_xsc_mode(False) self.graph_type.clear() graph_types = list(GraphingWidget.str_to_graph_ty.keys()) graph_types.remove(GraphingWidget.XSC_STRING) self.graph_type.addItems( list(GraphingWidget.str_to_graph_ty.keys())) self.xsc = result['xsc'] self.use_existing_window.setChecked(self.same_window_checked)
def __load_from_file(self) -> bool: """ Attempts to load the cache from a file. If the containing directories don't exist they're created, and then the __load_from_web function will be called. :return: Returns False if the function failed to load the file. This either means it doesn't exist or something weird happened """ import os.path path, _ = os.path.split(self.path) try: os.makedirs(path) except OSError as e: if e.errno != errno.EEXIST: print( "Encountered unrecoverable exception in utils.cache.py: __load_from_file" ) return False if os.path.exists(self.path) and os.path.isfile(self.path): try: with open(self.path, 'r') as file: text = file.read( ) # This reads whole contents of the file. parsed = json.loads(text) # This means the lifetime of the cache has expired (parsed['timestamp'] contains # the unix timestamp of when the file was written added to the number of seconds # before expiration). if int(time.time()) > parsed['timestamp']: return False self.cached = parsed['cached'] except Exception as e: err_log("Encountered exception '{}'".format(str(e))) return False else: return False return True
def graph_ts(self, standard_params): path_length = self.get_path_length() instrumental_fn = self.get_instrumental_fn() AF_wing = self.get_instrumental_fn_wing() Resolution = self.get_instrumental_resolution() if standard_params['WavenumberStep'] == None: standard_params['WavenumberStep'] = Resolution / 2 elif standard_params['WavenumberStep'] <= Resolution: err_log( 'Wavenumber Step must be less than Instrumental Resolution') self.data_name_error.setText( '<span style="color:#aa0000;">' + 'Wavenumber Step must be less than the ' 'Instrumental Resolution' + '</span>') self.done_graphing() return work = HapiWorker.echo( title=GraphingWidget.TRANSMITTANCE_SPECTRUM_STRING, titlex="Wavenumber (cm$^{-1}$)", titley="Transmittance", path_length=path_length, instrumental_fn=instrumental_fn, Resolution=Resolution, AF_wing=AF_wing, **standard_params) if self.use_existing_window.isChecked(): selected_window = self.get_selected_window() if selected_window in GraphDisplayWidget.graph_windows: GraphDisplayWidget.graph_windows[selected_window].add_worker( GraphType.TRANSMITTANCE_SPECTRUM, work) return GraphDisplayWidget(GraphType.TRANSMITTANCE_SPECTRUM, work, self.backend.currentText()) self.update_existing_window_items()