コード例 #1
0
 def set_visibility(self):
     row = self.get_data_row()
     for i, _ in enumerate(data_manager.get_growth_data_files()):
         if i != row:
             continue
         data_manager.get_growth_file(
             i).visible = not data_manager.get_growth_file(i).visible
コード例 #2
0
 def update_data_list(self):
     logger.debug('Updating the list of data files')
     self.data_list.clear()
     self.yaxis_dropdown.clear()
     self.legend_names.clear()
     for i, data in enumerate(data_manager.get_growth_data_files()):
         data_list_item = DataListItem(data.label, i, self)
         self.data_list.addItem(data_list_item.item)
         self.data_list.setItemWidget(data_list_item.item,
                                      data_list_item.widget)
         if data.legend:
             self.legend_names.addItem(data.legend)
         else:
             self.legend_names.addItem(data.label)
         if i > 0:
             continue
         contains_od = False
         contains_cd = False
         for sig in reversed(data.signals):
             self.yaxis_dropdown.addItem(sig.name)
             if sig.name == 'OD':
                 contains_od = True
             if sig.name == 'CD':
                 contains_cd = True
         if contains_od and not contains_cd and data_manager.calibration is not None:
             self.yaxis_dropdown.addItem('CD')
コード例 #3
0
 def create_events(self):
     # Show event information
     self.event_annotation = self.axes.annotate('',
                                                xy=(0, 0),
                                                xytext=(-20, 20),
                                                textcoords="offset points",
                                                bbox=dict(
                                                    boxstyle="round", fc="w"),
                                                arrowprops=dict(arrowstyle="->"))
     self.event_annotation.set_visible(False)
     self.annotation_names = []
     annotation_xpos = []
     annotation_ypos = []
     if config.show_events:
         for i, data in enumerate(data_manager.get_growth_data_files()):
             for data_event in data.events:
                 event_label = data_event.datetime.strftime(
                     '%d/%m/%Y %H:%M:%S')
                 for lab in data_event.labels:
                     event_label += '\n' + lab
                 self.annotation_names.append(event_label)
                 event_xpos = data_event.get_xpos(config.xvar)
                 annotation_xpos.append(event_xpos)
                 x_idx = np.abs(self.xdata_list[i] - event_xpos).argmin()
                 event_ypos = self.ydata_list[i][x_idx]
                 annotation_ypos.append(event_ypos)
         self.event_scatter = self.axes.scatter(annotation_xpos,
                                                annotation_ypos,
                                                s=10,
                                                c='black')
     return
コード例 #4
0
    def export(self):
        path = self.test_path
        if self.test_path == 'none':
            path = get_save_directory_name()
        logger.info('Exporting files to %s' % path)
        for data in data_manager.get_growth_data_files():
            filename = data.label + '.csv'
            if self.rename.isChecked():
                filename = path + '/' + data.profile + '_ada.csv'
            else:
                filename = path + '/' + \
                    filename.split('/')[-1].split('.')[0] + '_ada.csv'
            logger.debug('Exporting file %s' % filename)

            # Get the condition data if that option is checked
            conditions = None
            if self.conditions.isChecked():
                for cond_data in data_manager.get_condition_data_files():
                    if data.reactor != cond_data.reactor:
                        continue
                    if data.date != cond_data.date:
                        continue
                    if data.time != cond_data.time:
                        continue
                    conditions = cond_data

            with open(filename, 'w', newline='') as csvfile:
                writer = csv.writer(csvfile)
                name_header = [
                    'Name', data.label, 'Title', data.title, 'Reactor',
                    data.reactor, 'Profile', data.profile
                ]
                writer.writerow(name_header)
                date_header = ['Date', data.date, 'Time', data.time]
                writer.writerow(date_header)
                measurement_header = [
                    data.xaxis.name + ' [' + data.xaxis.unit + ']'
                ]
                for sig in data.signals:
                    measurement_header.append(sig.name + ' [' + sig.unit + ']')
                if conditions is not None:
                    measurement_header.append('Conditions')
                    for sig in conditions.signals:
                        measurement_header.append(sig.name + ' [' + sig.unit +
                                                  ']')
                writer.writerow(measurement_header)
                for i, xdat in enumerate(data.xaxis.data):
                    row = [xdat]
                    for sig in data.signals:
                        row.append(sig.data[i])
                    # Find closest signal time
                    if conditions is not None:
                        row.append('')
                        cond_ind = (np.abs(conditions.xaxis.data -
                                           xdat)).argmin()
                        for sig in conditions.signals:
                            row.append(sig.data[cond_ind])
                    writer.writerow(row)
        self.close()
コード例 #5
0
 def remove_item(self):
     row = self.get_data_row()
     logger.debug('Removing data list item %i' % row)
     for i, _ in enumerate(data_manager.get_growth_data_files()):
         if i != row:
             continue
         data_manager.growth_data.delete_data(i)
     self.update_data_list()
コード例 #6
0
 def remove_replicate(self, index):
     row = self.get_data_row()
     logger.debug('Removing replicate %i from data list item %i' %
                  (index, row))
     for i, _ in enumerate(data_manager.get_growth_data_files()):
         if i != row:
             continue
         data_manager.growth_data.delete_replicate(i, index)
     self.update_data_list()
