Ejemplo n.º 1
0
    def _figure(self):
        """
        Show the fitted model functions that are used to correct apply_data.
        """
        # create new figure and axes for adjusting the plateaus
        plot_params = {'lines.linewidth': 3.0}
        self._set_plot_params(plot_params)
        figure, ax_ = plt.subplots(1, 2, sharex=True, sharey=True)

        plottrace = self.modification.traces_apply
        ax = dict(list(zip(plottrace, ax_)))
        self._ax = ax

        # [ psdX, psdY ]
        traces = self.modification.traces_apply
        if 'psdZ' not in traces:
            traces.append('psdZ')
            traces.sort()

        # create lines to plot the corrections
        for trace in plottrace:
            ax[trace].plot([0], [0], c=tc.color(trace), marker='.', ls='')
            ax[trace].plot([0], [0], 'k-')
            ax[trace].plot([0], [0], 'y-', linewidth=3)
            ax[trace].legend(('fitdata', 'fit+extrapolation', 'fit'),
                             loc='best')
            ax[trace].set_xlabel(tc.label('psdZ'))
            ax[trace].set_ylabel(tc.label(trace))
            ax[trace].ticklabel_format(useOffset=False)
            ax[trace].grid(True)

        figure.suptitle("Crosstalk correction function for psdX and psdY from "
                        "psdZ.")

        return figure
Ejemplo n.º 2
0
    def _figure(self):
        # Create figure and axes to plot
        plot_params = {'wspace': 0.09, 'hspace': 0.1}
        self._set_plot_params(plot_params)
        fig, ax = plt.subplots(2, 2)
        ax = ax.flatten()

        # create lines to plot the data
        for i, trace in enumerate(self.modification.traces_apply):
            # original data
            ax[i].plot([0], [0], 'c')
            # corrected data
            ax[i].plot([0], [0], 'm')
            # plot the model
            ax[i].plot([0], [0], 'r')
            # datapoints, which were used to fit the model
            ax[i].plot([0], [0], 'r.', ms=3.5)

            ax[i].legend(('original', 'corrected', 'fit', 'fit points'),
                         loc='best')
            ax[i].set_xlabel("Time in (s)")
            ax[i].set_ylabel(tc.label(trace))
            ax[i].grid(True)

        fig.suptitle("Original and corrected data and datapoints used.")

        return fig
Ejemplo n.º 3
0
    def _figure(self):
        """
        Initialize and show an interactive plot for fitting the touchdown.
        Adjust the fit parameters interactively by displaying the fitted
        touchdown. The plot of the fitting is stored in self.figure.
        """
        # create new figure and axes for fitting the touchdown
        figure, ax = plt.subplots(1, 1, sharex=True, sharey=True)
        self._ax = ax

        # create lines to plot the data for the fit and for displaying fitting
        # result
        self._lines['orig_data'] = ax.plot([0], [0], tc.color('psdZ'))[0]
        self._lines['binned_data'] = ax.plot([0], [0], 'b.')[0]

        # cursor to display the "boundaries" for fitdata
        self._cursor = Cursor(ax, useblit=True, color='red', lw=1)

        # initialize all lines for the plot that represent the fit paramters
        # extrapolation of fit left
        self._lines['ext_left'] = ax.plot([0, 0], [0, 0], 'c', lw=1)[0]
        # extrapolation of fit right
        self._lines['ext_right'] = ax.plot([0, 0], [0, 0], 'c', lw=1)[0]
        # fit left
        self._lines['fit_left'] = ax.plot([0, 0], [0, 0], 'r', lw=3)[0]
        # fit right
        self._lines['fit_right'] = ax.plot([0, 0], [0, 0], 'g', lw=3)[0]
        # touchdown position
        self._lines['touchdown'] = ax.axvline(x=0.0, color='y', lw=2)
        # touchdown of bead, where positionZ equal to 0.0
        self._lines['touchdown_calib'] = ax.axvline(x=0.0, color='k', lw=2,
                                                    dashes=(10, 10))

        ax.set_xlabel(tc.label('positionZ'))
        ax.set_ylabel(tc.label('psdZ'))
        ax.ticklabel_format(useOffset=False)
        ax.grid(True)

        self.supertitle = figure.suptitle("Fit touchdown determination (move "
                                          "to upper and right/left limit, "
                                          "left/right click, repeat ...)")

        # method to update plot and perform the fit
        figure.canvas.mpl_connect('button_release_event',
                                  self._update_touchdown)

        return figure
