Ejemplo n.º 1
0
    def plot_batch_profile(self, average=False, confidence=0.95, 
        xlim=None, ylim=None, title=None, show=False, save=False, 
        savename=None, imagetype='png'):
        '''
        Plots multiple profiles on same plot
        '''

        font = {'family': 'Arial', 'size': 20}
        matplotlib.rc('font', **font)

        coloridx = np.linspace(0,1,10) # for use with tab10 colormap
        fig, ax = plt.subplots(figsize=(16,9), dpi=75)

        if average:
            data = [(self.lines[line]['x'], self.lines[line]['height']) \
                for line in self.lines]

            x, mean, std, lcl, ucl = utilities.batch_average_plot(data=data)

            for line in self.lines:
                ax.plot(self.lines[line]['x'], self.lines[line]['height'],
                    linewidth=3, color='k', alpha=0.2)

            ax.plot(x, mean, linewidth=3, color='r', label='mean')
            ax.plot(x, ucl, color='r', linewidth=3, linestyle='--',)
            ax.plot(x, lcl, color='r', linewidth=3, linestyle='--', 
                label=str(confidence)[2:]+'% Confidence Interval (t-test)')

        else:
            rous, wavs, pa = [], [], []

            for idx in self.lines:
                rous.append(self.metrics[idx]['R']['Rq'])
                wavs.append(self.metrics[idx]['W']['Wq'])
                pa.append(self.metrics[idx]['P']['Pa'])

                start = self.idxs[idx][0]
                end = self.idxs[idx][1]

                isolatedtrace = self.lines[idx]['x'][start:end]*0.001 - \
                    self.lines[idx]['x'][start]*0.001

                ax.plot(
                    isolatedtrace, 
                    self.lines[idx]['height'][start:end],
                    linewidth=2, 
                    color=plt.cm.tab10(coloridx[int(idx[1:])-1]), 
                    label=str(idx)
                )

            mean_r = np.mean(rous)
            mean_w = np.mean(wavs)
            mean_a = np.mean(pa)

            stats = {
                'r': r'$R_q = $'+'%.3f µm'%mean_r,
                'w': r'$W_q = $'+'%.3f µm'%mean_w,
                'a': r'$P_a = $'+'%.3f µm'%mean_a,
            }

            stats_text = stats['r']+'\n'+stats['w']+'\n'+stats['a']

            x_tlim, y_tlim = ax.get_xlim(), ax.get_ylim()

            x_tpos = 0.05*(x_tlim[1]-x_tlim[0]) + x_tlim[0]
            y_tpos = 0.80*(y_tlim[1]-y_tlim[0]) + y_tlim[0]

            ax.text(x_tpos, y_tpos, stats_text, bbox=dict(facecolor='w', 
                edgecolor='k'))

        ax.set_xlabel('Horizontal Position [mm]')
        ax.set_ylabel('Height [µm]')
        ax.legend(loc='upper right')
        ax.grid()

        if xlim:
            ax.set_xlim(xlim)
        if ylim:
            ax.set_ylim(ylim)

        if title:
            ax.set_title(title)
        else:
            ax.set_title(self.title)

        if save:
            if savename:
                plt.savefig(savename + '.' + imagetype)
            else:
                plt.savefig('batch_' + self.title + '.' + imagetype)

        if show:
            plt.show()

        plt.close(fig)
