示例#1
0
    def plot_efficiency(self,
                        xlim=False,
                        ylim=[90, 110],
                        title=None,
                        show=False,
                        save=False):
        ''' Plots charging efficiency vs cycle '''

        params = {
            'xlim': xlim,
            'ylim': ylim,
            'title': title,
            'titletag': '_Efficiency',
            'xlabel': 'Cycle Number',
            'ylabel': 'Coulombic Efficiency [%]'
        }

        cycles = list(self.cycles.keys())[1:]
        efficiency = [self.cycles[cycle]['efficiency'] for cycle in cycles]

        fig, ax = utilities.plot_setup(params=params)
        ax.plot(
            cycles[:-1],
            efficiency[:-1],
            color='b',
            linewidth=2,
        )

        if save:
            plt.savefig(self.title + params['titletag'] + '.png')
        if show:
            plt.show()

        plt.close(fig)
示例#2
0
    def plot_voltage(self,
                     xlim=None,
                     ylim=None,
                     title=None,
                     show=False,
                     save=False):
        ''' Plots voltage vs time '''

        params = {
            'xlim': xlim,
            'ylim': ylim,
            'title': title,
            'titletag': '_voltage',
            'xlabel': 'Time [s]',
            'ylabel': 'Voltage [V]'
        }

        fig, ax = utilities.plot_setup(params=params)

        ax.plot(
            self.time,
            self.voltage,
            color='b',
            linewidth=2,
        )

        if save:
            plt.savefig(self.title + params['titletag'] + '.png')
        if show:
            plt.show()

        plt.close(fig)
示例#3
0
    def plot_capacity(
        self,
        discharge=True,
        charge=True,
        xlim=False,
        ylim=False,
        title=None,
        show=False,
        save=False,
    ):
        ''' Plots charge/discharge capacity vs cycle '''

        params = {
            'xlim': xlim,
            'ylim': ylim,
            'title': title,
            'titletag': '_Capacity',
            'xlabel': 'Cycle Number',
            'ylabel': 'Capacity ' + r'$[mAh]$'
        }

        fig, ax = utilities.plot_setup(item=self, params=params)

        # Get list of all cycle numbers
        # Omit cycle 0 from plotting
        cycles = list(self.cycles.keys())[1:]

        # Plot both discharge and charge by default
        if discharge:
            Qdischarge = [
                np.max(self.cycles[cycle]['Qdischarge']) for cycle in cycles
            ]

            ax.plot(cycles[:-1],
                    Qdischarge[:-1],
                    color='b',
                    linewidth=2,
                    label=r'$Q_{discharge}$')
        if charge:
            # To make charge curve line up with discharge
            plotcycles = [cycle - 1 for cycle in cycles]
            Qcharge = [
                np.max(self.cycles[cycle]['Qcharge']) for cycle in cycles
            ]

            ax.plot(plotcycles,
                    Qcharge,
                    color='r',
                    linewidth=2,
                    label=r'$Q_{charge}$')

        ax.legend()

        if save:
            plt.savefig(self.title + params['titletag'] + '.png')
        if show:
            plt.show()

        plt.close(fig)
示例#4
0
    def plot_capacity_fade(
        self,
        xlim=False,
        ylim=[0, 100],
        title=None,
        show=False,
        save=False,
    ):
        ''' Plots capacity fade vs. cycle
            Similar to plotting capacity vs. cycle but normalized to 
            first cycle capacity '''

        params = {
            'xlim': xlim,
            'ylim': ylim,
            'title': title,
            'titletag': '_Fade',
            'xlabel': 'Cycle Number',
            'ylabel': 'Capacity Fade [%]'
        }

        fig, ax = utilities.plot_setup(params=params)

        # Get list of all cycle numbers
        # Omit cycle 0 from plotting
        cycles = list(self.cycles.keys())[1:]

        # baseline = np.max(self.cycles[cycles[0]]['Qdischarge'])
        fade = [self.cycles[cycle]['fade'] for cycle in cycles]

        ax.plot(cycles[:-1], fade[:-1], color='b', linewidth=2)

        if save:
            plt.savefig(self.title + params['titletag'] + '.png')
        if show:
            plt.show()

        plt.close(fig)
