def plotMultiPanelKOSContourAndOscillationDistance(self, manual_labels=False): fig, axs = plt.subplots(1, 2) U, LD = self.post_processor.param_study.meshGrid() Z = 1e-6 * self.reshapeListToArray( [pp.KOS for pp in self.post_processor.post_processors]) levels = contourLevels(Z, 0.5, 0.5) cplot = axs[0].contour(LD, 1e3 * U, Z, levels, cmap=self.cmap) # cplot = axs[0].contour(LD, 1e3*U, Z, levels, colors='k') if manual_labels: plt.clabel(cplot, inline=True, inline_spacing=24, fontsize=10, fmt='%g', manual=True) else: plt.clabel(cplot, inline=1, fontsize=12, fmt='%g') self.setAxisLabels(ax=axs[0]) annotate_axis_corner(axs[0], 'A') oscillLengths = 1e6 * np.asarray([ pp.integralOscillationPenetrationDistance() for pp in self.post_processor.post_processors ]) KOS = 1e-6 * np.asarray( [pp.KOS for pp in self.post_processor.post_processors]) axs[1].plot(oscillLengths, KOS, '.', color='b', markersize=3) slope, intercept, rvalue, pvalue, stderr = \ self.post_processor.KOSFitter.fitKOS(oscillLengths, KOS) rfit = np.linspace(np.min(oscillLengths), np.max(oscillLengths), 100) axs[1].xaxis.set_major_locator(MultipleWithMaxNLocator(0.5, 10)) axs[1].plot(rfit, slope * rfit + intercept, 'k-') labels.setXLabel(r'\Delta r_{\mathrm{osc}}', 'um', ax=axs[1]) labels.setYLabel(r'K_{OS}', 'IVR', ax=axs[1]) set_rounded_axis_limits(axs[1], base=0.5, axis='x') set_rounded_axis_limits(axs[1], base=1.0, axis='y') annotate_axis_corner(axs[1], 'B') self.fig_options.saveFig('plotKOSContourAndOscillationDistance') plt.clf()
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))
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)
if model_only: for model_name in postprocessor.integrators: plotter = DiffusiveInteractionModelPlotter( postprocessor.integrators[model_name]) plotter.plotAll() figOptions.saveFig('plot_{:s}_modelDiffusiveInteraction_Hb{:s}'.\ format(model_name, plot_name_suffix)) 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()
nargs='+', help='Models for which to plot results', default=['krogh', 'simple']) fig_options = FigureOptions(parser) args = parser.parse_args() file_name = args.paramFile method_name = args.methodName model_names = args.modelNames fig_options.parseOptions(args) fig, axs = plt.subplots(2, 2, sharey=True) flattened_axs = [ax for sublist in axs for ax in sublist] for study, ax, text in zip(studies, flattened_axs, annotations): path_to_study = os.path.join(path_to_parameter_studies, study) path_to_study_param_file = os.path.join(path_to_study, file_name) param_study = ParameterStudyFactory().makeParameterStudy( path_to_study_param_file) settings_dict = load_settings_file(path_to_study) postprocessor = ParameterStudyPostProcessor(param_study, settings_dict) plotter = DiffusiveInteractionParameterStudyPlotter( postprocessor, fig_options, model_names) plt.sca(ax) getattr(plotter, method_name)() annotate_axis_corner(ax, text) axs[0, 1].set_ylabel('') axs[1, 1].set_ylabel('') fig_options.saveFig('plotDiffusiveInteractionMulti_{:s}'.format(method_name))
if args.allSegments: sids = plotter.edge_ids() else: sids = args.segmentIndices if multipanel: nrow = len(sids) / ncol fig, axs = plt.subplots(nrow, ncol) flattened_axs = [ax for sublist in axs for ax in sublist] for si, ax, annotation in zip(sids, flattened_axs, annotations): plt.sca(ax) plotter.plot_hb_profiles(si) plotter.plot_hb_mean_pm_std(si) plotter.restrict_x_limits_to_defined_values(si) annotate_axis_corner(ax, annotation) e_string = '_'.join(['{:d}'.format(si) for si in sids]) plotname = 'plotHbSimulatedEdges_e_{:s}'.format(e_string) figOptions.saveFig(plotname) else: for si in sids: plt.clf() plotter.plot_hb_profiles(si) plotter.plot_hb_mean_pm_std(si) if integrated_profiles: plotter.plot_hb_profile_integrated(si) plotter.restrict_x_limits_to_defined_values(si) n_profiles = plotter.n_profiles(si) plotname = 'plotHbSimulatedEdges_e_{:d}_n_{:d}'.format(si, n_profiles) figOptions.saveFig(plotname) plt.clf()
path_to_study_file = os.path.join(path_to_parameter_studies, study, file_name) param_study = ParameterStudyFactory().makeParameterStudy( path_to_study_file) postprocessor = make_param_study_post_processor(param_study) plotter = DiffusiveInteractionParameterStudyPlotter( postprocessor, fig_options, model_names) plt.sca(ax) plotter.plotComparisonSaturationDifferenceDecayTime(color=color) ax.xaxis.label.set_color(color) for t1 in ax.get_xticklabels(): t1.set_color(color) # adapt axes limits and tick locations ax2.set_ylim(100, 200) ax2.yaxis.set_major_locator(MultipleLocator(20)) ax3.set_ylim(100, 200) ax3.yaxis.set_major_locator(MultipleLocator(20)) ax2.xaxis.set_major_locator(MultipleLocator(0.2)) # RBC velocity ax3.xaxis.set_major_locator(MultipleLocator(0.4)) # M_0 # if panel_layout[0] == 1: # ax3.set_ylabel('') # ax3.tick_params(labelleft='off') annotate_axis_corner(ax1, 'A', xy=(0.90, 0.88)) annotate_axis_corner(ax2, 'B', xy=(0.90, 0.88)) annotate_axis_corner(ax3, 'C', xy=(0.90, 0.88)) fig_options.saveFig('plotDecayTimesDiffusiveInteractionTheoreticalAndTwinAxes')
parser.add_argument('--paramFile', help='Path to parameter study file', default='params.json') parser.add_argument('--manual-labels', action='store_true', help='Whether to set manually the contour labels') parser.add_argument('--settingsFile', help='Relative path to the file with postprocessing settings', default='postprocess.json') fig_options = FigureOptions(parser) args = parser.parse_args() file_name = args.paramFile manual_labels = args.manual_labels settings_file = args.settingsFile fig_options.parseOptions(args) fig, axs = plt.subplots(1, 2, sharey=True) twin_axs = [] for study, ax, text in zip(studies, axs, annotations): path_to_study_file = os.path.join(path_to_parameter_studies, study, file_name) param_study = ParameterStudyFactory().makeParameterStudy(path_to_study_file) postprocessor = make_param_study_post_processor(param_study) plotter = PlasmaOxygenationParamStudyPlotter(postprocessor, fig_options) plt.sca(ax) plotter.contour_delta_po2(manual_labels=manual_labels) twin_axs.append(plt.gca()) # hack to get the twin axes annotate_axis_corner(ax, text, xy=(0.94, 0.92)) twin_axs[0].set_ylabel('') twin_axs[0].set_yticklabels([]) axs[1].set_ylabel('') fig_options.saveFig('plotPlasmaOxygenation_rc_1.5um_2.0um')
help='Maximal time difference used for the linear fit') figOptions = FigureOptions(parser) args = parser.parse_args() case_name = args.caseName eids = args.edgeIndices n_profile_min = args.nProfileMin time_diff_max_fit = args.timeDiffMaxFit figOptions.parseOptions(args) postprocessor = make_post_processor(case_name) plotter = HemoglobinOnSegmentsPlotter(postprocessor, n_profile_min=n_profile_min) fig, axs = plt.subplots(len(eids), 2) flattened_axs = [ax for sublist in axs for ax in sublist] for i, (ei, annot) in enumerate(zip(eids, annotations)): plt.sca(axs[i, 0]) plotter.plot_hb_profiles(ei) plotter.plot_hb_mean_pm_std(ei) plotter.restrict_x_limits_to_defined_values(ei) annotate_axis_corner(axs[i, 0], annot[0]) plt.sca(axs[i, 1]) plotter.plot_hb_drop_vs_time_to_previous_rbc(ei, threshold=time_diff_max_fit) annotate_axis_corner(axs[i, 1], annot[1]) e_string = '_'.join(['{:d}'.format(ei) for ei in eids]) figOptions.saveFig( 'plotHbProfilesWithDropVsRBCSpacing_e_{:s}'.format(e_string))