Beispiel #1
0
    def __init(self, d_thr=2.0):

        from VascGraph.GraphIO import ReadPajek

        try:
            g = ReadPajek(self.g_path).GetOutput()
            if self.fix_rad:
                self.g = self.fixRad(g)
            else:
                self.g = g
            self.gtrue = ReadPajek(self.gtrue_path).GetOutput()
        except:
            g = ReadPajek(os.getcwd() + '/' + self.g_path).GetOutput()
            self.g = self.fixRad(g)
            self.gtrue = ReadPajek(os.getcwd() + '/' +
                                   self.gtrue_path).GetOutput()
            self.g_path = os.getcwd() + '/' + self.g_path
            self.gtrue_path = os.getcwd() + '/' + self.gtrue_path

        nodes_exp = np.array(self.g.GetNodesPos())
        nodes_real = np.array(self.gtrue.GetNodesPos())

        radius_exp = np.array(self.g.GetRadii())[:, None]
        radius_real = np.array(self.gtrue.GetRadii())[:, None]

        dist1 = []
        for idx, i in enumerate(nodes_real):
            dist1.append(np.sum((i - nodes_exp)**2, axis=1))

        #real nodes with the corresponding exp. ones
        idx1 = np.argmin(dist1, axis=1)
        d1 = np.array([i[idx1[j]]**.5 for j, i in enumerate(dist1)])
        radius_exp_m = radius_exp[idx1]
        self.rad_real = radius_real[d1 < d_thr]
        self.rad_exp_m = radius_exp_m[d1 < d_thr]

        dist2 = []
        for idx, i in enumerate(nodes_exp):
            dist2.append(np.sum((i - nodes_real)**2, axis=1))
        #exp nodes with the corresponding real. ones
        idx2 = np.argmin(dist2, axis=1)
        d2 = np.array([i[idx2[j]]**.5 for j, i in enumerate(dist2)])
        radius_real_m = radius_real[idx2]
        self.rad_exp = radius_exp[d2 < d_thr]
        self.rad_real_m = radius_real_m[d2 < d_thr]
Beispiel #2
0
                             Item('reset_nodes', show_label=False),
                             Item('nodes_list', style='readonly', label='Selected nodes'),
                             Item('connect_nodes', show_label=False),
                             orientation='horizontal'
                            ),
                             
                     Group('_', Item('save', show_label=False),'_'),
                     
                     label='Edit', orientation='vertical', layout='split',show_border = True,
                     )

    # The layout of the dialog created
    view = View(
            Group(
                
               Group(Item('scene', editor=SceneEditor(scene_class=MayaviScene),
                     height=600, width=400, show_label=False)),
             
               Group(control_group,
               editing_group, layout='tabbed'),
                     
                layout='split'),
               resizable=True,    title = 'Nodes selection'    
               
               )


if __name__=='__main__':
    g=ReadPajek('/home/rdamseh/GraphPaper2018V1/1.pajek')
    window=ModifyGraph(fixG(g.GetOutput()))
    window.configure_traits()
Beispiel #3
0
import numpy as np
import networkx as nx
import skimage as sk
from VascGraph.Skeletonize import GenerateGraph, ContractGraph, RefineGraph
from VascGraph.GeomGraph import DiGraph
from VascGraph.GraphIO import ReadPajek, WritePajek
from VascGraph.GraphLab import GraphPlot
from matplotlib import pyplot as plt
from mayavi import mlab
from VascGraph.Tools.VisTools import *
from VascGraph.Tools.CalcTools import *
from GraphFlowSimulation import GraphObject, GraphFlowSimulation

if __name__ == "__main__":

    g = ReadPajek('/home/rdamseh/GraphPaper2018V1' +
                  '/flow/test_network.di.pajek').GetOutput()
    metadata = sio.loadmat('/home/rdamseh/GraphPaper2018V1' +
                           '/flow/test_network.di.pajek.metadata.mat')

    g_object = GraphObject(g)
    g_object.InitGraph()
    g = g_object.GetGraph()
    #    g_object.UpdateReducedGraph()
    #    g=g_object.GetReducedGraph()

    # ----------- assigne resistances ---------- #
    print('Computes resistances ...')
    flow = GraphFlowSimulation(g, metadata)
    flow.ComputeResistance()
    flow.GetCloseGraph()
    g = flow.Graph
