Exemplo n.º 1
0
    def plot_histogram_tissue_radii(self, **kwargs):
        style_scheme = styles.StyleSchemeCOSH()
        x_range = (0, 40)
        bin_width = 2
        bar_fraction = 0.7
        bar_width = 0.5 * bin_width * bar_fraction
        bins = np.array(
            np.linspace(x_range[0], x_range[1],
                        (x_range[1] - x_range[0]) / bin_width + 1))
        ax = plt.gca()
        func_radii = 1e6 * np.array(self.results.functional_tissue_radii())
        topol_radii = 1e6 * np.array(self.results.topological_tissue_radii())
        functional_count, _ = np.histogram(func_radii, bins=bins)
        topological_count, _ = np.histogram(topol_radii, bins=bins)
        x1 = 0.5 * (bins[:-1] + bins[1:]) - 0.5 * bar_width
        x2 = 0.5 * (bins[:-1] + bins[1:]) + 0.5 * bar_width
        plt.bar(x1,
                functional_count,
                bar_width,
                edgecolor=style_scheme['int_func_radii_edge_color'],
                facecolor=style_scheme['int_func_radii_face_color'],
                linewidth=0.4,
                label='functional')
        plt.bar(x2,
                topological_count,
                bar_width,
                edgecolor=style_scheme['int_topol_radii_edge_color'],
                facecolor=style_scheme['int_topol_radii_face_color'],
                linewidth=0.4,
                label='geometric')

        # plot mean and standard deviation
        y_max = np.max(np.hstack((functional_count, topological_count)))
        ax.errorbar(np.mean(func_radii),
                    1.1 * y_max,
                    xerr=np.std(func_radii),
                    fmt='o',
                    markersize=2,
                    linewidth=1,
                    elinewidth=0.5,
                    capsize=2,
                    capthick=0.5,
                    color=style_scheme['int_func_radii_face_color'])
        ax.errorbar(np.mean(topol_radii),
                    1.05 * y_max,
                    xerr=np.std(topol_radii),
                    fmt='o',
                    markersize=2,
                    linewidth=1,
                    elinewidth=0.5,
                    capsize=2,
                    capthick=0.5,
                    color=style_scheme['int_topol_radii_edge_color'])

        ax.set_xlim(x_range)
        majorFormatter = FormatStrFormatter('%d')
        ax.yaxis.set_major_formatter(majorFormatter)
        styles.create_COSH_legend(ax, bbox_to_anchor=(1, 0.90))
        setXLabel('\mathrm{tissue\;radius}\;r_t', 'um')
        setYLabel('\mathrm{frequency}', '')
Exemplo n.º 2
0
def plotStdHbProfiles(plotter):
    plotter.plotSimStdHbProfile()
    plotter.plotODEStdHbProfile()
    plotter.plotODELinearizedStdHbProfile()
    plotter.plotNoModelStdHbProfile()
    ax = plt.gca()
    create_COSH_legend(ax, bbox_to_anchor=(0.99, 0.82))
    ax.yaxis.set_major_locator(MultipleWithMaxNLocator(0.01, 6))
    ax.set_xlim(ax.xaxis.get_data_interval())
