Ejemplo n.º 1
0
 def test_terminal_br(self):
     eldata = placentagen.import_exelem_tree(TESTDATA_FILENAME1)
     noddata = placentagen.import_exnode_tree(TESTDATA_FILENAME)
     term_br = placentagen.calc_terminal_branch(noddata['nodes'],
                                                eldata['elems'])
     print(term_br['terminal_elems'])
     self.assertTrue(term_br['terminal_elems'][0] == 1)
Ejemplo n.º 2
0
 def test_terminal_elems_present(self):
     noddata = placentagen.import_exnode_tree(TESTDATA_FILENAME)
     term_br={}
     term_br['terminal_nodes']=[3]
     term_br['total_terminals']=1
     rectangular_mesh = {}
     rectangular_mesh['nodes'] =np.array( [[ 0.,  0.,  0.],[ 1.,  0. , 0.],[ 0.,  1. , 0.],[ 1. , 1. , 0.],[ 0.,  0. , 1.],[ 1.,  0. , 1.],[ 0. , 1. , 1.],[ 1. , 1. , 1.]])
     rectangular_mesh['elems']=[[0, 0, 1, 2, 3, 4, 5, 6, 7]]
     term_grid =placentagen.terminals_in_sampling_grid_fast(rectangular_mesh, term_br, noddata['nodes'])
     self.assertTrue(term_grid['terminal_elems'][0] == 0)#this zero does not mean branch are not located. it means samp_grid el 0
Ejemplo n.º 3
0
 def test_terminals_elem_general_absent(self):
     noddata = placentagen.import_exnode_tree(TESTDATA_FILENAME)
     eldata = placentagen.import_exelem_tree(TESTDATA_FILENAME1)
     term_br = placentagen.calc_terminal_branch(noddata['nodes'], eldata['elems'])
     placenta_list = [1]
     rectangular_mesh = {}
     rectangular_mesh['elems'] = np.zeros((8, 9), dtype=int)
     rectangular_mesh['nodes'] = [[0., -1., -1.], [1., -1., -1.], [0., 0., -1.], [1., 0., -1.], [0., -1., 0.],
                                  [1., -1., 0.], [0., 0., 0.], [1., 0., 0.]]
     rectangular_mesh['elems'][1] = [0, 0, 1, 2, 3, 4, 5, 6, 7]
     term_grid = placentagen.terminals_in_sampling_grid(rectangular_mesh, placenta_list, term_br, noddata['nodes'])
     self.assertTrue(
         np.sum(term_grid['terminal_elems']) == 0)  # all must be zero as could not locate any terminal br
Ejemplo n.º 4
0
 def test_terminals_elem_general_present(self):
     noddata = placentagen.import_exnode_tree(TESTDATA_FILENAME)
     term_br = {}
     term_br['terminal_nodes'] = [3]
     term_br['total_terminals'] = 1
     placenta_list = [7]
     rectangular_mesh = {}
     rectangular_mesh['elems'] = np.zeros((8, 9), dtype=int)
     rectangular_mesh['nodes'] = [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [1., 1., 0.], [0., 0., 1.], [1., 0., 1.],
                                  [0., 1., 1.], [1., 1., 1.]]
     rectangular_mesh['elems'][7] = [0, 0, 1, 2, 3, 4, 5, 6, 7]
     term_grid = placentagen.terminals_in_sampling_grid(rectangular_mesh, placenta_list, term_br, noddata['nodes'])
     self.assertTrue(term_grid['terminal_elems'][0] == 7)
Ejemplo n.º 5
0
    def test_term_br_loc(self):

        eldata = placentagen.import_exelem_tree(TESTDATA_FILENAME1)
        nodedata = placentagen.import_exnode_tree(TESTDATA_FILENAME)
        term_br = placentagen.calc_terminal_branch(nodedata['nodes'],
                                                   eldata['elems'])
        volume = 1  # mm^3
        thickness = 1  # mm
        ellipticity = 1.00  # no units
        spacing = 1.0  # mm
        rectangular_mesh = placentagen.gen_rectangular_mesh(
            volume, thickness, ellipticity, spacing, spacing, spacing)
        terminals_in_grid = placentagen.terminals_in_sampling_grid(
            rectangular_mesh, term_br, nodedata['nodes'])
        test_array = terminals_in_grid == [[0, 1, 0, 1]]
        self.assertTrue(test_array.all)