示例#5
0
    def plot_DOD(
        self,
        plotcycleinterval=20,
        charge=True,
        discharge=True,
        xlim=[0, 1],
        ylim=None,
        title=None,
        show=False,
        save=False,
    ):
        ''' Plots voltage vs DOD 
            Max Qdischarge is on the y-axis (decreasing to the right)
            plotcycleinterval = cycle interval to include on plot
            '''

        params = {
            'xlim': xlim,
            'ylim': ylim,
            'title': title,
            'titletag': '_DOD',
            'xlabel': 'Capacity [mAh/cm' + r'$^2$' + ']',
            'ylabel': 'Voltage [V]',
        }

        fig, ax = utilities.plot_setup(params=params)

        if charge:
            DOC = {}

            for cycle in list(self.cycles.keys())[1:]:
                if np.remainder(cycle, plotcycleinterval) == 0:
                    DOC[cycle] = {'voltage': [], 'Qcharge': []}

            # Remove last element of voltage and Qdischarge lists to avoid "tail" in graphs
            # Artifact of splitting up by cycle/tester resolution
            for cycle in DOC:
                for voltage, current, Qcharge in \
                    zip(self.cycles[cycle]['voltage'], \
                        self.cycles[cycle]['current'], \
                        self.cycles[cycle]['Qcharge']):

                    if Qcharge != 0 and current > 0:
                        DOC[cycle]['voltage'].append(voltage)
                        DOC[cycle]['Qcharge'].append(Qcharge)

            coloridx = np.linspace(0.25, 1, len(DOC))

            for idx, cycle in enumerate(DOC):
                ax.plot(DOC[cycle]['Qcharge'],
                        DOC[cycle]['voltage'],
                        linewidth=3,
                        color=plt.cm.Blues(coloridx[idx]),
                        label=cycle)

        if discharge:
            DOD = {}

            for cycle in list(self.cycles.keys())[1:]:
                if np.remainder(cycle, plotcycleinterval) == 0:
                    DOD[cycle] = {'voltage': [], 'Qdischarge': []}

            # Remove last element of voltage and Qdischarge lists to avoid "tail" in graphs
            # Artifact of splitting up by cycle/tester resolution
            for cycle in DOD:
                for voltage, current, Qdischarge in \
                    zip(self.cycles[cycle]['voltage'], \
                        self.cycles[cycle]['current'], \
                        self.cycles[cycle]['Qdischarge']):

                    if Qdischarge != 0 and current < 0:
                        DOD[cycle]['voltage'].append(voltage)
                        DOD[cycle]['Qdischarge'].append(Qdischarge)

            coloridx = np.linspace(0.25, 1, len(DOD))

            for idx, cycle in enumerate(DOD):
                ax.plot(DOD[cycle]['Qdischarge'][1:-1],
                        DOD[cycle]['voltage'][1:-1],
                        linewidth=2,
                        color=plt.cm.Blues(coloridx[idx]),
                        label=cycle)

        handles, labels = fig.gca().get_legend_handles_labels()
        i = 1
        while i < len(labels):
            if labels[i] in labels[:i]:
                del (labels[i])
                del (handles[i])
            else:
                i += 1
        plotlabels = ['Cycle ' + str(label) for label in labels]
        ax.legend(handles, plotlabels)

        if save:
            plt.savefig(self.title + params['titletag'] + '.png')
        if show:
            plt.show()

        plt.close(fig)
