Beispiel #1
0
 def __call__(self, name, v):
     avg, std = np.average(v, axis=0), np.std(v, axis=0)
     #if exponent is not None:
     exponent = Format.exponents[name]
     multi = Format.multi[name]
     if exponent:
         exponent_str = ('\,10^{%i}' % exponent) if exponent <> 0 else ''
         f = math.pow(10., exponent)
         s = r'%s \pm %s%s' % (f2l(avg / f * multi, exponential=False),
                               f2l(std / f * multi,
                                   exponential=False), exponent_str)
     else:
         s = r'%s \pm %s\,' % (f2l(avg * multi), f2l(std * multi))
     return s
Beispiel #2
0
def GenerateGlobalMeasurementOutputStrings(dataman, po2group, cachelocation):
  prop_list = ['gtv', 'jtv','mro2', 'po2_tissue', 'oef', 'e1', 'e3', 'Jin_root', 'Jout_root', 'Jout_tv', 'Jout_cons']

  Get = lambda prop: dataman.obtain_data('detailedPO2_global', prop, po2group, sample_length, cachelocation)
  data = map(Get, prop_list)
  Fmt = lambda (name, val): r'$%s = %s$ %s' % (Prettyfier.get_sym(name), f2l(val), Prettyfier.get_munit_legacy(name))
  result_string = map(Fmt, zip(prop_list, data))
  return result_string
Beispiel #3
0
 def fmt_axis_labels(ax, name, scalefactor=None, hidex=True):
     ax.set(
         ylabel=(r'$%s$ %s' %
                 (Prettyfier.get_sym(name), Prettyfier.get_bunit(name))) +
         ((r' $\times\, %s$' %
           f2l(scalefactor, exponential=True)) if scalefactor else ''),
         title=Prettyfier.get_label(name))
     if hidex: ax.set(xticklabels=[])
     else:
         xsym = r'\phi' if distance_distribution_name == 'levelset' else r'|x|'
         ax.set(xlabel=r'$%s$ [$mm$]' % xsym)
Beispiel #4
0
def FormatParameters(root):
    from quantities import Prettyfier
    parametergroup = root['parameters']
    parameters = dict(parametergroup.attrs)
    parameters = sorted(parameters.items(), key=lambda (k, v): k)
    result = ['++++ Vessel Network Creation Parameters ++++']
    for k, v in parameters:
        k = 'vgp_' + k
        try:
            name, sym, unit = Prettyfier.get_label(k), Prettyfier.get_msym(
                k), Prettyfier.get_munit(k)
        except KeyError:
            continue
        if isinstance(v, float):
            v = f2l(v)
        else:
            v = str(v)
        #name = name.ljust(60)
        #print len(name)
        result.append('%s:\n%s = $%s$ %s' % (name, sym, v, unit))
    return result
Beispiel #5
0
def fmt(name, sym, value, unit):
  value = f2l(value)
  if unit:
    value = '%s %s' % (mm_(value), mm_(unit))
  return '%s %s = %s' % (name, mm_(sym), value)
Beispiel #6
0
  fn = 'vessel-single-all.h5'
  #os.unlink(fn)
  f = h5files.open(fn,'a')
  
  GenerateSingleCapillaryWPo2(dataman, f, 'nair_uptake', 14, singleVesselParameterSets.nair_uptake)
  plot_single_capillary(dataman, f['nair_uptake'], useInsets = True)

  GenerateSingleCapillaryWPo2(dataman, f, 'nair_release', 14, singleVesselParameterSets.nair_release)
  plot_single_capillary(dataman, f['nair_release'], useInsets = True)

  grouplist = []
  for name in [ 'moschandreou_case%02i' % i for i in xrange(6) ]:
    params = getattr(singleVesselParameterSets, name)
    r = params.paramsTube['r']
    label = 'r = %s' % f2l(r)
    GenerateSingleCapillaryWPo2(dataman, f, name, 14, params)
    grouplist.append((f[name], label))
  compare_single_capillary2(dataman, 'moschandreou_cases', grouplist, None)
  plot_single_capillary(dataman, f['moschandreou_case02'], useInsets = True)

  GenerateSingleCapillaryWPo2(dataman, f, 'moschandreou_extra_long', 14, singleVesselParameterSets.moschandreou_extra_long)
  plot_single_capillary_long(dataman, f['moschandreou_extra_long'], useInsets = True)

