Example #1
0
def DoGetMurrayForSingleFile(fn, pattern):
    vesselgrp_before = fn['adaption/recomputed']
    result = ku.get_Murray(ku.find_lattice_group_(vesselgrp_before),
                           vesselgrp_before)
    vesselgrp_after = fn['adaption/vessels_after_adaption']
    result_after = ku.get_Murray(ku.find_lattice_group_(vesselgrp_after),
                                 vesselgrp_after)
    #print result
    max_before = np.max(result[0, :])
    max_after = np.max(result_after[0, :])
    xmax = np.ceil(np.fmax(max_before, max_after))
    x = np.arange(0, xmax, 0.1)
    y = x
    fig1, (ax1, ax2) = plt.subplots(2, 1, sharex=True, sharey=True)

    #fig1.suptitle('this is the figure title', fontsize=12)
    ax1.set_title('Murray for \n%s\n%i points considered' %
                  (os.path.basename(afile.filename), result.shape[1]))
    #plt.subplot(2,1,1)
    ax1.scatter(result[0, :], np.sqrt(result[1, :]**2 + result[2, :]**2))
    ax1.set_xlabel('radius mother/ daughter vessel')
    ax1.set_ylabel(r"$\sqrt{r_a^2+r_b^2}$")
    #plt.title('Murray for \n%s\n%i points considered' % (os.path.basename(afile.filename),result.shape[1]))
    ax1.plot(x, y, 'k')
    ax1.grid()
    ax1.legend(['murray', 'before_data'], loc=4)
    #      plt.subplot(2,1,2)
    ax2.scatter(result_after[0, :],
                np.sqrt(result_after[1, :]**2 + result_after[2, :]**2))
    #ax2.set_xlabel('radius mother/ daughter vessel')
    ax2.set_ylabel(r"$\sqrt{r_a^2+r_b^2}$")
    #plt.title('Murray for \n%s\n%i points considered' % (os.path.basename(afile.filename),result.shape[1]))
    ax2.plot(x, y, 'k')
    ax2.legend(['murray', 'after_data'], loc=4)
    ax2.grid()
    plt.savefig('murray_%s.png' % os.path.basename(afile.filename))
Example #2
0
def DoGetMurrayForSingleFileGENERAL(fn, pattern, pdfpages):
    afile = h5files.open(fn, 'r')
    vesselgrp = afile[pattern]
    print(vesselgrp)
    result_venous, result_a = ku.get_Murray(vesselgrp)
    #result = ku.get_Murray(vesselgrp, alpha)
    result_venous = removeZeros(result_venous)
    result_a = removeZeros(result_a)

    #x=np.arange(0,max_,0.1)
    #y=x
    #fig1, (ax1, ax2) = plt.subplots(2,1,sharex=True, sharey=True)
    fig1, (ax1, ax2) = plt.subplots(2, 1)
    ### plot murrays law with exponent
    alphas = np.arange(2, 6, 0.5)
    alphas = [3]
    max_ = np.max(result_venous[2, :])
    min_ = np.min(result_venous[0, :])
    x = np.arange(min_, max_, 0.1)
    font = {
        'family': 'serif',
        'color': 'black',
        'weight': 'normal',
        'size': 4,
        'rotation': 30,
        'verticalalignment': 'bottom',
        'horizontalalignment': 'left',
    }
    for alpha in alphas:
        ax1.text(x[-1], x[-1], r'$\alpha = %0.1f $' % alpha, fontdict=font)
        ax1.plot(x, x, c='k', linewidth=0.1)

    ### plot data
    ax1.set_title('%i venous points, %i arterial points' %
                  (result_venous.shape[1], result_a.shape[1]),
                  size=6)
    # ax1.set_title('Murray for file:\n%s\n%i venous points, %i arterial points' % (os.path.basename(afile.filename),result_venous.shape[1], result_a.shape[1]), size=6)
    pointsize = 0.1
    venous = ax1.scatter(np.power(
        result_venous[0, :]**3 + result_venous[1, :]**3, 1 / float(3)),
                         result_venous[2, :],
                         c='b',
                         s=pointsize,
                         label='bldk')
    arterial = ax1.scatter(np.power(result_a[0, :]**3 + result_a[1, :]**3,
                                    1 / float(3)),
                           result_a[2, :],
                           c='r',
                           s=pointsize)
    ax1.set_xlabel(r'$\sqrt[3]{r_{daughter_1}^3 + r_{daughter_2}^3}$')
    ax1.set_ylabel(r'$r_{mother}$')
    ax1.legend((venous, arterial), ('Venous', 'Arterial'), loc='lower right')
    ax1.grid()

    ### histogramm deviation of daughters
    hist, bin_edges = np.histogram(
        result_a[1, :] - result_a[0, :],
        bins=50)  #note. they are sorted in on c++ side
    width = 0.7 * (bin_edges[1] - bin_edges[0])
    centers = (bin_edges[:-1] + bin_edges[1:]) / 2
    ax2.bar(centers,
            hist / float(len(result_a[0, :])),
            align='center',
            width=width,
            color='red')
    ax2.set_xlabel(r'$\|r_{daughter 1}- r_{daughter 2}\|$')
    ax2.set_ylabel(r'$p$')
    fig1.tight_layout()
    pdfpages.savefig(fig1)
