예제 #1
0
    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()
예제 #2
0
    def add_worker(self, graph_ty, work_object):
        id = self.cur_work_id
        self.cur_work_id += 1
        worker = HapiWorker(GraphDisplayWidget.graph_ty_to_work_ty[graph_ty], work_object,
                            lambda x: (self.plot(x), self.workers.pop(id)))

        self.workers[id] = worker
        worker.start()
예제 #3
0
    def __on_data_name_changed(self, new_table):
        """
        Disables all graph buttons. (Inner method callback : enables graph buttons if necessary
        params to graph are supplied.)
        """
        self.set_graph_buttons_enabled(False)
        self.same_window_checked = self.use_existing_window.isChecked()

        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)

        self.broadener_input.set_table(new_table)

        worker = HapiWorker(WorkRequest.TABLE_META_DATA,
                            {'table_name': new_table}, callback)
        self.workers.append(worker)
        worker.start()
예제 #4
0
    def __on_select_table_name_selection_changed(self, new_selection):
        """
        When the table that is being worked with changes, update the parameter list.
        """
        self.run_button.setDisabled(True)
        if new_selection == '':
            return

        args = HapiWorker.echo(table_name=new_selection)

        worker = HapiWorker(WorkRequest.TABLE_META_DATA, args,
                            self.__on_select_table_name_complete)
        worker.start()
        self.parent.workers.append(worker)
예제 #5
0
class CrossSectionFetchWidget(QWidget):

    CROSS_SECTION_FETCH_WIDGET_INSTANCE = None

    @staticmethod
    def gen_toggle_function(other_widgets: List[QWidget]):
        return lambda checked: list(
            map(lambda widget: widget.setDisabled(not checked), other_widgets))

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        if CrossSectionFetchWidget.CROSS_SECTION_FETCH_WIDGET_INSTANCE is not None:
            raise Exception(
                "No more than one instance of CrossSectionFetchWidget"
                " should be created")
        CrossSectionFetchWidget.CROSS_SECTION_FETCH_WIDGET_INSTANCE = self

        self.all_molecules = MoleculeMeta.all_names()

        self.parent = parent

        self.wn_check: QCheckBox = None
        self.numin: QDoubleSpinBox = None
        self.numax: QDoubleSpinBox = None

        self.pressure_check: QCheckBox = None
        self.pressure_min: QDoubleSpinBox = None
        self.pressure_max: QDoubleSpinBox = None

        self.temp_check: QCheckBox = None
        self.temp_min: QDoubleSpinBox = None
        self.temp_max: QDoubleSpinBox = None

        self.molecule: QComboBox = None
        self.cross_section_list: QListWidget = None

        self.fetch_button: QPushButton = None
        self.apply_filters: QPushButton = None

        self.cross_section_meta: CrossSectionMeta = None

        self.fetching = False

        uic.loadUi('layouts/cross_section_widget.ui', self)

        self.pressure_check.toggled.connect(
            self.gen_toggle_function([self.pressure_max, self.pressure_min]))
        self.temp_check.toggled.connect(
            self.gen_toggle_function([self.temp_max, self.temp_min]))
        self.wn_check.toggled.connect(
            self.gen_toggle_function([self.numax, self.numin]))

        self.pressure_check.setChecked(True)
        self.temp_check.setChecked(True)
        self.wn_check.setChecked(True)

        self.temp_check.toggle()
        self.wn_check.toggle()
        self.pressure_check.toggle()

        self.fetch_button.clicked.connect(self.__on_fetch_clicked)
        self.apply_filters.clicked.connect(self.__on_apply_filters_clicked)
        self.molecule.addItems(
            CrossSectionMeta.all_names_sorted_by_hitran_id())
        self.molecule.setEditable(True)
        self.completer: QCompleter = QCompleter(CrossSectionMeta.all_aliases(),
                                                self)
        self.completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
        self.molecule.setCompleter(self.completer)

        self.molecule.currentTextChanged.connect(
            self.__on_molecule_selection_changed)
        self.__on_molecule_selection_changed(self.molecule.currentText())

    def get_selected_xscs(self) -> List[str]:
        xscs = []
        for i in range(self.cross_section_list.count()):
            item = self.cross_section_list.item(i)

            if item.checkState() == QtCore.Qt.Checked:
                xscs.append(str(item.text()))
        return xscs

    def __on_apply_filters_clicked(self, _checked: bool):
        if self.pressure_check.isChecked():
            pressure = [self.pressure_min.value(), self.pressure_max.value()]
            pressure.sort()
        else:
            pressure = None

        if self.wn_check.isChecked():
            wn = [self.numin.value(), self.numax.value()]
            wn.sort()
        else:
            wn = None

        if self.temp_check.isChecked():
            temp = [self.temp_min.value(), self.temp_max.value()]
            temp.sort()
        else:
            temp = None

        xsc_filter = CrossSectionFilter(self.get_selected_molecule_id(), wn,
                                        pressure, temp)
        self.set_cross_section_list_items(xsc_filter.get_cross_sections())

    def __on_molecule_selection_changed(self, _current_text: str):
        mid = self.get_selected_molecule_id()
        if mid is None:
            return

        self.cross_section_meta = CrossSectionMeta(mid)
        items = self.cross_section_meta.get_all_filenames()
        self.set_cross_section_list_items(items)

        if self.fetching:
            return

        if len(items) == 0:
            self.fetch_button.setDisabled(True)
        else:
            self.fetch_button.setEnabled(True)

    def __on_fetch_clicked(self, _checked: bool):
        xscs = self.get_selected_xscs()
        if len(xscs) == 0:
            return
        args = HapiWorker.echo(xscs=xscs,
                               molecule_name=self.molecule.currentText())
        self.fetch_button.setDisabled(True)
        self.worker = HapiWorker(WorkRequest.DOWNLOAD_XSCS, args,
                                 self.__on_fetch_xsc_done)
        self.worker.start()

    def __on_fetch_xsc_done(self, res):
        _result = res.result
        if _result is None:
            err_log("Failed to fetch cross sections...")
        self.parent.populate_table_lists()
        self.fetching = False
        self.fetch_button.setEnabled(True)

    def get_selected_molecule_id(self) -> Optional[int]:
        selected_molecule_name = self.molecule.currentText()
        mid = MoleculeMeta(selected_molecule_name)
        if mid.populated:
            return mid.id
        else:
            return None

    def set_cross_section_list_items(self, xscs: List[str]):
        list(
            map(lambda _: self.cross_section_list.takeItem(0),
                range(self.cross_section_list.count())))
        for xsc in xscs:
            item = QtWidgets.QListWidgetItem(xsc)
            item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable
                          | QtCore.Qt.ItemIsEnabled)

            item.setCheckState(QtCore.Qt.Unchecked)

            self.cross_section_list.addItem(item)