Example #1
0
def get_length_in_ring_rough(exp, t, args):
    length = 0
    for edge in exp.nx_graph[t].edges:
        edge_obj = Edge(Node(edge[0], exp), Node(edge[1], exp), exp)
        is_in_end = np.all(is_in_study_zone(edge_obj.end, t, 1000, 150))
        is_in_begin = np.all(is_in_study_zone(edge_obj.begin, t, 1000, 150))
        if is_in_end and is_in_begin:
            length += np.linalg.norm(edge.end.pos(t) - edge.begin.pos(t)) * 1.725
    return ("tot_length_study_rough", length)
Example #2
0
def get_length_study_zone(exp, t, args):
    length = 0
    for edge in exp.nx_graph[t].edges:
        edge_obj = Edge(Node(edge[0], exp), Node(edge[1], exp), exp)
        is_in_end = np.all(is_in_study_zone(edge_obj.end, t, 1000, 150))
        is_in_begin = np.all(is_in_study_zone(edge_obj.begin, t, 1000, 150))
        if is_in_end and is_in_begin:
            length += get_length_um_edge(edge_obj, t)
    return ("tot_length_study", length)
Example #3
0
def get_hulls(exp, ts):
    hulls = []
    for t in ts:
        nx_graph = exp.nx_graph[t]
        threshold = 0.1
        S = [
            nx_graph.subgraph(c).copy()
            for c in nx.connected_components(nx_graph)
        ]
        selected = [
            g for g in S
            if g.size(weight="weight") * len(g.nodes) / 10**6 >= threshold
        ]
        polys = Polygon()
        if len(selected) >= 0:
            area_max = 0
            for g in selected:
                nodes = np.array([
                    node.pos(t) for node in exp.nodes if node.is_in(t)
                    and np.all(is_in_study_zone(node, t, 1000, 150)) and (
                        node.label in g.nodes)
                ])

                if len(nodes) > 3:
                    hull = spatial.ConvexHull(nodes)
                    poly = Polygon(
                        [nodes[vertice] for vertice in hull.vertices])
                    area_hull = poly.area * 1.725**2 / (1000**2)
                    polys = polys.union(poly)
        print(t, len(selected), polys.area)
        hulls.append(polys)
    return hulls
Example #4
0
def get_hyphae_in_ring(hull1, hull2, t, exp):
    hyphae = [
        hyph for hyph in exp.hyphaes
        if hyph.end.is_in(t) and hull2.contains(Point(hyph.end.pos(t)))
        and not hull1.contains(Point(hyph.end.pos(t)))
        and np.all(is_in_study_zone(hyph.end, t, 1000, 200))
    ]
    return hyphae
Example #5
0
def get_nodes_in_ring(hull1, hull2, t, exp):
    nodes = [
        node for node in exp.nodes
        if node.is_in(t) and hull2.contains(Point(node.pos(t)))
        and not hull1.contains(Point(node.pos(t)))
        and np.all(is_in_study_zone(node, t, 1000, 200))
    ]
    return nodes
Example #6
0
def get_num_nodes_study_zone(exp, t, args):
    return (
        "num_nodes_study",
        len(
            [
                node
                for node in exp.nodes
                if node.is_in(t) and np.all(is_in_study_zone(node, t, 1000, 150))
            ]
        ),
    )
Example #7
0
def get_area_study_zone(exp, t, args):
    nodes = np.array(
        [
            node.pos(t)
            for node in exp.nodes
            if node.is_in(t) and np.all(is_in_study_zone(node, t, 1000, 150))
        ]
    )
    if len(nodes) > 3:
        hull = spatial.ConvexHull(nodes)
        poly = Polygon([nodes[vertice] for vertice in hull.vertices])
        area = poly.area * 1.725**2 / (1000**2)
    else:
        area = 0
    return ("area_study", area)
Example #8
0
def get_area_separate_connected_components(exp, t, args):
    nx_graph = exp.nx_graph[t]
    threshold = 0.1
    S = [nx_graph.subgraph(c).copy() for c in nx.connected_components(nx_graph)]
    selected = [
        g for g in S if g.size(weight="weight") * len(g.nodes) / 10**6 >= threshold
    ]
    area = 0
    for g in selected:
        nodes = np.array(
            [
                node.pos(t)
                for node in exp.nodes
                if node.is_in(t)
                and np.all(is_in_study_zone(node, t, 1000, 150))
                and (node.label in g.nodes)
            ]
        )
        if len(nodes) > 3:
            hull = spatial.ConvexHull(nodes)
            poly = Polygon([nodes[vertice] for vertice in hull.vertices])
            area += poly.area * 1.725**2 / (1000**2)
    return ("area_sep_comp", area)
Example #9
0
def gets_out_of_ROI(hyph, args):
    for t in hyph.ts:
        if not np.all(is_in_study_zone(hyph.end, t, 1000, 150)):
            return ('out_of_ROI', t)
    return ('out_of_ROI', None)
Example #10
0
def in_ROI(hypha, t, tp1, args):
    return ('in_ROI', str(np.all(is_in_study_zone(hypha.end, t, 1000, 150))))