Example #3
0
def DoGetMurray(filenames, pdfpages):
    alpha = 3
    filenames = adaption.get_files_with_successful_adaption(filenames)
    files = [h5files.open(fn, 'r') for fn in filenames]
    for afile in files:
        print("consider file: %s " % afile.filename)
        if ('adaption/recomputed' in afile):
            vesselgrp_before = afile['adaption/recomputed']
        if ('vessels/recomputed_flow' in afile):
            vesselgrp_before = afile['vessels/recomputed_flow']
        if (not 'vesselgrp_before' in locals()):
            print("bad")
        if ('results' in locals()):
            results = np.hstack(
                (results, ku.get_Murray(vesselgrp_before, alpha)))
        else:
            results = ku.get_Murray(vesselgrp_before, alpha)
        vesselgrp_after = afile['adaption/vessels_after_adaption']
        if ('results_after' in locals()):
            results_after = np.hstack(
                (results_after, ku.get_Murray(vesselgrp_after, alpha)))
        else:
            results_after = ku.get_Murray(vesselgrp_after, alpha)

    results = removeZeros(results)
    results_after = removeZeros(results_after)
    #print result
    max_before = np.amax(results)
    max_after = np.amax(results_after)
    xmax = np.ceil(np.fmax(max_before, max_after))
    x = np.arange(0, xmax, 0.1)
    y = x
    fig1, (ax1, ax2) = plt.subplots(2, 1, sharex=True, sharey=True)
    fig2, (ax3, ax4) = plt.subplots(2, 1, sharex=True, sharey=True)
    #fig2 = plt.hist(results[0,:]-results[1,:],20)
    #fig1.suptitle('this is the figure title', fontsize=12)
    ax1.set_title('Murray for \n%s\n%i points considered' %
                  (os.path.basename(afile.filename), results.shape[1]))
    #plt.subplot(2,1,1)
    ax1.scatter(results[0, :], results[1, :])
    #ax1.set_xlabel('daughter vessel')
    ax1.set_ylabel('mother')
    #plt.title('Murray for \n%s\n%i points considered' % (os.path.basename(afile.filename),result.shape[1]))
    ax1.plot(x, y, 'k')
    ax1.grid()
    ax1.legend(['murray', 'before_data'], loc=4)
    #      plt.subplot(2,1,2)
    ax2.scatter(results_after[0, :], results_after[1, :])
    ax2.set_xlabel(r"daughter $\sqrt{\sum_ir_i^2}$")
    #ax2.set_ylabel(r"$\sqrt{r_a^2+r_b^2}$")
    #plt.title('Murray for \n%s\n%i points considered' % (os.path.basename(afile.filename),result.shape[1]))
    ax2.plot(x, y, 'k')
    ax2.legend(['murray', 'after_data'], loc=4)
    ax2.grid()
    pdfpages.savefig(fig1)
    #fig1.savefig('murray_%s.png' % os.path.basename(afile.filename))

    hist, bin_edges = np.histogram(results[0, :] - results[1, :], bins=50)
    width = 0.7 * (bin_edges[1] - bin_edges[0])
    centers = (bin_edges[:-1] + bin_edges[1:]) / 2
    ax3.bar(centers, hist, align='center', width=width)

    hist_after, bin_edges = np.histogram(
        results_after[0, :] - results_after[1, :], bin_edges)
    ax4.bar(centers, hist_after, align='center', width=width)
    #fig2.savefig('dens_murray_%s.png' % os.path.basename(afile.filename))
    pdfpages.savefig(fig2)