Exemplo n.º 3
0
    def plot_histogram_tissue_radii_multipanel(self, functional_colors,
                                               functional_labels, **kwargs):
        f, axarr = plt.subplots(len(self.results_list) + 2, sharex=True)
        panel_annotation = 'ABCD'
        style_scheme = styles.StyleSchemeCOSH()
        x_range = (0, 40)
        bin_width = 2
        bar_fraction = 0.7
        bar_width = bin_width * bar_fraction
        bins = np.array(
            np.linspace(x_range[0], x_range[1],
                        (x_range[1] - x_range[0]) / bin_width + 1))
        bin_center = 0.5 * (bins[:-1] + bins[1:])
        y_max = 0.0
        hist_axes = axarr[0:-1]

        # boxplot
        data = [
            1e6 * np.array(self.results_list[0].topological_tissue_radii()),
            1e6 * np.array(self.results_list[1].functional_tissue_radii()),
            1e6 * np.array(self.results_list[0].functional_tissue_radii())
        ]
        labels = 'CBA'
        medianprops = {'color': 'w'}
        flierprops = {'marker': '.', 'markersize': 2}
        bp = axarr[-1].boxplot(data,
                               whis=[5, 95],
                               vert=False,
                               labels=labels,
                               patch_artist=True,
                               medianprops=medianprops,
                               showfliers=False,
                               flierprops=flierprops)
        fill_colors = [
            style_scheme['int_topol_radii_face_color'], functional_colors[1],
            functional_colors[0]
        ]
        for patch, color in zip(bp['boxes'], fill_colors):
            patch.set_facecolor(color)

        # histograms
        for i, (results, ax) in enumerate(zip(self.results_list, hist_axes)):
            func_radii = 1e6 * np.array(results.functional_tissue_radii())
            functional_count, _ = np.histogram(func_radii, bins=bins)
            y_max = max(y_max, np.max(functional_count))
            x_func = bin_center
            ax.bar(x_func,
                   functional_count,
                   bar_width,
                   edgecolor='k',
                   facecolor=functional_colors[i],
                   linewidth=0.4,
                   label=functional_labels[i])

        x_topol = bin_center
        topol_radii = 1e6 * np.array(
            self.results_list[0].topological_tissue_radii())
        topological_count, _ = np.histogram(topol_radii, bins=bins)
        axarr[-2].bar(x_topol,
                      topological_count,
                      bar_width,
                      edgecolor=style_scheme['int_topol_radii_edge_color'],
                      facecolor=style_scheme['int_topol_radii_face_color'],
                      linewidth=0.4,
                      label='geometric')
        y_max = max(y_max, np.max(topological_count))

        # plot mean and standard deviation
        y_error_bar = 1.04 * y_max
        for i, (results, ax) in enumerate(zip(self.results_list, hist_axes)):
            func_radii = 1e6 * np.array(results.functional_tissue_radii())
            ax.errorbar(np.mean(func_radii),
                        y_error_bar,
                        xerr=np.std(func_radii),
                        fmt='o',
                        markersize=2,
                        linewidth=1,
                        elinewidth=0.5,
                        capsize=2,
                        capthick=0.5,
                        color=functional_colors[i])

        axarr[-2].errorbar(np.mean(topol_radii),
                           y_error_bar,
                           xerr=np.std(topol_radii),
                           fmt='o',
                           markersize=2,
                           linewidth=1,
                           elinewidth=0.5,
                           capsize=2,
                           capthick=0.5,
                           color=style_scheme['int_topol_radii_edge_color'])

        axarr[0].set_xlim(x_range[0] - 1, x_range[1] + 1)
        y_lim_max = 1.1 * y_max
        setXLabel('\mathrm{tissue\;radius}\;r_t', 'um')
        for ax in hist_axes:
            majorLocator = MultipleLocator(10)
            ax.yaxis.set_major_locator(majorLocator)
            ax.set_ylim((0, y_lim_max))
            styles.create_COSH_legend(ax,
                                      loc='upper left',
                                      bbox_to_anchor=(0.01, 0.92))
            setYLabel('\mathrm{frequency}', '', ax=ax)
        for ax, annotation in zip(axarr, panel_annotation):
            annotate_axis_corner(ax, annotation, xy=(0.94, 0.82))