Ejemplo n.º 2
0
    def plot_batch_vis_shearstress(self,
                                   average=False,
                                   confidence=None,
                                   xlim=None,
                                   ylim=None,
                                   title=None,
                                   show=False,
                                   save=False,
                                   savename=None,
                                   imagetype='png'):
        ''' Plots multiple profiles on same plot
            Possible choices for both x and y are
            'step', 'point', 'time', 'viscosity', 'torque', 'speed', 
            'shearstress', 'shearrate', 'temperature', 'density', 'accuracy', 
        '''

        font = {'family': 'Arial', 'size': 24}
        matplotlib.rc('font', **font)

        coloridx = np.linspace(0, 1, 10)  # for use with tab10 colormap
        fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(18, 10), dpi=100)

        for yval, ax in zip(('viscosity', 'shearstress'), (ax1, ax2)):
            if average:
                for idx, inkname in enumerate(self.alldata):
                    data = [ (self.alldata[inkname][sample]['shearrate'], \
                        self.alldata[inkname][sample][yval]) \
                        for sample in self.alldata[inkname]
                    ]

                    indep, mean, std, lcl, ucl = \
                        utilities.batch_average_plot(data=data)

                    mask = np.isfinite(mean)

                    if not confidence:
                        ax.errorbar(
                            indep[mask],
                            mean[mask],
                            yerr=std[mask],
                            color=plt.cm.tab10(coloridx[idx]),
                            marker='.',
                            markersize=8,
                            linewidth=3,
                            capsize=10,
                            elinewidth=3,
                            markeredgewidth=3,
                            label=self.labels[inkname],
                        )
                    else:
                        ax.plot(self.alldata[sample]['shearrate'],
                                self.alldata[sample][yval],
                                linewidth=3,
                                color='k',
                                alpha=0.2)

                        ax.plot(indep,
                                mean,
                                linewidth=3,
                                color='r',
                                label='mean')
                        ax.plot(
                            indep,
                            ucl,
                            color='r',
                            linewidth=3,
                            linestyle='--',
                        )
                        ax.plot(indep,
                                lcl,
                                color='r',
                                linewidth=3,
                                linestyle='--',
                                label=str(confidence)[2:] +
                                '% Confidence Interval (t-test)')

            else:
                idx = 0

                for inkname in self.data[inkname]:
                    for sample in self.alldata[inkname]:
                        x_plot = np.array(
                            self.alldata[inkname][sample]['shearrate'])
                        y_plot = np.array(self.alldata[inkname][sample][yval])

                        if np.isnan(np.min(y_plot)):
                            x_plot = x_plot.astype(np.double)
                            y_plot = y_plot.astype(np.double)
                            mask = np.isfinite(y_plot)

                            ax.plot(x_plot[mask],
                                    y_plot[mask],
                                    linewidth=3,
                                    color=plt.cm.tab10(coloridx[idx]),
                                    linestyle='--')

                        ax.plot(x_plot,
                                y_plot,
                                linewidth=3,
                                color=plt.cm.tab10(coloridx[idx]),
                                marker='o',
                                markersize=8,
                                label=str(sample))

                        idx += 1

            ax.set_xlabel(self.plotinfo['shearrate']['label'])
            ax.set_ylabel(self.plotinfo[yval]['label'])
            ax.legend()
            # ax.grid()

        if title:
            plt.suptitle(title)
        else:
            plt.suptitle('batch_viscosity_shearstress_' + self.title)

        plt.tight_layout()

        if save:
            if savename:
                plt.savefig(savename + '.' + imagetype)
            else:
                plt.savefig('batch_viscosity_shearstress_' \
                    + self.title + '.' + imagetype)

        if show:
            plt.show()

        plt.close(fig)
Ejemplo n.º 3
0
    def plot_DCIR_average(self,
                          confidence=0.95,
                          xlim=None,
                          ylim=None,
                          title=None,
                          show=False,
                          save=False,
                          savename=None,
                          imagetype='png'):
        ''' Plots average DCIR vs cycle number
            Includes confidence interval '''

        # Combines all sample data into list of tuples (x,y) by sample number (len = # of samples)
        data = [(self.alldata[sample].DCIR['cycles'], self.alldata[sample].DCIR['average']) \
            for sample in sorted(list(self.alldata.keys()))]

        cycles, mean, std, lcl, ucl = utilities.batch_average_plot(
            data, confidence=confidence)

        font = {'family': 'Arial', 'size': 28}
        matplotlib.rc('font', **font)
        fig, ax = plt.subplots(figsize=(16, 9), dpi=75)

        for sample in data:
            ax.plot(sample[0], sample[1], color='b', linewidth=3, alpha=0.2)
        ax.plot(cycles, mean, color='b', linewidth=3)

        if confidence:
            ax.plot(cycles,
                    lcl,
                    color='b',
                    linestyle='--',
                    linewidth=2,
                    label=str(confidence)[2:] +
                    '% Confidence Interval (t-test)')
            ax.plot(cycles, ucl, color='b', linestyle='--', linewidth=2)
            ax.fill_between(cycles, ucl, lcl, color='b', alpha=0.2)
        else:
            ax.plot(cycles,
                    mean + std,
                    color='b',
                    linestyle='--',
                    linewidth=2,
                    label='±1 ' + r'$\sigma$')
            ax.plot(cycles, mean - std, color='b', linestyle='--', linewidth=2)
            ax.fill_between(cycles,
                            mean + std,
                            mean - std,
                            color='b',
                            alpha=0.2)

        ax.set_xlabel('Cycle Number')
        ax.set_ylabel('DCIR [Ω]')
        ax.legend()
        ax.grid()

        if xlim:
            ax.set_xlim(xlim)
        if ylim:
            ax.set_ylim(ylim)

        if title:
            ax.set_title(title)
        else:
            ax.set_title(self.title)

        if save:
            if savename:
                plt.savefig(savename + '.' + imagetype)
            else:
                plt.savefig('batch_' + self.title + '_DCIR_average' + '.' +
                            imagetype)

        if show:
            plt.show()

        plt.close(fig)