示例#6
0
    def plot_IR_drop(
        self,
        steps=['charge', 'discharge', 'rest'],
        average=True,
        xlim=None,
        ylim=None,
        semilogy=True,
        title=None,
        show=False,
        save=False,
    ):
        ''' Plots extracted IR data vs cycle number
            IRtype accepts kwargs 'charge', 'discharge', 'rest', or 'average' as list
            e.g. ['charge', 'discharge',]
            '''

        self.get_IR_data()

        params = {
            'xlim': xlim,
            'ylim': ylim,
            'title': title,
            'titletag': '_DCIR',
            'xlabel': 'Cycle Number',
            'ylabel': 'DC Internal Resistance [Ω]'
        }

        fig, ax = utilities.plot_setup(params=params)

        plotcolors = {'charge': 'r', 'discharge': 'g', 'rest': 'b'}
        plotcycles = list(self.DCIR.keys())

        for step in steps:
            # Plots averaged DCIR per step (if multiples of each step per cycle)
            if average:
                plotIR = [
                    self.DCIR[cycle][step]['average'] for cycle in self.DCIR
                ]

                if semilogy:
                    ax.semilogy(plotcycles,
                                plotIR,
                                color=plotcolors[step],
                                linewidth=2,
                                label=step)
                else:
                    ax.plot(plotcycles,
                            plotIR,
                            color=plotcolors[step],
                            linewidth=2,
                            label=step)

            else:
                # Plots all raw IR values (multiple steps plotted individually)
                all_IR = np.array(
                    [self.DCIR[cycle][step]['all'] for cycle in self.DCIR]).T

                alphas = np.linspace(1, 0.6, len(all_IR))

                for idp, pulse in enumerate(all_IR):
                    if semilogy:
                        if idp == 0:
                            ax.semilogy(plotcycles,
                                        pulse,
                                        color=plotcolors[step],
                                        alpha=alphas[idp],
                                        linewidth=2,
                                        label=step)
                        else:
                            ax.semilogy(plotcycles,
                                        pulse,
                                        color=plotcolors[step],
                                        alpha=alphas[idp],
                                        linewidth=2)
                    else:
                        if idp == 0:
                            ax.plot(plotcycles,
                                    pulse,
                                    color=plotcolors[step],
                                    alpha=alphas[idp],
                                    linewidth=2,
                                    label=step)
                        else:
                            ax.plot(plotcycles,
                                    pulse,
                                    color=plotcolors[step],
                                    alpha=alphas[idp],
                                    linewidth=2)

        ax.legend()

        if save:
            plt.savefig(self.title + params['titletag'] + '.png')
        if show:
            plt.show()

        plt.close(fig)
示例#7
0
    def plot_capacity(
        self,
        discharge=True,
        charge=False,
        xlim=False,
        ylim=[0, 1],
        title=None,
        show=False,
        save=False,
    ):
        ''' Plots charge/discharge capacity vs cycle '''

        params = {
            'xlim': xlim,
            'ylim': ylim,
            'title': title,
            'titletag': '_Capacity',
            'xlabel': 'Cycle Number',
            'ylabel': 'Capacity ' + r'$[mAh]$'
        }

        fig, ax = utilities.plot_setup(item=self, params=params)
        coloridx = np.linspace(0, 1, 10)  # for use with tab10 colormap

        for sample in self.alldata:
            single = self.alldata[sample]

            plotcycles = list(single.cycles.keys())[1:]

            if discharge:
                plotQdischarge = [
                    np.max(single.cycles[cycle]['Qdischarge'])
                    for cycle in plotcycles
                ]
                ax.plot(plotcycles[:-1],
                        plotQdischarge[:-1],
                        color=plt.cm.tab10(coloridx[int(sample) - 1]),
                        linewidth=2,
                        label='S' + str(sample))

            elif charge:
                plotQcharge = [
                    np.max(single.cycles[cycle]['Qcharge'])
                    for cycle in plotcycles
                ]
                ax.plot(plotcycles[:-1],
                        plotQcharge[:-1],
                        color=plt.cm.tab10(coloridx[int(sample) - 1]),
                        linewidth=2,
                        label='S' + str(sample))

        ax.legend()

        if title:
            ax.set_title(title + '_Qdischarge')
        else:
            ax.set_title(self.title + '_Qdischarge')

        if save:
            if title:
                plt.savefig(title + params['titletag'] + '.png')
            else:
                plt.savefig('batch' + params['titletag'] + '.png')

        if show:
            plt.show()

        plt.close(fig)