Exemplo n.º 4
0
    def plot_histogram_tissue_radii(self, functional_colors, functional_labels,
                                    **kwargs):
        ax = plt.gca()
        style_scheme = styles.StyleSchemeCOSH()
        n_bar_types = 1 + len(self.results_list)
        x_range = (0, 40)
        bin_width = 2
        bar_fraction = 0.7
        bar_width = bin_width * bar_fraction / n_bar_types
        bins = np.array(
            np.linspace(x_range[0], x_range[1],
                        (x_range[1] - x_range[0]) / bin_width + 1))
        bin_center = 0.5 * (bins[:-1] + bins[1:])
        y_max = 0.0

        for i, results in enumerate(self.results_list):
            func_radii = 1e6 * np.array(results.functional_tissue_radii())
            functional_count, _ = np.histogram(func_radii, bins=bins)
            y_max = max(y_max, np.max(functional_count))
            offset = (-0.5 +
                      (i + 0.5) / n_bar_types) * bin_width * bar_fraction
            x_func = bin_center + offset
            plt.bar(x_func,
                    functional_count,
                    bar_width,
                    edgecolor='k',
                    facecolor=functional_colors[i],
                    linewidth=0.4,
                    label=functional_labels[i])

        offset = (0.5 - 0.5 / n_bar_types) * bin_width * bar_fraction
        x_topol = bin_center + offset
        topol_radii = 1e6 * np.array(
            self.results_list[0].topological_tissue_radii())
        topological_count, _ = np.histogram(topol_radii, bins=bins)
        plt.bar(x_topol,
                topological_count,
                bar_width,
                edgecolor=style_scheme['int_topol_radii_edge_color'],
                facecolor=style_scheme['int_topol_radii_face_color'],
                linewidth=0.4,
                label='geometric')

        # plot mean and standard deviation
        y_max = max(y_max, np.max(topological_count))
        for i, results in enumerate(self.results_list):
            func_radii = 1e6 * np.array(results.functional_tissue_radii())
            y_error_bar = (1.1 - i / (len(self.results_list)) * 0.07) * y_max
            ax.errorbar(np.mean(func_radii),
                        y_error_bar,
                        xerr=np.std(func_radii),
                        fmt='o',
                        markersize=2,
                        linewidth=1,
                        elinewidth=0.5,
                        capsize=2,
                        capthick=0.5,
                        color=functional_colors[i])

        y_error_bar = 1.03 * y_max
        ax.errorbar(np.mean(topol_radii),
                    y_error_bar,
                    xerr=np.std(topol_radii),
                    fmt='o',
                    markersize=2,
                    linewidth=1,
                    elinewidth=0.5,
                    capsize=2,
                    capthick=0.5,
                    color=style_scheme['int_topol_radii_edge_color'])

        ax.set_xlim(x_range)
        styles.create_COSH_legend(ax,
                                  bbox_to_anchor=(0.48, 0.85),
                                  handlelength=2.3,
                                  handleheight=0.4)
        setXLabel('\mathrm{tissue\;radius}\;r_t', 'um')
        setYLabel('\mathrm{frequency}', '')
