Ejemplo n.º 1
0
    def btnSubmitEvent(self):
        canceled, filename = save_dialog('CSV')
        if canceled:
            return

        self.csvNameBox.setText(filename)
        logging.info('Writing the output to %s' % filename)
        self.parent.inDialog()

        # initialize the progress bar
        progressBar = OutputProgressDialog()

        # do the calculations
        sampling_frequency = int(self.timeSampling.text())
        self.var_ID = self.firstVarBox.currentText().split('(')[0][:-1]
        self.second_var_ID = self.secondVarBox.currentText()
        if self.second_var_ID == '0':
            self.second_var_ID = None
        elif '(' in self.second_var_ID:
            self.second_var_ID = self.second_var_ID.split('(')[0][:-1]
        else:
            self.second_var_ID = VolumeCalculator.INIT_VALUE

        names = ['Polygon %d' % (i + 1) for i in range(len(self.polygons))]

        with Serafin.Read(self.data.filename,
                          self.data.language) as input_stream:
            input_stream.header = self.data.header
            input_stream.time = self.data.time
            if self.supVolumeBox.isChecked():
                calculator = VolumeCalculatorThread(
                    VolumeCalculator.POSITIVE, self.var_ID, self.second_var_ID,
                    input_stream, names, self.polygons, sampling_frequency,
                    self.mesh, self.parent.csv_separator, self.parent.digits)
            else:
                calculator = VolumeCalculatorThread(
                    VolumeCalculator.NET, self.var_ID, self.second_var_ID,
                    input_stream, names, self.polygons, sampling_frequency,
                    self.mesh, self.parent.csv_separator, self.parent.digits)

            progressBar.setValue(5)
            QApplication.processEvents()

            with open(filename, 'w') as f2:
                progressBar.connectToThread(calculator)
                calculator.write_csv(f2)

        if not calculator.canceled:
            progressBar.outputFinished()
        progressBar.exec_()
        self.parent.outDialog()

        if calculator.canceled:
            self.csvNameBox.clear()
            return

        # unlock the image viewer
        self.parent.imageTab.getData()
        self.parent.tab.setTabEnabled(1, True)
Ejemplo n.º 2
0
    def btnSubmitEvent(self):
        selected_var_IDs = self.getSelectedVariables()
        if not selected_var_IDs:
            QMessageBox.critical(
                self, 'Error',
                'Choose at least one output variable before submit!',
                QMessageBox.Ok)
            return

        canceled, filename = save_dialog('CSV')
        if canceled:
            return

        self.csvNameBox.setText(filename)
        logging.info('Writing the output to %s' % filename)
        self.parent.inDialog()

        indices_nonempty = [
            i for i in range(len(self.input.lines))
            if self.input.line_interpolators[i][0]
        ]
        reference = self.input.lines[
            int(self.referenceLine.currentText().split()[1]) - 1]
        time_index = int(self.timeSelection.index.text()) - 1

        # initialize the progress bar
        process = WriteCSVProcess(self.parent.csv_separator,
                                  self.parent.digits, self.input.mesh)
        progressBar = OutputProgressDialog()

        with Serafin.Read(self.input.data.filename,
                          self.input.data.language) as input_stream:
            input_stream.header = self.input.data.header
            input_stream.time = self.input.data.time

            progressBar.setValue(1)
            QApplication.processEvents()

            with open(filename, 'w') as output_stream:
                progressBar.connectToThread(process)

                if self.intersect.isChecked():
                    process.write_csv(input_stream, selected_var_IDs,
                                      output_stream,
                                      self.input.line_interpolators,
                                      indices_nonempty, reference, time_index)
                else:
                    process.write_csv(input_stream, selected_var_IDs,
                                      output_stream,
                                      self.input.line_interpolators_internal,
                                      indices_nonempty, reference, time_index)
        if not process.canceled:
            progressBar.outputFinished()
        progressBar.exec_()
        self.parent.outDialog()
        if process.canceled:
            self.csvNameBox.clear()
            return
