Beispiel #1
0
    def plot(self, start=0, end=None, overlay=None):
        """Plots the whole time_signal for each component.

        Parameters
        ----------
        start : float
            start time for plotting
        end : float
            end time for plotting

        See also
        --------
        CADETProcess.plot
        """
        x = self.time / 60
        y = self.solution / 1000
        ymax = np.max(y)

        fig, ax = plotting.setup_figure()

        ax.plot(x, y)

        if overlay is not None:
            ymax = 1.1 * np.max(overlay)
            plotting.add_overlay(ax, overlay)

        layout = plotting.Layout()
        layout.x_label = '$time~/~min$'
        layout.y_label = '$V~/~L$'
        layout.xlim = (start, end)
        layout.ylim = (0, ymax)
        plotting.set_layout(fig, ax, layout)

        return ax
Beispiel #2
0
    def plot_purity(self, start=0, end=None):
        """Plots the local purity for each component of the concentration
        profile.

        Parameters
        ----------
        start : float
            start time for plotting
        end : float
            ent time for plotting

        See also
        --------
        plotlib
        plot
        """
        x = self.time / 60
        y = self.local_purity * 100

        fig, ax = plotting.setup_figure()
        ax.plot(x,y)

        layout = plotting.Layout()
        layout.x_label = '$time~/~min$'
        layout.y_label = '$c~/~mol \cdot L^{-1}$'
        layout.xlim = (start, end)
        layout.ylim = (0, 1.1*np.max(y))
        
        plotting.set_layout(fig, ax, layout)        
        
        return ax
Beispiel #3
0
    def _plot_2D(self, t, comp, state, vmax):
        x = self.axial_coordinates
        y = self.particle_coordinates

        if not self.time[0] <= t <= self.time[-1]:
            raise ValueError("Time exceeds bounds.")
        t_i = np.where(t <= self.time)[0][0]
        c_i = comp * self.n_bound + state
        v = self.solution[t_i, :, :, c_i].transpose()

        if vmax is None:
            vmax = v.max()

        fig, ax = plotting.setup_figure()
        mesh = ax.pcolormesh(x, y, v, shading='gouraud', vmin=0, vmax=vmax)

        plotting.add_text(ax, f'time = {t:.2f} s')

        layout = plotting.Layout()
        layout.title = f'Solid phase concentration, comp={comp}, state={state}'
        layout.x_label = '$z~/~m$'
        layout.y_label = '$r~/~m$'
        layout.labels = self.component_system.labels[c_i]
        plotting.set_layout(fig, ax, layout)
        fig.colorbar(mesh)

        return fig, ax, mesh
Beispiel #4
0
    def plot(self, start=0, end=None):
        """Plots the whole time_signal for each component.

        Parameters
        ----------
        start : float
            start time for plotting
        end : float
            end time for plotting

        See also
        --------
        plotlib
        plot_purity
        """
        x = self.time / 60
        y = self.signal

        fig, ax = plotting.setup_figure()
        ax.plot(x,y)

        layout = plotting.Layout()
        layout.x_label = '$time~/~min$'
        layout.y_label = '$c~/~mol \cdot L^{-1}$'
        layout.xlim = (start, end)
        layout.ylim = (0, 1.1*np.max(y))
        
        plotting.set_layout(fig, ax, layout)        

        return ax
    def plot_events(self):
        """Plot parameter state as function of time.
        """
        time = np.linspace(0, self.cycle_time, 1001)
        for parameter, tl in self.parameter_timelines.items():
            y = tl.value(time)

            fig, ax = plotting.setup_figure()

            layout = plotting.Layout()
            layout.title = str(parameter)
            layout.x_label = '$time~/~min$'
            layout.y_label = '$state$'

            ax.plot(time / 60, y)

            plotting.set_layout(fig, ax, layout)
    def plot(self):
        """Plot section state over time.
        """
        start = self.sections[0].start
        end = self.sections[-1].end
        time = np.linspace(start, end, 1001) / 60
        y = self.value(time)

        fig, ax = plotting.setup_figure()
        ax.plot(time, y)

        layout = plotting.Layout()
        layout.x_label = '$time~/~min$'
        layout.y_label = '$state$'
        layout.xlim = (start / 60, end / 60)
        layout.ylim = (0, 1.1 * np.max(y))

        plotting.set_layout(fig, ax, layout)

        return ax