Exemplo n.º 5
0
    def plot_compared_hb_distal_distribution_multipanel(self, bin_width=0.02,
                                                        panel_annotation=('A', 'B', 'C')):
        """
        Plot a comparison between the simulated and the integrated hemoglobin distribution.

        Args:
            bin_width (float): bin width for histogram
            panel_annotation (sequence): panel annotations
        """
        f, axarr = plt.subplots(4, sharex=True)
        hist_axes = axarr[0:3]
        bp_ax = axarr[-1]
        sim_hb = self.postprocessor.distal_hb()
        # compute integrated distal hemoglobin distributions
        self.postprocessor.integrator.use_topological_radii = True
        self.postprocessor.integrator.compute()
        int_topol_hb, topol_weights = self.postprocessor.integrator.distal_hb_distribution()
        int_topol_hb_repeat = self.postprocessor.integrator.distal_hb_distribution_with_repeat()
        int_topol_mean = self.postprocessor.integrator.average_distal_hb()
        int_topol_std = self.postprocessor.integrator.std_distal_hb()
        self.postprocessor.integrator.use_topological_radii = False
        self.postprocessor.integrator.compute()
        int_func_hb, func_weights = self.postprocessor.integrator.distal_hb_distribution()
        int_func_hb_repeat = self.postprocessor.integrator.distal_hb_distribution_with_repeat()
        int_func_mean = self.postprocessor.integrator.average_distal_hb()
        int_func_std = self.postprocessor.integrator.std_distal_hb()

        # plot histograms
        bounds = rounded_bounds(np.hstack((sim_hb, int_topol_hb, int_func_hb)), bin_width)
        bins = np.arange(bounds[0], bounds[1]+0.5*bin_width, bin_width)
        simul_count, _ = np.histogram(sim_hb, bins=bins, normed=True)
        int_topol_count, _ = np.histogram(int_topol_hb, weights=topol_weights,
                                          bins=bins, normed=True)
        int_func_count, _ = np.histogram(int_func_hb, weights=func_weights,
                                         bins=bins, normed=True)
        bar_fraction = 0.8
        bar_width = bin_width*bar_fraction
        x = 0.5*(bins[:-1] + bins[1:])
        hist_axes[0].bar(x, simul_count, bar_width,
                         edgecolor=style_scheme['simul_radii_edge_color'],
                         facecolor=style_scheme['simul_radii_face_color'],
                         linewidth=0.3,
                         label='moving RBCs')
        hist_axes[1].bar(x, int_func_count, bar_width,
                         edgecolor=style_scheme['int_func_radii_edge_color'],
                         facecolor=style_scheme['int_func_radii_face_color'],
                         linewidth=0.3,
                         label='ODE (functional)')
        hist_axes[2].bar(x, int_topol_count, bar_width,
                         edgecolor=style_scheme['int_topol_radii_edge_color'],
                         facecolor=style_scheme['int_topol_radii_face_color'],
                         linewidth=0.3,
                         label='ODE (geometric)')
        xlim = max(0.0, round_to_base(axarr[0].get_xlim()[0], 0.1, func=np.floor)), \
               axarr[0].get_xlim()[1]
        axarr[0].set_xlim(xlim)

        # plot mean and standard deviation
        y_max = np.max(np.hstack((simul_count, int_topol_count, int_func_count)))
        sim_mean = np.mean(self.postprocessor.distal_hb())
        sim_std = np.std(self.postprocessor.distal_hb())
        y_error_bar = 1.05*y_max
        hist_axes[0].errorbar(sim_mean, y_error_bar, xerr=sim_std,
                              fmt='o', markersize=2, linewidth=1,
                              elinewidth=0.5,
                              capsize=2, capthick=0.5,
                              color=style_scheme['simul_radii_face_color'])
        hist_axes[1].errorbar(int_func_mean, y_error_bar, xerr=int_func_std,
                              fmt='o', markersize=2, linewidth=1,
                              elinewidth=0.5,
                              capsize=2, capthick=0.5,
                              color=style_scheme['int_func_radii_face_color'])
        hist_axes[2].errorbar(int_topol_mean, y_error_bar, xerr=int_topol_std,
                              fmt='o', markersize=2, linewidth=1,
                              elinewidth=0.5,
                              capsize=2, capthick=0.5,
                              color=style_scheme['int_topol_radii_edge_color'])
        setXLabel('\mathrm{outflow\;saturation}\;S_v', '')
        axarr[0].xaxis.set_major_locator(MultipleLocator(0.1))
        for ax, annotation in zip(hist_axes, panel_annotation):
            styles.create_COSH_legend(ax, loc='upper left')
            ax.yaxis.set_major_locator(MultipleLocator(5))
            # ax.yaxis.set_major_locator(MultipleLocator(10))
            setYLabel('f_{S_v}', '', ax=ax)
        for ax, annotation in zip(axarr, panel_annotation):
            annotate_axis_corner(ax, annotation, xy=(0.956, 0.79))
            # if annotation != 'C':
            #     annotate_axis_corner(ax, annotation, xy=(0.956, 0.79))
            # else:
            #     annotate_axis_corner(ax, annotation, xy=(0.956, 0.72))

        # boxplot
        data = [int_topol_hb_repeat, int_func_hb_repeat, sim_hb]
        offset = len(panel_annotation) - len(data)
        labels = panel_annotation[-1-offset::-1]
        medianprops = {'color': 'w'}
        flierprops = {'marker': '.', 'markersize': 2}
        bp = bp_ax.boxplot(data, whis=[5, 95], vert=False, labels=labels,
                           patch_artist=True, medianprops=medianprops, flierprops=flierprops,
                           showfliers=False)
        fill_colors = [style_scheme['int_topol_radii_edge_color'],
                       style_scheme['int_func_radii_face_color'],
                       style_scheme['simul_radii_face_color']]
        for patch, color in zip(bp['boxes'], fill_colors):
            patch.set_facecolor(color)
        print "5th percentile of topological:  ", np.percentile(int_topol_hb_repeat, 5)
        print "First quartile of topological:  ", np.percentile(int_topol_hb_repeat, 25)
        print "Median of topological:          ", np.percentile(int_topol_hb_repeat, 50)
        print "Third quartile of topological:  ", np.percentile(int_topol_hb_repeat, 75)
        print "95th percentile of topological: ", np.percentile(int_topol_hb_repeat, 95)

        # statistical testing
        F = int_topol_std**2/sim_std**2
        pvalue = scipy.stats.f.sf(F, np.size(int_topol_hb) - 1, np.size(sim_hb) - 1)
        print "p-value for ODE model (topological radii) vs. moving RBC: {:g}".format(pvalue)
        F = int_func_std**2/sim_std**2
        pvalue = scipy.stats.f.sf(F, np.size(int_func_hb) - 1, np.size(sim_hb) - 1)
        print "p-value for ODE model (functional radii) vs. moving RBC: {:g}".format(pvalue)
        F = int_topol_std**2/int_func_std**2
        pvalue = scipy.stats.f.sf(F, np.size(int_topol_hb) - 1, np.size(int_func_hb) - 1)
        print "p-value for ODE model, topological vs. functional radii: {:g}".format(pvalue)