import numpy as np
import networkx as nx
import skimage as sk
from VascGraph.Skeletonize import GenerateGraph, ContractGraph, RefineGraph
from VascGraph.GeomGraph import DiGraph
from VascGraph.GraphIO import ReadPajek, WritePajek
from VascGraph.GraphLab import GraphPlot
from matplotlib import pyplot as plt
from mayavi import mlab
from VascGraph.Tools.VisTools import *
from VascGraph.Tools.CalcTools import *
from GraphFlowSimulation import GraphObject, GraphFlowSimulation

if __name__ == "__main__":

    g = ReadPajek('/home/rdamseh/GraphPaper2018V1' +
                  '/flow/test_network_flow.di.pajek').GetOutput()

    arteriol_pressure = 60
    venule_pressure = 25
    intra_cranial_pressure = 10

    input_so2 = .94  # arteriol o2 saturation
    alpha = 1.275 * 10e-12  # bunsen solubility
    po2_tissue = 15  # o2 partial pressure in tissue

    rho = 30 * 1e-6  # effective radius for o2 consumbtion rate
    Kappa_w = 5 * 10e-8  #o2 premiability on vascular wall
    C_Hb = 150  # hemoglobin concentration g/mL
    gamma_Hb = 2.3 * 10 - 9  # mL of Hb to moles

    def so2_to_Cb(so2):
Beispiel #5
0
class ValidateRadius:
    def __init__(self, g_path, gtrue_path, fix_rad=True, mode='mean'):

        self.g_path = g_path
        self.gtrue_path = gtrue_path
        self.mode = mode
        self.fix_rad = fix_rad

    def __init(self, d_thr=2.0):

        from VascGraph.GraphIO import ReadPajek

        try:
            g = ReadPajek(self.g_path).GetOutput()
            if self.fix_rad:
                self.g = self.fixRad(g)
            else:
                self.g = g
            self.gtrue = ReadPajek(self.gtrue_path).GetOutput()
        except:
            g = ReadPajek(os.getcwd() + '/' + self.g_path).GetOutput()
            self.g = self.fixRad(g)
            self.gtrue = ReadPajek(os.getcwd() + '/' +
                                   self.gtrue_path).GetOutput()
            self.g_path = os.getcwd() + '/' + self.g_path
            self.gtrue_path = os.getcwd() + '/' + self.gtrue_path

        nodes_exp = np.array(self.g.GetNodesPos())
        nodes_real = np.array(self.gtrue.GetNodesPos())

        radius_exp = np.array(self.g.GetRadii())[:, None]
        radius_real = np.array(self.gtrue.GetRadii())[:, None]

        dist1 = []
        for idx, i in enumerate(nodes_real):
            dist1.append(np.sum((i - nodes_exp)**2, axis=1))

        #real nodes with the corresponding exp. ones
        idx1 = np.argmin(dist1, axis=1)
        d1 = np.array([i[idx1[j]]**.5 for j, i in enumerate(dist1)])
        radius_exp_m = radius_exp[idx1]
        self.rad_real = radius_real[d1 < d_thr]
        self.rad_exp_m = radius_exp_m[d1 < d_thr]

        dist2 = []
        for idx, i in enumerate(nodes_exp):
            dist2.append(np.sum((i - nodes_real)**2, axis=1))
        #exp nodes with the corresponding real. ones
        idx2 = np.argmin(dist2, axis=1)
        d2 = np.array([i[idx2[j]]**.5 for j, i in enumerate(dist2)])
        radius_real_m = radius_real[idx2]
        self.rad_exp = radius_exp[d2 < d_thr]
        self.rad_real_m = radius_real_m[d2 < d_thr]

    def fixRad(self, g):
        '''
        fix radius values across graph branches
        '''

        from VascGraph.GeomGraph import GraphObject

        obj = GraphObject(g)
        obj.InitGraph()
        obj.UpdateReducedGraph()
        obj.UpdateDictBranches()
        red = obj.GetDictBranches()

        b = []
        for i in red.keys():
            for j in red[i]:
                b.append(j)

        for i in b:
            r = np.array([g.node[k]['r'] for k in i])
            if self.mode == 'mean':
                r = np.mean(r)
            elif self.mode == 'max':
                r = np.max(r)
            else:
                r = np.median(r)

            for k in i:
                g.node[k]['r'] = r

        return g

    def Normalize(self, x):
        return (x - x.min()) / (x.max() - x.min())

    def MSEerror(self, x, y):
        e = (x - y)**2
        e = np.mean(e, axis=0)
        return e[0]

    def MPEerror(self, y_pred, y_true):

        m = y_true.min()

        if m < 1.0:
            y_pred = y_pred + (1 - m)
            y_true = y_true + (1 - m)

        return np.mean(np.abs((y_true - y_pred) / y_true)) * 100

    def KSerror(self, x, y):
        e = kstest(x, y)
        return e[0]

    def GetScores(self, d_thr=10.0):
        '''
        Compute errors between radius values in the expiremental graph the true one
        
        Output:
            - mse: minimum mean square error
            - mpe: mean percentage error 
            - kse: kolomogorov smirnove measure 
        '''
        self.__init(
            d_thr=d_thr
        )  # threshold of maximum distance when matching the two graphs

        self.rad_exp = self.Normalize(self.rad_exp)
        self.rad_real_m = self.Normalize(self.rad_real_m)

        mse = self.MSEerror(self.rad_exp, self.rad_real_m)
        mpe = self.MPEerror(self.rad_exp, self.rad_real_m)
        kse = self.KSerror(self.rad_exp[:, 0], self.rad_real_m[:, 0])

        return mse, mpe, kse
