Exemplo n.º 1
0
def colorbar(fig, axes, theplot, height="50%", **kwargs):
    #  axins = mpl_utils.inset_axes(
    #    axes,
    #    width = "3%",
    #    height = height,
    #    loc=2
    #  )
    divider = mpl_utils.make_axes_locatable(axes)
    cax = divider.append_axes("right", size="5%", pad=0.05)
    return fig.colorbar(theplot, cax=cax, **kwargs), cax
Exemplo n.º 2
0
    thegrad = np.sqrt(thegrad)
    del gradfield_

    if SHOW_BLURRED_IMAGES:
        kernel = (1.0 / 64.0) * np.ones((4, 4, 4), dtype=np.float32)
        thefield = sig.fftconvolve(thefield, kernel)
        volfraction = sig.fftconvolve(volfraction, kernel)
        thegrad = sig.fftconvolve(thegrad, kernel)

    z = fieldld.shape[2] / 2

    fig, axes = pyplot.subplots(2, 2)
    ax = axes[0, 0]
    plt = ax.imshow(thefield[:, :, z])
    ax.set(title='pressure')
    divider = mpl_utils.make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad=0.05)
    fig.colorbar(plt, cax=cax)

    ax = axes[0, 1]
    plt = ax.imshow(volfraction[:, :, z])
    ax.set(title='volume fraction')
    divider = mpl_utils.make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad=0.05)
    fig.colorbar(plt, cax=cax)

    ax = axes[1, 0]
    plt = ax.imshow(thegrad[:, :, z])
    ax.set(title='gradient magnitude')
    divider = mpl_utils.make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad=0.05)
Exemplo n.º 3
0
def sample_vessel_system(goodArguments):
    filename = goodArguments.vesselFileNames
    grouppath = goodArguments.grp_pattern

    with h5py.File(filename, 'r') as file:
        if ('vessels' in grouppath):
            print('found vessels!')
            vesselgroup = file[grouppath]
        else:
            if ('out' in grouppath):
                outgroup = file[grouppath]
                print('found tumor of type: %s' %
                      str(outgroup['tumor'].attrs.get('TYPE')))
                vesselgroup = file[grouppath + '/vessels']
            else:
                print("unknown data structure!")
        ldvessels = krebsutils.read_lattice_data_from_hdf(
            vesselgroup['lattice'])
        wbbox = ldvessels.worldBox

        graph = krebsutils.read_vesselgraph(vesselgroup, ['position', 'flags'])
        graph = graph.get_filtered(
            myutils.bbitwise_and(graph['flags'], krebsutils.CIRCULATED))

    print 'vessel ld:'
    print ldvessels
    ''' this splits splits space in lattices of 300.
      the second 300 adds a 'safety layer of 100. mum
      so we do not consider the outermost data for calculating the
      actual mvd
  '''
    sampling_lattice_spacing = goodArguments.sampling_lattice_spacing
    fieldld = krebsutils.SetupFieldLattice(wbbox, 3, sampling_lattice_spacing,
                                           100.)
    wbbox = fieldld.worldBox
    print 'field ld:'
    print fieldld
    z = fieldld.shape[2] / 2

    longitudinal_sampling_distance = goodArguments.longitudinal
    weights = krebsutils.sample_edges_weights(graph.nodes['position'],
                                              graph.edgelist,
                                              longitudinal_sampling_distance)
    positions = krebsutils.sample_edges(
        graph.nodes['position'], graph.edgelist, graph.nodes['position'],
        longitudinal_sampling_distance,
        krebsutils.VesselSamplingFlags.DATA_PER_NODE
        | krebsutils.VesselSamplingFlags.DATA_LINEAR)

    eps = 1.0 - 1.e-15
    x0, x1, y0, y1, z0, z1 = wbbox
    ranges = [
        np.arange(x0, x1, fieldld.scale * eps),
        np.arange(y0, y1, fieldld.scale * eps),
        np.arange(z0, z1, fieldld.scale * eps),
    ]
    print 'histogram bin ends:', map(lambda r: (r.min(), r.max()), ranges)
    mvd, _ = np.histogramdd(positions, bins=ranges, weights=weights)
    mvd *= 1.e6 / (fieldld.scale**3)
    print 'result shape:', mvd.shape
    print('average mvd')
    print(np.mean(mvd[1:-1, 1:-1, 1:-1]))
    ''' new stuff '''
    from scipy import ndimage

    bool_field = mvd > 0
    bool_field = np.logical_not(bool_field)
    distance_map = ndimage.morphology.distance_transform_edt(bool_field)
    distance_map = distance_map * sampling_lattice_spacing

    #  fig, ax = pyplot.subplots(1)
    #  plt = ax.imshow(mvd[:,:,z], interpolation = 'none')
    #  ax.set(title = 'MVD')
    #  divider = mpl_utils.make_axes_locatable(ax)
    #  cax = divider.append_axes("right", size = "5%", pad = 0.05)
    #  fig.colorbar(plt, cax = cax)

    fig, ax = pyplot.subplots(1)
    plt = ax.imshow(distance_map[:, :, z], interpolation='none')
    #ax.set(title = 'Distance Map \n group: %s, file: %s' %(grouppath, filename))
    ax.set(title='Distance Map \n smp_logitudinal: %s, lattice_const: %s' %
           (longitudinal_sampling_distance, sampling_lattice_spacing))
    divider = mpl_utils.make_axes_locatable(ax)
    cax = divider.append_axes("right", size="5%", pad=0.05)
    fig.colorbar(plt, cax=cax)
    basename(filename)
    with PdfPages('distmap_' + basename(filename) + '_' + grouppath +
                  '.pdf') as pdf:
        pdf.savefig(fig)