Ejemplo n.º 6
0
 def test_node_array_setup(self):
     nodedata = placentagen.import_exnode_tree(TESTDATA_FILENAME)
     node_array = nodedata['node_array']
     self.assertTrue(np.isclose(node_array[2][2], -0.5000000000000000E+01))
Ejemplo n.º 7
0
 def test_num_nodes(self):
     nodedata = placentagen.import_exnode_tree(TESTDATA_FILENAME)
     self.assertTrue(nodedata['total_nodes'] is 4)

nel_x=int(np.floor((x_radius*2)/2))#number of element in x aixs in pl mesh
nel_y=int(np.floor((y_radius*2)/2))#number of element in y axis in pl mesh
nel_z=int(np.floor((z_radius*2)/2))#number of element in z axis in pl mesh

strahler_order=1.53#strahler order
el_file='full.exelem'
node_file='full.exnode'
stem_file='stem_xy.txt'
velocity=26.5#mm3 per sec inlet and outlet vel of spiral artery and decidual vein
####################################################################################################################################
total_start = time.time()

#Read in exnode and exelem files desrcibing whole placenta tree
nodes_input=pg.import_exnode_tree(node_file)
elems_input=pg.import_exelem_tree(el_file)

#Define element radii by Strahler order
elem_radius = pg.define_radius_by_order(nodes_input['nodes'],elems_input['elems'],'strahler',0,start_radius,strahler_order)
pg.export_exfield_1d_linear(elem_radius, 'arteries', 'radius', 'artery_radius')

#Calculate location of terminal branches
terminal_branches = pg.calc_terminal_branch(nodes_input['nodes'],elems_input['elems'])

#define rectangular mesh
rectangular_mesh = pg.gen_rectangular_mesh(volume, thickness, ellipticity,spacing,spacing,spacing)
pg.export_ex_coords(rectangular_mesh['nodes'],'samplingmesh','sampling_mesh','exnode')
pg.export_exelem_3d_linear(rectangular_mesh['elems'],'samplingmesh','sampling_mesh')

start = time.time()
Ejemplo n.º 9
0
#chor_elem_in_file = home + '/placenta_patient_51/grow_tree/chor_elems_cycle3_v5.exelem'

#seed_points_in_file = home + '/placenta_patient_49/seed_points/p49_seed_points_uniform_10_step_9_final.exdata' #uniform distribution
seed_points_in_file = home + '/placenta_patient_49/seed_points/p49_seed_points_heterogeneous_7_12_18_final.exdata'

seed_points_option = 'read_in' #or 'generate'


if(export_intermediates or export_results):
    if not os.path.exists(export_directory):
        os.makedirs(export_directory)

#Import chorion and stem geometry
chorion_and_stem = {}

chorion_and_stem['nodes'] = pg.import_exnode_tree(chor_node_in_file)['nodes'][:, 0:4]
chorion_and_stem['elems'] = pg.import_exelem_tree(chor_elem_in_file)['elems']

#df1 = pd.DataFrame(np.array(chorion_and_stem['nodes']).reshape(len(chorion_and_stem['nodes']),4))
#df1.to_csv('chorion_and_stem.csv')

#populate element connectivity
elem_connectivity = pg.element_connectivity_1D(chorion_and_stem['nodes'],chorion_and_stem['elems'])
chorion_and_stem['elem_up'] = elem_connectivity['elem_up']
chorion_and_stem['elem_down'] = elem_connectivity['elem_down']

if (seed_points_option== 'generate'):
    # Define data points that represent the density of villous tissue, equispaced within an ellipsoidal geometry
    datapoints_villi=pg.equispaced_data_in_ellipsoid(n_seed,volume,thickness,ellipticity)
else:
    #read in seed points filling the volume of the placenta based on images