#  GenerateSingleCapillaryWPo2(dataman, f, 'moschandreou_diag_base', 14, singleVesselParameterSets.moschandreou_diag_base)
#  GenerateSingleCapillaryWPo2(dataman, f, 'moschandreou_diag'    , 14, singleVesselParameterSets.moschandreou_diag)
#  compare_single_capillary2(dataman, 'moschandreou_diag', [(f['moschandreou_diag_base'], 'parallel'),
#                                                          (f['moschandreou_diag'], 'diag')], None)

#  GenerateSingleCapillaryWPo2(dataman, f, 'test_thin', 7, singleVesselParameterSets.basecase)
#  GenerateSingleCapillaryWPo2(dataman, f, 'test_straight', 7, singleVesselParameterSets.test_straight)
Beispiel #7
0
def fmt_(b):
    for i, c in enumerate('xyz'):
        yield '%s = %s .. %s mm' % (c, f2l(b[0][i] * 1.e-3, exponential=False),
                                    f2l(b[1][i] * 1.e-3, exponential=False))
Beispiel #8
0
 def printstuff_(sym, a, mult, unit=''):
     text.append('$%s$ = $%s \pm %s$ %s' %
                 (sym, f2l(np.average(a) * mult, exponential=False),
                  f2l(np.std(a) * mult, exponential=False), unit))
def PlotRadialCurves(pdfwriter, bins_spec, snapshotlist, measurementinfo,
                     world_size):
    charsize = 12 / 90.
    figscale = mpl_utils.a4size[0] * 0.33
    fig, axes = pyplot.subplots(2,
                                2,
                                dpi=90,
                                figsize=(figscale * 2, figscale * 1.5))
    mpl_utils.subplots_adjust_abs(fig,
                                  left=4 * charsize,
                                  right=-2 * charsize,
                                  top=-3. * charsize,
                                  bottom=5. * charsize,
                                  hspace=8. * charsize,
                                  wspace=12 * charsize)
    axes = axes.ravel()

    bins = bins_spec.arange() * 1.e-3

    FmtTime = lambda time: 't=' + f2l(round(time))

    default_colors = 'rgbcmyk'

    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 fmt_axis_labels(ax, name, scalefactor=None, hidex=True):
        ax.set(
            ylabel=(r'$%s$ %s' %
                    (Prettyfier.get_sym(name), Prettyfier.get_bunit(name))) +
            ((r' $\times\, %s$' %
              f2l(scalefactor, exponential=True)) if scalefactor else ''),
            title=Prettyfier.get_label(name))
        if hidex: ax.set(xticklabels=[])
        else:
            xsym = r'\phi' if measurementinfo[
                'distancemap_spec'] == 'levelset' else r'|x|'
            ax.set(xlabel=r'$%s$ [$mm$]' % xsym)


#  if measurementinfo.distancemap_spec == 'radial':
#    axtwin = axes[0].twinx()
#    plot(axtwin, 'theta_tumor', colors = [(0.5,0.5,0.5)]*7, errorbars=False)

    plot(axes[0], 'mvd', label=True)
    fmt_axis_labels(axes[0], 'mvd')
    theLegend = axes[0].legend(loc='lower right', prop={'size': 6})
    #theLegend.get_title().set_fontsize('2')
    #pyplot.setp(axes[0].get_legend().get_texts(),fontsize='2')
    theLegend.__sizes = [1]

    plot(axes[1], 'phi_vessels')
    fmt_axis_labels(axes[1], 'phi_vessels')

    plot(axes[2], 'radius')
    fmt_axis_labels(axes[2], 'radius', hidex=False)

    plot(axes[3], 'velocity', scalefactor=1.0e-3)
    fmt_axis_labels(axes[3], 'velocity_mm', hidex=False)

    pdfwriter.savefig(fig, postfix='_o2radial')