Exemplo n.º 6
0
    def plot_compared_hb_distal_distribution(self, bin_width=0.02):
        """
        Plot a comparison between the simulated and the integrated hemoglobin distribution.

        Args:
            bin_width (float): bin width for histogram
        """
        ax = plt.gca()
        sim_hb = self.postprocessor.distal_hb()
        # compute integrated distal hemoglobin distributions
        self.postprocessor.integrator.use_topological_radii = True
        self.postprocessor.integrator.compute()
        int_topol_hb, topol_weights = self.postprocessor.integrator.distal_hb_distribution()
        int_topol_mean = self.postprocessor.integrator.average_distal_hb()
        int_topol_std = self.postprocessor.integrator.std_distal_hb()
        self.postprocessor.integrator.use_topological_radii = False
        self.postprocessor.integrator.compute()
        int_func_hb, func_weights = self.postprocessor.integrator.distal_hb_distribution()
        int_func_mean = self.postprocessor.integrator.average_distal_hb()
        int_func_std = self.postprocessor.integrator.std_distal_hb()

        # plot histograms
        bounds = rounded_bounds(np.hstack((sim_hb, int_topol_hb, int_func_hb)), bin_width)
        bins = np.arange(bounds[0], bounds[1]+0.5*bin_width, bin_width)
        bar_fraction = 0.7
        bar_width = 1./3.*bin_width*bar_fraction
        simul_count, _ = np.histogram(sim_hb, bins=bins, normed=True)
        int_topol_count, _ = np.histogram(int_topol_hb, weights=topol_weights,
                                          bins=bins, normed=True)
        int_func_count, _ = np.histogram(int_func_hb, weights=func_weights,
                                          bins=bins, normed=True)
        x1 = 0.5*(bins[:-1] + bins[1:]) - bar_width
        x2 = 0.5*(bins[:-1] + bins[1:])
        x3 = 0.5*(bins[:-1] + bins[1:]) + bar_width
        ax.bar(x1, simul_count, bar_width,
               edgecolor=style_scheme['simul_radii_edge_color'],
               facecolor=style_scheme['simul_radii_face_color'],
               linewidth=0.3,
               label='moving RBCs')
        ax.bar(x2, int_func_count, bar_width,
               edgecolor=style_scheme['int_func_radii_edge_color'],
               facecolor=style_scheme['int_func_radii_face_color'],
               linewidth=0.3,
               label='ODE (functional)')
        ax.bar(x3, int_topol_count, bar_width,
               edgecolor=style_scheme['int_topol_radii_edge_color'],
               facecolor=style_scheme['int_topol_radii_face_color'],
               linewidth=0.3,
               label='ODE (geometric)')
        xlim = max(0.0, round_to_base(ax.get_xlim()[0], 0.1, func=np.floor)), ax.get_xlim()[1]
        ax.set_xlim(xlim)

        # plot mean and standard deviation
        y_max = np.max(np.hstack((simul_count, int_topol_count, int_func_count)))
        sim_mean = np.mean(self.postprocessor.distal_hb())
        sim_std = np.std(self.postprocessor.distal_hb())
        ax.errorbar(sim_mean, 1.1*y_max, xerr=sim_std,
                    fmt='o', markersize=2, linewidth=1,
                    elinewidth=0.5,
                    capsize=2, capthick=0.5,
                    color=style_scheme['simul_radii_face_color'])
        ax.errorbar(int_func_mean, 1.06*y_max, xerr=int_func_std,
                    fmt='o', markersize=2, linewidth=1,
                    elinewidth=0.5,
                    capsize=2, capthick=0.5,
                    color=style_scheme['int_func_radii_face_color'])
        ax.errorbar(int_topol_mean, 1.02*y_max, xerr=int_topol_std,
                    fmt='o', markersize=2, linewidth=1,
                    elinewidth=0.5,
                    capsize=2, capthick=0.5,
                    color=style_scheme['int_topol_radii_edge_color'])
        styles.create_COSH_legend(ax, bbox_to_anchor=(0.45, 0.95))
        setXLabel('\mathrm{outflow\;saturation}\;S_v', '')
        setYLabel('\mathrm{probability\;density}', '')
        ax.xaxis.set_major_locator(MultipleLocator(0.1))
        ax.yaxis.set_major_locator(MultipleLocator(5))
        plt.clf()