Ejemplo n.º 10
0
def get_tree_stats(path):

    print('path = ' + path)

    full_geom = {}
    full_geom['nodes'] = pg.import_exnode_tree(
        path + '/full_tree.exnode')['nodes'][:, 0:4]
    num_nodes = len(full_geom['nodes'])
    print('num nodes = ' + str(num_nodes))
    full_geom['elems'] = pg.import_exelem_tree(path +
                                               '/full_tree.exelem')['elems']
    num_elems = len(full_geom['elems'])
    print('num elems = ' + str(num_elems))

    tree_orders = pg.evaluate_orders(full_geom['nodes'], full_geom['elems'])
    strahler_orders = tree_orders['strahler']
    generations = tree_orders['generation']
    print('max strahler order = ' + str(max(strahler_orders)))
    print('max horsfield order = ' + str(max(tree_orders['horsfield'])))
    print('max generations = ' + str(max(generations)))

    #get element connectivity to count the number of non-branching elements in the chorionic tree
    #get second nodes for chorionic elements -  add to count if number of connected elements is less than three

    max_strahler = max(strahler_orders)

    elem_connectivity = pg.element_connectivity_1D(full_geom['nodes'],
                                                   full_geom['elems'])
    non_branching_elems = np.zeros(max_strahler, dtype=int)
    for i in range(0, num_elems):
        if elem_connectivity['elem_down'][i][0] == 1:
            non_branching_elems[strahler_orders[i] -
                                1] = non_branching_elems[strahler_orders[i] -
                                                         1] + 1

    print('Number of non-branching elements per Strahler order:')
    header = ['Strahler order', 'number of non-branching elements']
    non_branching_elems_df = pd.DataFrame(non_branching_elems)
    print(tabulate(non_branching_elems_df, headers=header))

    bins = []
    for i in range(1, max_strahler + 2):
        bins.append(i)

    (frequency, orders_temp) = np.histogram(tree_orders['strahler'], bins)
    orders = orders_temp[0:max_strahler]
    freq_final = np.subtract(frequency, non_branching_elems)
    print('orders', orders)
    print('frequency', freq_final)

    #plot number of branches by order
    plt.bar(orders, freq_final)
    heading = 'Number of true branches per Strahler order'
    plt.title(heading)
    plt.legend()
    plt.show()

    #plot number of branches with higher strahler order >= 6
    if max_strahler > 6:
        plt.bar(orders[5:max_strahler], freq_final[5:max_strahler])
        heading = 'Number of true branches per Strahler order >= 6'
        plt.title(heading)
        plt.legend()
        plt.show()

    (branching_ratio, r2) = pg.find_strahler_ratio(orders, freq_final)
    print('Strahler branching ratio = ' + str(branching_ratio))
    print('Strahler r**2 = ' + str(r2))

    #Average and min terminal generation(pathlength between the inlet and terminal unit
    path_generations = generations[(strahler_orders == 1)]

    print('Average number of generations at terminal units = ' +
          str(np.mean(path_generations)))
    print('Minimum number of generations at terminal units = ' +
          str(np.min(path_generations)))

    return 0
Ejemplo n.º 11
0
import pandas as pd
from vessel_stats_utilities import *
from os.path import expanduser

home = expanduser("~")

#Parameters

#input and output file names
node_in_file = home+'/reprosim_patients_49_51/reprosim_results/output_patient_51_two_inlets_uniform/full_tree.exnode'
elems_in_file = home+'/reprosim_patients_49_51/reprosim_results/output_patient_51_two_inlets_uniform/arterial_tree.exelem'
radius_in_file_exelem  = home+'/reprosim_patients_49_51/reprosim_results/output_patient_51_two_inlets_uniform/arterial_radius.exelem'
path = home+'/placenta_patient_49/results/p51_uniform'

full_geom = {}
full_geom['nodes'] = pg.import_exnode_tree(node_in_file)['nodes'][:, 0:4]
num_nodes = len(full_geom['nodes'])
print ('num nodes = ' + str(num_nodes))
full_geom['elems'] = pg.import_exelem_tree(elems_in_file)['elems']
num_elems = len(full_geom['elems'])
print ('num elems = ' + str(num_elems))

tree_orders = pg.evaluate_orders(full_geom['nodes'],full_geom['elems'])
strahler_orders = tree_orders['strahler']
generations = tree_orders['generation']
print('max strahler order = ' + str(max(strahler_orders)))
print('max horsfield order = ' + str(max(tree_orders['horsfield'])))
print('max generations = ' + str(max(generations)))

#get element connectivity to count the number of non-branching elements in the chorionic tree
#get second nodes for chorionic elements -  add to count if number of connected elements is less than three