Beispiel #7
0
    def plot_at_location(self, z, overlay=None, ymax=None):
        """Plot bulk solution over time at given location.

        Parameters
        ----------
        z : float
            space for plotting

        See also
        --------
        plot_at_time
        CADETProcess.plotting
        """
        x = self.time

        if not self.axial_coordinates[0] <= z <= self.axial_coordinates[-1]:
            raise ValueError("Axial coordinate exceets boundaries.")
        z_i = np.where(z <= self.axial_coordinates)[0][0]

        y = self.solution[:, z_i]
        if ymax is None:
            ymax = 1.1 * np.max(y)

        fig, ax = plotting.setup_figure()
        ax.plot(x, y)

        plotting.add_text(ax, f'z = {z:.2f} m')

        if overlay is not None:
            ymax = np.max(overlay)
            plotting.add_overlay(ax, overlay)

        layout = plotting.Layout()
        layout.x_label = '$time~/~min$'
        layout.y_label = '$c~/~mM$'
        layout.ylim = (0, ymax)
        plotting.set_layout(fig, ax, layout)

        return ax
Beispiel #8
0
    def plot_at_time(self, t, overlay=None, ymax=None):
        """Plot bulk solution over space at given time.

        Parameters
        ----------
        t : float
            time for plotting

        See also
        --------
        plot_at_location
        CADETProcess.plotting
        """
        x = self.axial_coordinates

        if not self.time[0] <= t <= self.time[-1]:
            raise ValueError("Time exceeds bounds.")
        t_i = np.where(t <= self.time)[0][0]

        y = self.solution[t_i, :]
        if ymax is None:
            ymax = 1.1 * np.max(y)

        fig, ax = plotting.setup_figure()
        ax.plot(x, y)

        plotting.add_text(ax, f'time = {t:.2f} s')

        if overlay is not None:
            ymax = np.max(overlay)
            plotting.add_overlay(ax, overlay)

        layout = plotting.Layout()
        layout.x_label = '$z~/~m$'
        layout.y_label = '$c~/~mM$'
        layout.ylim = (0, ymax)
        plotting.set_layout(fig, ax, layout)

        return ax
Beispiel #9
0
    def _plot_1D(self, t, ymax):
        x = self.axial_coordinates

        if not self.time[0] <= t <= self.time[-1]:
            raise ValueError("Time exceeds bounds.")
        t_i = np.where(t <= self.time)[0][0]
        y = self.solution[t_i, :]

        if ymax is None:
            ymax = 1.1 * np.max(y)

        fig, ax = plotting.setup_figure()
        ax.plot(x, y)

        plotting.add_text(ax, f'time = {t:.2f} s')

        layout = plotting.Layout()
        layout.x_label = '$z~/~m$'
        layout.y_label = '$c~/~mM$'
        layout.ylim = (0, ymax)
        plotting.set_layout(fig, ax, layout)

        return fig, ax
Beispiel #10
0
def plot_solution_1D(solution,
                     ax=None,
                     layout=None,
                     only_plot_total_concentrations=False,
                     alpha=1,
                     hide_labels=False,
                     hide_species_labels=True,
                     secondary_axis=None,
                     secondary_layout=None,
                     show_legend=True):

    time = solution.time / 60
    sol = solution.solution

    if ax is None:
        fig, ax = plotting.setup_figure()

    total_concentration = solution.total_concentration()

    if secondary_axis is not None:
        ax_secondary = ax.twinx()
    else:
        ax_secondary = None

    species_index = 0
    for i, comp in enumerate(solution.component_system.components):
        color = next(ax._get_lines.prop_cycler)['color']
        if hide_labels:
            label = None
        else:
            label = comp.name

        if secondary_axis is not None and i in secondary_axis.component_indices:
            a = ax_secondary
        else:
            a = ax

        if secondary_axis is not None \
                and secondary_axis.transform is not None \
                and i in secondary_axis.component_indices:
            y = secondary_axis.transform(total_concentration[..., i])
        else:
            y = total_concentration[..., i]

        a.plot(time, y, label=label, color=color, alpha=alpha)

        if not only_plot_total_concentrations:
            if comp.n_species == 1:
                species_index += 1
                continue

            for s, species in enumerate(comp.species):
                if hide_species_labels:
                    label = None
                else:
                    label = s
                if secondary_axis is not None and i in secondary_axis.component_indices:
                    a = ax_secondary
                else:
                    a = ax

                if secondary_axis is not None \
                        and secondary_axis.transform is not None \
                        and i in secondary_axis.component_indices:
                    y = secondary_axis.transform(sol[..., species_index])
                else:
                    y = sol[..., species_index]

                a.plot(time, y, '--', label=label, color=color, alpha=alpha)
                species_index += 1

    if layout is not None:
        plotting.set_layout(fig, ax, layout, show_legend, ax_secondary,
                            secondary_layout)

    return ax, fig