コード例 #7
0
 def test(self):
     config.do_fit = True
     test_option = self.test_option.currentText()
     measurement_option = self.test_measurement.currentText()
     # Calculate value of all replicates individually
     measurements = []
     for i, dat in enumerate(data_manager.get_growth_data_files()):
         if test_option == 'T-test':
             data1 = self.data_option1.currentText(error=True)
             data2 = self.data_option2.currentText(error=True)
             if data1 == data2:
                 raise RuntimeError('Samples must be different')
             if dat.label != data1 and dat.label != data2:
                 continue
         signal = self.signal.currentText()
         if measurement_option == 'gradient':
             grad_from = self.grad_from.get_float(error=True)
             grad_to = self.grad_to.get_float(error=True)
             measurements.append(data_manager.get_replicate_gradients(
                 i, signal, grad_from, grad_to))
         elif measurement_option == 'time to':
             time_to = self.time_to.get_float(error=True)
             measurements.append(
                 data_manager.get_replicate_time_to(i, signal, time_to))
         elif measurement_option == 'fit parameter':
             fit_name = self.fit.currentText(error=True)
             fit_from = self.fit_from.get_float(error=True)
             fit_to = self.fit_to.get_float(error=True)
             fit_param = self.param.currentText(error=True)
             measurements.append(data_manager.get_replicate_fits(
                 i, signal, fit_name, fit_from, fit_to, fit_param))
         else:
             raise RuntimeError('Unknown measurement')
     # Calculate test result
     statistic, pvalue = -1, -1
     if test_option == 'T-test':
         if len(measurements) != 2:
             raise RuntimeError('Unable to find data for t-test')
         statistic, pvalue = ttest_ind(measurements[0], measurements[1])
     if test_option == 'ANOVA':
         statistic, pvalue = f_oneway(*measurements)
     # Display test result
     self.statistic.setText('Statistic = ' + str(statistic))
     self.pvalue.setText('P value = ' + str(pvalue))
コード例 #8
0
    def fit_data(self):
        logger.debug('Fitting %s with %s' %
                     (config.fit_curve, config.fit_type))
        # Find the curve to fit
        fit_index = -1
        for i, dat in enumerate(data_manager.get_growth_data_files()):
            if config.fit_curve == dat.label:
                fit_index = i
        # If the data hasn't been found
        if fit_index == -1:
            return

        fit_x, _, _ = data_manager.get_fit_data(fit_index)
        x_unit, y_unit = data_manager.get_units(fit_index)

        model = get_model(config.fit_type, x_unit, y_unit)
        func = model.func()

        fit_result, covm = data_manager.get_fit(fit_index)
        self.axes.plot(fit_x, func(fit_x, *fit_result),
                       '-', color='r', label='Fit')

        bounding_box = dict(boxstyle="round", ec=(
            1., 0.5, 0.5), fc=(1., 0.8, 0.8))
        if config.show_fit_text:
            self.axes.text(0.25, 0.95, model.latex,
                           transform=self.axes.transAxes,
                           bbox=bounding_box, picker=True)

        if config.show_fit_result and not config.show_fit_errors:
            self.axes.text(0.25, 0.65, model.param_text(fit_result),
                           transform=self.axes.transAxes,
                           bbox=bounding_box, picker=True)

        if config.show_fit_result and config.show_fit_errors:
            self.axes.text(0.25, 0.65, model.param_text_error(fit_result, covm),
                           transform=self.axes.transAxes,
                           bbox=bounding_box, picker=True)

        return
コード例 #9
0
    def update_plot(self):
        self.parent.update_config()
        logger.debug('Updating the correlation plot')
        self.plot_config.clear()
        # Process the data here
        x_data, x_error = data_manager.get_averages(
            self.condition.currentText(), self.start_t.get_float(),
            self.end_t.get_float())
        y_data, y_error = data_manager.get_all_fit_params(
            self.data.currentText(), self.fit.currentText(),
            self.start_t.get_float(), self.end_t.get_float(),
            self.param.currentText())
        tunit = 's'
        if config.xvar == 'minutes':
            tunit = 'min'
        if config.xvar == 'hours':
            tunit = 'hr'
        if config.xvar == 'days':
            tunit = 'day'

        # Create the X axis title
        x_title = self.x_title.text()
        if x_title == '':
            condition_unit = data_manager.get_condition_unit(
                self.condition.currentText())
            x_title = ('Average %s [%s]' %
                       (self.condition.currentText(), condition_unit))
        self.plot_config.x_title = x_title

        # Create the Y axis title
        y_title = self.y_title.text()
        if y_title == '':
            data_unit = data_manager.get_growth_unit(self.data.currentText())
            model = get_model(self.fit.currentText(), tunit, data_unit)
            y_title = ('%s [%s] (%s)' %
                       (model.get_latex_param(self.param.currentText()),
                        model.get_units(self.param.currentText()),
                        self.data.currentText()))
        self.plot_config.y_title = y_title

        self.plot_config.title = self.figure_title.text()
        labels = []
        for dat in data_manager.get_growth_data_files():
            labels.append('Name: %s\nReactor: %s\nProfile: %s' %
                          (dat.label, dat.reactor, dat.profile))

        # Remove any broken fits
        for i, yerr in enumerate(y_error):
            logger.debug('Fit %i: x=%.2f (%.2f), y=%.2f (%.2f)' %
                         (i, x_data[i], x_error[i], y_data[i], y_error[i]))
            if y_data[i] == 1 and yerr > 50:
                logger.warning('Fit ' + str(i) + ' failed')
            else:
                self.plot_config.x_data.append(x_data[i])
                self.plot_config.y_data.append(y_data[i])
                self.plot_config.x_error.append(x_error[i])
                self.plot_config.y_error.append(y_error[i])
                if self.label.isChecked():
                    self.plot_config.labels.append(labels[i])

        # Work out correlation coefficient
        if self.calc_correlation.isChecked():
            corr_coef = np.corrcoef(self.plot_config.x_data,
                                    self.plot_config.y_data)
            self.plot_config.correlation_coeff = corr_coef[1][0]
        else:
            self.plot_config.correlation_coeff = None

        self.plot.plot(self.plot_config)