Beispiel #6
0
    if len(check_result)==0:
        print('Item not found!!!')
        
    lines_=[]
    ind=[]
    for idx, l in enumerate(lines):
        if l.find('(')!=-1:
            lines_.append(l)
            ind.append(idx)
    attr=file.attr
    '''
    # read/write
    from VascGraph.GraphIO import WritePajek, ReadPajek
    namepajek = ''.join(attr_filename.split('.')[:-1]) + '.pajek'
    WritePajek('', namepajek, g)
    g = ReadPajek(namepajek, mode='di').GetOutput()

    from OxyGraph import OxyGraph
    og = OxyGraph(g)
    og.AddType()
    og.AddVelocityFromFlow()
    og.AddSo2FromPo2()
    og.BuildDirectionsGraph()
    g = og.g

    gplot = GraphPlot(new_engine=True)
    gplot.Update(g)
    gplot.SetTubeRadius(3)
    gplot.SetTubeRadiusByScale(True)
    gplot.SetTubeRadiusByColor(True)
Beispiel #7
0
                  degree_threshold=degree_threshold,
                  clustering_resolution=clustering_r,
                  stop_param=stop_param,
                  n_free_iteration=n_free_iteration,
                  area_param=area_param,
                  poly_param=poly_param)

    sk.UpdateWithStitching(size=size,
                           niter1=niter1,
                           niter2=niter2,
                           is_parallel=is_parallel,
                           n_parallel=n_parallel)

    fullgraph = sk.GetOutput()

    # save graph
    WritePajek(path='', name='mygraph.pajek', graph=fixG(fullgraph))

    #load graph
    loaded_g = ReadPajek('mygraph.pajek').GetOutput()

    print('--Visualize final skeleton ...')
    splot = StackPlot(new_engine=True)
    splot.Update((s > 0).astype(int))

    gplot = GraphPlot()
    gplot.Update(loaded_g)
    gplot.SetTubeRadiusByScale(True)
    gplot.SetTubeRadiusByColor(True)
    gplot.SetTubeRadius(3)