Ejemplo n.º 3
0
    def btnSubmitEvent(self):
        canceled, filename = save_dialog('Serafin', self.data.filename)
        if canceled:
            return

        # fetch the list of selected variables
        selected_vars = self.inputTab.getSelectedVariables()

        # deduce header from selected variable IDs and write header
        output_header = self.getOutputHeader(selected_vars)

        # fetch the list of selected frames
        if self.timeSelection.manualSelection.hasData:
            output_time_indices = self.timeSelection.getManualTime()
            output_message = 'Writing the output with variables %s for %d frame%s between frame %d and %d.' \
                             % (str(output_header.var_IDs), len(output_time_indices),
                             ['', 's'][len(output_time_indices) > 1], output_time_indices[0]+1, output_time_indices[-1]+1)
        else:
            start_index, end_index, sampling_frequency, output_time_indices = self.timeSelection.getTime(
            )
            output_message = 'Writing the output with variables %s between frame %d and %d with sampling frequency %d.' \
                             % (str(output_header.var_IDs), start_index, end_index, sampling_frequency)

        self.parent.inDialog()
        progressBar = OutputProgressDialog()

        # do some calculations
        with Serafin.Read(self.data.filename,
                          self.data.language) as input_stream:
            # instead of re-reading the header and the time, just do a copy
            input_stream.header = self.data.header
            input_stream.time = self.data.time
            progressBar.setValue(5)
            QApplication.processEvents()

            with Serafin.Write(filename, self.data.language) as output_stream:
                logging.info(output_message)

                output_stream.write_header(output_header)

                # do some additional computations
                necessary_equations = get_necessary_equations(
                    self.data.header.var_IDs,
                    output_header.var_IDs,
                    is_2d=output_header.is_2d,
                    us_equation=self.data.us_equation)
                process = ExtractVariablesThread(necessary_equations,
                                                 self.data.us_equation,
                                                 input_stream, output_stream,
                                                 output_header,
                                                 output_time_indices)
                progressBar.connectToThread(process)
                process.run()

                if not process.canceled:
                    progressBar.outputFinished()
                progressBar.exec_()
                self.parent.outDialog()
Ejemplo n.º 4
0
    def btnSubmitEvent(self):
        selected_var_IDs = self.getSelectedVariables()

        if not selected_var_IDs:
            QMessageBox.critical(
                self, 'Error',
                'Choose at least one output variable before submit!',
                QMessageBox.Ok)
            return

        canceled, filename = save_dialog('CSV')
        if canceled:
            return

        self.csvNameBox.setText(filename)
        logging.info('Writing the output to %s' % filename)
        self.parent.inDialog()

        sampling_frequency = int(self.timeSampling.text())
        selected_time = self.data.time[::sampling_frequency]
        indices_inside = [
            i for i in range(len(self.points))
            if self.point_interpolators[i] is not None
        ]

        # initialize the progress bar
        process = WriteCSVProcess(self.parent.csv_separator,
                                  self.parent.digits, self.mesh)
        progressBar = OutputProgressDialog()

        with Serafin.Read(self.data.filename,
                          self.data.language) as input_stream:
            input_stream.header = self.data.header
            input_stream.time = self.data.time

            progressBar.setValue(1)
            QApplication.processEvents()

            with open(filename, 'w') as output_stream:
                progressBar.connectToThread(process)
                process.write_csv(
                    input_stream, selected_time, selected_var_IDs,
                    output_stream, indices_inside,
                    [self.points[i] for i in indices_inside],
                    [self.point_interpolators[i] for i in indices_inside])
        if not process.canceled:
            progressBar.outputFinished()
        progressBar.exec_()
        self.parent.outDialog()

        if process.canceled:
            self.csvNameBox.clear()
            return

        self.parent.imageTab.getData(selected_var_IDs, indices_inside)
        self.parent.tab.setTabEnabled(1, True)