Ejemplo n.º 4
0
    def __init__(self,
                 modify=None,
                 recalculate=None,
                 mod_params=None,
                 print_info=None,
                 **kwargs):
        # modify: function, that modifies the data
        # recalculate: function, which (in automatic mode) is called before
        #               _modify(). Can be used to automatically calculate
        #               mod_params, which are calculated with data obtained
        #               from view_based, i.e. data obtained by
        #               _get_data_based(). (Only called, if self.updated
        #               is False. Self.updated is set to False, upon any change
        #               of the view_based). The mod_params can be used by
        #               _modify().
        # kwargs:
        # traces_apply=None,
        # view_apply=None, # obligatory
        # view_based=None,
        # automatic_switch=False, Option to disable automatic call of
        #           _recalculate() before the call of _modify()
        # datapoints=-1, if>0 creates an iattribute, which is used for
        #                     decimate/average calculation in functions
        #                   _get_data(), _get_data_apply, and _get_data_based()
        #                  and binnumber determination in calculate_bin_means()

        if modify is None:
            raise TypeError("GenericMod missing required positional argument "
                            "`modify`.")

        # initialize _mod_params before call of super().__init__
        # to make sure __getattr__() doesn't end in a infinite
        # recursion loop
        self._mod_params = []

        super().__init__(**kwargs)

        # register widgets for modifications of traces
        for trace in self.traces_apply:
            self._mod_params.append(trace)
            key = self._key(trace)
            description = ''.join(('Parameter for trace ', tc.label(trace)))
            self.add_iattribute(key, description=description, value=0.0)

        if mod_params is not None:
            mod_params = hp.listify(mod_params)
            for name in mod_params:
                self._mod_params.append(name)
                key = self._key(name)
                description = ''.join(('Parameter ', name))
                self.add_iattribute(key, description=description, value=0.0)

        self._mod = unboundfunction(modify)

        if recalculate is not None:
            self._recalc = unboundfunction(recalculate)

        if print_info is not None:
            self._print_inf = unboundfunction(print_info)
Ejemplo n.º 5
0
    def _update_fig(self, **kwargs):
        """
        Update the plot
        """
        # recalculate the plateaus with the new offset and scaling values
        self.calculate_plateaus()

        # plot data
        self._lines['left'].set_data(self.leftposition, self.leftpsd)
        self._lines['right'].set_data(self.rightposition, self.rightpsd)
        excited_psd = self.modification.traces_apply[0]
        excited_position = self.modification.traces_apply[1]
        self._ax.set_xlabel(tc.label(excited_position))
        self._ax.set_ylabel(tc.label(excited_psd))

        # recompute ax.dataLim
        self._ax.relim()
        # update ax.viewLim using new dataLim
        self._ax.autoscale_view()
Ejemplo n.º 6
0
    def __init__(self, **kwargs):
        traces_apply = ['psdX', 'psdY', 'psdZ']
        super().__init__(automatic_switch=True,
                         traces_apply=traces_apply,
                         **kwargs)

        # register widgets for the offsets
        for trace in self.traces_apply:
            key = self._key(trace)
            description = ''.join(('Offset ', tc.label(trace)))
            self.add_iattribute(key, description=description, value=0.0)
Ejemplo n.º 7
0
 def _print_info(self):
     for trace in self.traces_apply:
         print("    %s coeffs: %s" %
               (tc.label(trace), self._model[self.lia(trace)].get_coeffs()))