def plot(ax, name, scalefactor=1., label=None, colors=default_colors, errorbars=True, zero_ylim=True): for i, path in enumerate(pathorder): curve = curves_by_path_and_name[path, name] label = labels_by_path[path] if label else None mask = ~curve.avg.mask if errorbars: mpl_utils.errorbar(ax, bins[mask], scalefactor * curve.avg[mask], yerr=scalefactor * curve.std_mean[mask], label=label, marker=None, color=colors[i], every=2) else: ax.plot(bins[mask], scalefactor * curve.avg[mask], label=label, color=colors[i]) if zero_ylim: _, ymax = ax.get_ylim() ax.set_ylim((0., ymax)) if distance_distribution_name == 'levelset': ax.set(xlim=(-2., 2.)) mpl_utils.add_crosshair(ax, (0., None), ls=':') else: ax.set(xlim=(0., rmax)) for i, path in enumerate(pathorder): mpl_utils.add_crosshair( ax, (curves_by_path_and_name[path, 'approximate_tumor_radius'].avg * 1.e-3, None), ls=':')
def plot(ax, name, scalefactor=1., label=None, colors=default_colors, errorbars=True, zero_ylim=True): for color, i, (time, tumor_radius, curves) in itertools.izip(itertools.cycle(colors), itertools.count(), snapshotlist): curve = myutils.MeanValueArray.fromSummation( map(lambda x: x.avg, curves[name])) label = FmtTime(time) mask = ~curve.avg.mask if errorbars: mpl_utils.errorbar(ax, bins[mask], scalefactor * curve.avg[mask], yerr=scalefactor * curve.std_mean[mask], label=label, marker=None, color=color, every=2) else: ax.plot(bins[mask], scalefactor * curve.avg[mask], label=label, color=colors[i]) if zero_ylim: _, ymax = ax.get_ylim() ax.set_ylim((0., ymax)) if measurementinfo['distancemap_spec'] == 'levelset': ax.set(xlim=(-2., 2.)) mpl_utils.add_crosshair(ax, (0., None), ls=':') else: mpl_utils.add_crosshair(ax, (0.5e-3 * world_size[0], None)) ax.set(xlim=(0, 0.5e-3 * world_size[0])) for color, i, (time, tumor_radius, curves) in itertools.izip(itertools.cycle(colors), itertools.count(), snapshotlist): mpl_utils.add_crosshair(ax, (tumor_radius * 1.e-3, None), ls=':', color=color)
def plot_many(filenames, pdfpages): groups_by_time = defaultdict(list) files = [h5py.File(fn, 'r') for fn in filenames] for f in files: groups = myutils.getTimeSortedGroups(f['.']) for g in groups: groups_by_time[round(g.attrs['time'])].append(g) times = groups_by_time.keys() times.sort() times = np.asarray(times) radius, radius_std = averaged_global((groups_by_time, times), 'geometry/radius') volume, volume_std = averaged_global((groups_by_time, times), 'geometry/volume') sphere_equiv_radius, sphere_equiv_radius_std = averaged_global( (groups_by_time, times), 'geometry/sphere_equiv_radius') #sphere_equiv_radius, sphere_equiv_radius_std = averaged_global((groups_by_time, times), 'geometry/cylinder_equiv_radius') sphericity, sphericity_std = averaged_global((groups_by_time, times), 'geometry/sphericity') # estimate velocity data = np.asarray((times, radius)) if len(data[0]) > 1: from scipy.optimize import leastsq func = lambda p, x, y: (x * p[0] + p[1] - y) p, success = leastsq(func, (1, 0), args=(data[0], data[1])) velocity = p[0] print 'estimated velocity: %f' % velocity print 'fit params: %s' % str(p) else: velocity = 0. if 1: #plot by time fig, axes = pyplot.subplots(2, 2, figsize=(mastersize[0] * 0.5, mastersize[0] * 0.5)) mpl_utils.subplots_adjust_abs( fig, left=mpl_utils.mm_to_inch * 13, right=-mpl_utils.mm_to_inch * 5, top=-mpl_utils.mm_to_inch * 5, bottom=mpl_utils.mm_to_inch * 10, hspace=mpl_utils.mm_to_inch * 30, wspace=mpl_utils.mm_to_inch * 40, ) axes = axes.ravel() def plt_rad(ax): ax.set(ylabel='[mm]', xlabel='t [h]') mpl_utils.errorbar(ax, times, 1.e-3 * radius, yerr=1.e-3 * radius_std, label='r', lw=0., marker='x', color='k', markersize=5.) label = u'$r_0 + v_{fit} t$\n$v_{fit} = %s$ [\u03BCm/h]' % f2s( velocity) ax.plot(times, 1.e-3 * (p[1] + p[0] * times), label=label, color='r') ax.legend() #ax.text(0.6, 0.2, r'$v_{fit} = %s$' % f2s(velocity), transform = ax.transAxes) def plt_vol(ax): ax.set(ylabel='volume', xlabel='t [h]') ax.errorbar(times, 1.e-9 * volume, yerr=1.e-9 * volume_std) def plt_sprad(ax): ax.set(ylabel='sphere equiv. radius', xlabel='t [h]') ax.errorbar(times, 1.e-3 * sphere_equiv_radius, yerr=1.e-3 * sphere_equiv_radius_std) def plt_sphereicity(ax): ax.set(ylabel='sphericity', xlabel='t [h]') ax.errorbar(times, sphericity, yerr=sphericity_std) for ax, func in zip(axes, [plt_rad, plt_vol, plt_sprad, plt_sphereicity]): l = MaxNLocator(nbins=4) ax.xaxis.set_major_locator(l) func(ax) pdfpages.savefig(fig) times = times[0::2] radial = averaged_radial((groups_by_time, times), 'vs_dr', [ 'phi_tumor', 'mvd', 'radius', 'shearforce', 'flow', 'sources', 'vel', 'oxy', 'maturation' ]) bins = np.asarray(groups_by_time[times[0]][0]['radial/vs_dr/bins']) bins *= 1. / 1000. xlim = -1.5, 1.0 mask = np.logical_and(bins < xlim[1], bins >= xlim[0]) def plot_times(ax, name, **kwargs): f = kwargs.pop('value_prefactor', 1.) colors = 'rgbmk' markers = 'os<>d' for i, t in enumerate(times): avg, std = radial[name, t] avg, std = avg[mask], std[mask] #ax.errorbar(bins[mask], f*avg, yerr=f*std, label = 't = %s' % f2s(t), **kwargs) mpl_utils.errorbar(ax, bins[mask], f * avg, yerr=f * std, label='t = $%s$' % f2s(t), marker=markers[i], color=colors[i], every=5, **kwargs) def text1(ax, txt): ax.text(0.95, 0.9, txt, ha="right", transform=ax.transAxes) def text2(ax, txt): ax.text(0.01, 0.9, txt, ha="left", transform=ax.transAxes) def mkfig(nrows, ncols): fig, axes = mpl_utils.subplots_abs_mm( (mastersize[0] / mpl_utils.mm_to_inch * 0.5 * ncols, mastersize[0] / mpl_utils.mm_to_inch * 0.2 * nrows), nrows, ncols, 10, 20, a4size[0] / mpl_utils.mm_to_inch * 0.38, a4size[0] / mpl_utils.mm_to_inch * 0.16, 15, 5) return fig, axes # fig, axes = pyplot.subplots(4, 2, figsize = (mastersize[0], mastersize[0]*0.25*4.)) # mpl_utils.subplots_adjust_abs(fig, left = mpl_utils.mm_to_inch*20, # right = -mpl_utils.mm_to_inch*10, # top = -mpl_utils.mm_to_inch*5, # bottom = mpl_utils.mm_to_inch*10, # hspace = mpl_utils.mm_to_inch*30,) def plt_mvd(ax): # mvd can be written as N^3 * L0/N * 3 / V = (V=L0^3) ... = N^2 / L0^2 ax.set(ylabel=ur'$\times 10^3$ [\u03BCm$^{-2}$]', xlim=xlim) plot_times(ax, 'mvd', value_prefactor=1e3) text1(ax, r'$L/V$') ax.legend(loc=mpl_utils.loc.lower_left, frameon=True) def plt_rad(ax): ax.set(ylabel=ur'[\u03BCm]', xlim=xlim) plot_times(ax, 'radius') text1(ax, r'$r_v$') def plt_vel(ax): ax.set(ylabel=ur'[\u03BCm/h]', xlim=xlim) text1(ax, r'$v_\phi$') plot_times(ax, 'vel') def plt_tum(ax): ax.set(ylabel=ur'', xlim=xlim, ylim=(-0.1, 0.7)) plot_times(ax, 'phi_tumor') text1(ax, r'$\phi_t$') def plt_oxy(ax): ax.set(ylabel=ur'', xlim=xlim) plot_times(ax, 'oxy') text1(ax, r'$c_o$') def plt_sf(ax): ax.set(ylabel=ur'[Pa]', xlim=xlim) plot_times(ax, 'shearforce', value_prefactor=1e3) text1(ax, r'$f_v$') def plt_wall(ax): ax.set(ylabel=ur'[\u03BCm]', xlim=xlim) plot_times(ax, 'maturation') text1(ax, r'$w_v$') def plt_qv(ax): ax.set(ylabel=ur'[\u03BCm]', xlim=xlim) ax.set(xlabel=ur'$\theta$ [mm]') plot_times(ax, 'flow') text1(ax, r'$q_v$') fig, axes = mkfig(3, 2) plt_mvd(axes[0, 0]) plt_rad(axes[0, 1]) plt_vel(axes[1, 0]) plt_oxy(axes[1, 1]) plt_wall(axes[2, 0]) plt_sf(axes[2, 1]) for ax in axes[2, :]: ax.set(xlabel=ur'$\theta$ [mm]') axes = axes.ravel() for i, ax in enumerate(axes): ax.grid(linestyle=':', linewidth=0.5, color=gridcolor) mpl_utils.add_crosshair(ax, (0, 0), color=gridcolor) if not ax.get_xlabel(): ax.set(xticklabels=[]) text2(ax, '(%s)' % 'abcdefghij'[i]) pdfpages.savefig(fig)
mpl_utils.subplots_adjust_abs( fig, left=mpl_utils.mm_to_inch * 20, right=-mpl_utils.mm_to_inch * 10, top=-mpl_utils.mm_to_inch * 5, bottom=mpl_utils.mm_to_inch * 10, hspace=mpl_utils.mm_to_inch * 30, ) ax = axes[0] ax.set(xticklabels=[]) ax.set(ylabel=r'[kPa]') plot('iff_pressure', label=r'$p_i$', marker='o', color='r') #plot('ivp', label = '$p_v$', marker = 's', color = 'k') #plot('ivp_minus_ifp', label = '$p_v - p_i$', marker='>', color = 'b') #end pressure ax = axes[1] ax.set(ylabel=ur'[\u03BCm/s]' ) #, xlabel = r'$\theta$ [mm]', title = 'velocity') ax.set(xticklabels=[]) # plot('iff_velocity_out', label = r'$v_{||}$', marker = 'o', color = 'r') # plot('iff_velocity_mag', label = r'$|v|$', marker = 's', color = 'b') ax.legend() gridcolor = (0.7, 0.7, 0.7) for ax in axes: ax.set_xlim(*xlim) ax.grid(linestyle=':', linewidth=0.5, color=gridcolor) mpl_utils.add_crosshair(ax, (0, 0), color=gridcolor) pyplot.show()