Ejemplo n.º 5
0
    def btnSubmitEvent(self):
        if not self.conditions:
            QMessageBox.critical(self, 'Error', 'Add at least one condition.',
                                 QMessageBox.Ok)
            return

        start_index = int(self.timeSelection.startIndex.text()) - 1
        end_index = int(self.timeSelection.endIndex.text())
        time_indices = list(range(start_index, end_index))

        if len(time_indices) == 1:
            QMessageBox.critical(self, 'Error',
                                 'Start and end frame cannot be the same.',
                                 QMessageBox.Ok)
            return

        canceled, filename = save_dialog('Serafin', self.data.filename)
        if canceled:
            return

        # deduce header from selected variable IDs and write header
        output_header = self.getOutputHeader()
        output_message = 'Computing Arrival / Duration between frame %d and %d.' \
                          % (start_index+1, end_index)
        self.parent.inDialog()
        logging.info(output_message)
        progressBar = OutputProgressDialog()

        # do some calculations
        with Serafin.Read(self.data.filename,
                          self.data.language) as input_stream:
            input_stream.header = self.data.header
            input_stream.time = self.data.time

            progressBar.setValue(5)
            QApplication.processEvents()

            with Serafin.Write(filename, self.data.language) as output_stream:
                process = ArrivalDurationThread(input_stream, self.conditions,
                                                time_indices)
                progressBar.connectToThread(process)
                values = process.run()

                if not process.canceled:
                    values = self._convertTimeUnit(time_indices, values)
                    output_stream.write_header(output_header)
                    output_stream.write_entire_frame(output_header,
                                                     self.data.time[0], values)
                    progressBar.outputFinished()

        progressBar.exec_()
        self.parent.outDialog()
Ejemplo n.º 6
0
    def btnSubmitEvent(self):
        # fetch the list of selected variables
        selected_vars = self._getSelectedVariables()
        if not selected_vars:
            QMessageBox.critical(self, 'Error',
                                 'Select at least one variable.',
                                 QMessageBox.Ok)
            return

        canceled, filename = save_dialog('Serafin', self.data.filename)
        if canceled:
            return

        # deduce header from selected variable IDs and write header
        output_header = self.getOutputHeader(selected_vars)

        start_index = int(self.timeSelection.startIndex.text()) - 1
        end_index = int(self.timeSelection.endIndex.text())
        time_indices = list(range(start_index, end_index))
        var = self.varBox.currentText().split(' (')[0]

        output_message = 'Computing SynchMax of variables %s between frame %d and %d.' \
                          % (str(list(map(lambda x: x[0], selected_vars[1:]))), start_index+1, end_index)
        self.parent.inDialog()
        logging.info(output_message)
        progressBar = OutputProgressDialog()

        # do some calculations
        with Serafin.Read(self.data.filename,
                          self.data.language) as input_stream:
            input_stream.header = self.data.header
            input_stream.time = self.data.time

            progressBar.setValue(5)
            QApplication.processEvents()

            with Serafin.Write(filename, self.data.language) as output_stream:
                process = SynchMaxThread(input_stream, selected_vars[1:],
                                         time_indices, var)
                progressBar.connectToThread(process)
                values = process.run()

                if not process.canceled:
                    output_stream.write_header(output_header)
                    output_stream.write_entire_frame(output_header,
                                                     self.data.time[0], values)
                    progressBar.outputFinished()

        progressBar.exec_()
        self.parent.outDialog()
Ejemplo n.º 7
0
    def btnSubmitEvent(self):
        canceled, filename = save_dialog('CSV')
        if canceled:
            return
        self.csvNameBox.setText(filename)

        sampling_frequency = int(self.timeSampling.text())
        flux_type, self.var_IDs, flux_title = self._getFluxSection()
        self.parent.tab.setTabEnabled(1, False)

        logging.info('Writing the output to %s' % filename)
        self.parent.inDialog()

        # initialize the progress bar
        progressBar = OutputProgressDialog()

        # do the calculations
        names = ['Section %d' % (i+1) for i in range(len(self.polylines))]

        with Serafin.Read(self.data.filename, self.data.language) as input_stream:
            input_stream.header = self.data.header
            input_stream.time = self.data.time
            calculator = FluxCalculatorThread(flux_type, self.var_IDs,
                                              input_stream, names, self.polylines, sampling_frequency,
                                              self.mesh, self.parent.csv_separator, self.parent.digits)
            progressBar.setValue(5)
            QApplication.processEvents()

            with open(filename, 'w') as f2:
                progressBar.connectToThread(calculator)
                calculator.write_csv(f2)

        if not calculator.canceled:
            progressBar.outputFinished()
        progressBar.exec_()
        self.parent.outDialog()

        if calculator.canceled:
            self.csvNameBox.clear()
            return

        # unlock the image viewer
        self.parent.imageTab.getData(flux_title)
        self.parent.tab.setTabEnabled(1, True)
