def plotPO2YProfile(simParams, x=150e-6, **kwargs): kroghSol = KroghSolution2DCone(simParams) kroghSol.intravascularResistanceLDHalf = kwargs.get( 'K0', kroghSol.intravascularResistanceLDHalf) kroghSol.convO2Transport = kwargs.get('convO2Transport', True) if 'K0' in kwargs: print "plotPO2Profile: Using K0 = %g" % kwargs['K0'] style = kwargs.get('style', {'color': 'k'}) PO2AnalyticalStyle = { 'color': 'k', 'linestyle': '-', 'linewidth': 1, 'dashes': (1.2, 1.5) } # 'dashes': (5,2.5,1,2.5)} nr = 300 rMax = kroghSol.geometry.tissueRadius(x) rAnalytical = np.linspace(0, rMax, nr) rTissue = np.linspace(kroghSol.geometry['radiusWall'], rMax, nr) PO2Analytical = [kroghSol.PO2Analytical(x, r) for r in rAnalytical] PO2Tissue = [kroghSol.PO2Tissue(x, r) for r in rTissue] PO2RBCMean = kroghSol.PO2RBCMeanAtX(x) plt.plot(1e6 * rAnalytical, PO2Analytical, **PO2AnalyticalStyle) plt.plot(1e6 * rTissue, PO2Tissue, linewidth=1, **style) plt.plot(1e6 * kroghSol.Rrbc / 2, PO2RBCMean, '.', color='k', markersize=4) plt.xlim(0, 1e6 * rMax) plt.ylim(rounded_bounds(PO2Analytical, 10)) labels.setXLabel('r', 'um') labels.setYLabel('PO2', 'mmHg')
def plotPO2ProfileInterstitialSpace(simParams, radius=17.6e-6, **kwargs): kroghSol = KroghSolution2DCone(simParams) kroghSol.intravascularResistanceLDHalf = kwargs.get( 'K0', kroghSol.intravascularResistanceLDHalf) if 'K0' in kwargs: print "plotPO2Profile: Using K0 = %g" % kwargs['K0'] style = kwargs.get('style', {'color': 'k'}) L = simParams['domainLength'] nx = 100 xValues = np.linspace(0, L, nx) PO2 = [kroghSol.PO2Tissue(x, radius) for x in xValues] plt.plot(1e6 * xValues, PO2, linewidth=1, **style) plt.ylim(rounded_bounds(PO2, 10)) interstitialLayerWidth = 0.35e-6 kroghSol.geometry['radiusWall'] += interstitialLayerWidth kroghSol.intravascularResistanceLDHalf *= 1.1 PO2WithInterstitial = [kroghSol.PO2Tissue(x, radius) for x in xValues] plt.plot(1e6 * xValues, PO2WithInterstitial, '--') labels.setXLabel('x', 'um') labels.setYLabel('PO2', 'mmHg') print 'Difference: ', np.array(PO2) - np.array(PO2WithInterstitial)
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)
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))
def plot_integrated_hb_distal_distribution(self, bin_width=0.01, **kwargs): hb, weights = self.postprocessor.integrator.distal_hb_distribution() bounds = rounded_bounds(hb, bin_width) bins = np.arange(bounds[0], bounds[1]+0.5*bin_width, bin_width) plt.hist(hb, bins=bins, histtype='bar', weights=weights, **kwargs) setXLabel('\mathrm{outflow\;saturation}\;S_v', '')
def plot_simulated_hb_distal_distribution(self, bin_width=0.01, **kwargs): values = self.postprocessor.distal_hb() bounds = rounded_bounds(values, bin_width) bins = np.arange(bounds[0], bounds[1]+0.5*bin_width, bin_width) plt.hist(values, bins=bins, histtype='bar', **kwargs) setXLabel('\mathrm{outflow\;saturation}\;S_v', '')