else:
    plotter = DiffusiveInteractionComparisonPlotter(postprocessor, model_names)
    if args.multipanel:
        panel_layout = (2, 1) if not args.panelLayout else args.panelLayout
        fig, axs = plt.subplots(*panel_layout, sharex=True)
        plt.sca(axs[0])
        plotter.plotHbProfiles(plot_mean=plot_mean)
        annotate_axis_corner(axs[0], 'A')
        if panel_layout[1] == 1:
            axs[0].set_xlabel('')
        plt.sca(axs[1])
        plotter.plotHbDiffProfiles(exponential_fit=exponential_fit,
                                   linearized_ode=linearized_ode)
        # legend = create_COSH_legend(axs[1], bbox_to_anchor=(1, 0.86))
        legend = create_COSH_legend(axs[1], bbox_to_anchor=(0.5, 0.86))
        annotate_axis_corner(axs[1], 'B')
        figOptions.saveFig('plotDiffusiveInteractionMultipanel' +
                           plot_name_suffix)
    else:
        plotter.plotHbProfiles()
        plotter.plotHbDiffProfiles(exponential_fit=exponential_fit)
        figOptions.saveFig('plotDiffusiveInteraction' + plot_name_suffix)
        plt.clf()
        for model_name, modelPlotter in plotter.modelPlotters.iteritems():
            modelPlotter.plotOutfluxes()
        figOptions.saveFig('plotOutfluxes')
        plt.clf()

        for model_name, modelPlotter in plotter.modelPlotters.iteritems():
            modelPlotter.plotTissueRadii()
        style.update(style_scheme['MVN1'])
        style.update({'label': 'MVN 1'})
    elif '20150715' in case_path or 'MVN2' in case_path:
        style.update(style_scheme['MVN2'])
        style.update({'label': 'MVN 2'})

plt.clf()
combined_plotter.plot_histogram_tissue_radii()
fig_options.saveFig('plotHistogramTissueRadii')

plt.clf()
for plotter, style in zip(plotters, styles):
    plotter.plot_functional_vs_topological_tissue_radii(**style)
cosh_styles.create_COSH_legend(plt.gca(),
                               loc='upper left',
                               markerscale=0.7,
                               handletextpad=0,
                               handlelength=2.5)
fig_options.saveFig('plotFunctionalVsTopologicalTissueRadii')

plt.clf()
for plotter, style in zip(plotters, styles):
    plotter.plot_tissue_radii_vs_hb_mean(**style)
cosh_styles.create_COSH_legend(plt.gca(),
                               loc='upper left',
                               markerscale=0.8,
                               handletextpad=0,
                               handlelength=2.5)
fig_options.saveFig('plotTissueRadiiVsHbMean')

plt.clf()