Ejemplo n.º 8
0
    def btnSubmitEvent(self):
        if self.secondTable.rowCount() == 0:
            QMessageBox.critical(
                self, 'Error',
                'Choose at least one output variable before submit!',
                QMessageBox.Ok)
            return

        canceled, filename = save_dialog('Serafin',
                                         input_names=[
                                             self.input.first_data.filename,
                                             self.input.second_data.filename
                                         ])
        if canceled:
            return

        # deduce header from selected variable IDs
        output_header = self._getOutputHeader()
        time_indices = self.input.common_frames
        operation_type = {
            0: operations.PROJECT,
            1: operations.DIFF,
            2: operations.REV_DIFF,
            3: operations.MAX_BETWEEN,
            4: operations.MIN_BETWEEN
        }[self.operationBox.currentIndex()]
        self.parent.inDialog()
        progressBar = OutputProgressDialog()

        # do some calculations
        with Serafin.Read(self.input.first_data.filename,
                          self.input.first_data.language) as first_in:
            first_in.header = self.input.first_data.header
            first_in.time = self.input.first_data.time

            with Serafin.Read(self.input.second_data.filename,
                              self.input.second_data.language) as second_in:
                second_in.header = self.input.second_data.header
                second_in.time = self.input.second_data.time

                progressBar.setValue(5)
                QApplication.processEvents()

                with Serafin.Write(
                        filename,
                        self.input.first_data.language) as out_stream:

                    out_stream.write_header(output_header)
                    process = ProjectMeshThread(first_in, second_in,
                                                out_stream, output_header,
                                                self.input.is_inside,
                                                self.input.point_interpolators,
                                                time_indices, operation_type)
                    progressBar.connectToThread(process)
                    process.run()

                    if not process.canceled:
                        progressBar.outputFinished()

        progressBar.exec_()
        self.parent.outDialog()
Ejemplo n.º 9
0
    def btnSubmitEvent(self):
        # fetch the list of selected variables
        selected_vars = self._getSelectedVariables()
        if not selected_vars:
            QMessageBox.critical(self, 'Error',
                                 'Select at least one variable.',
                                 QMessageBox.Ok)
            return

        canceled, filename = save_dialog('Serafin', self.data.filename)
        if canceled:
            return

        # separate scalars and vectors
        scalars, vectors, additional_equations = operations.scalars_vectors(
            self.data.header.var_IDs, selected_vars)

        # get the operation type
        if self.maxButton.isChecked():
            max_min_type = operations.MAX
        elif self.minButton.isChecked():
            max_min_type = operations.MIN
        else:
            max_min_type = operations.MEAN

        # deduce header from selected variable IDs and write header
        output_header = self.getOutputHeader(scalars, vectors)

        start_index = int(self.timeSelection.startIndex.text()) - 1
        end_index = int(self.timeSelection.endIndex.text())
        time_indices = list(range(start_index, end_index))

        output_message = 'Computing %s of variables %s between frame %d and %d.' \
                          % ('Max' if self.maxButton.isChecked() else ('Min' if self.minButton.isChecked() else 'Mean'),
                             str(output_header.var_IDs), start_index+1, end_index)
        self.parent.inDialog()
        logging.info(output_message)
        progressBar = OutputProgressDialog()

        # do some calculations
        with Serafin.Read(self.data.filename,
                          self.data.language) as input_stream:
            input_stream.header = self.data.header
            input_stream.time = self.data.time

            progressBar.setValue(5)
            QApplication.processEvents()

            with Serafin.Write(filename, self.data.language) as output_stream:
                process = MaxMinMeanThread(max_min_type, input_stream, scalars,
                                           vectors, time_indices,
                                           additional_equations)
                progressBar.connectToThread(process)
                values = process.run()

                if not process.canceled:
                    output_stream.write_header(output_header)
                    output_stream.write_entire_frame(output_header,
                                                     self.data.time[0], values)
                    progressBar.outputFinished()

        progressBar.exec_()
        self.parent.outDialog()