from __future__ import division
import os
from matplotlib import delaunay
from emd_util import find_edges
from drosophila_eye_map.precompute_buchner71_optics import x,y
import drosophila_eye_map.precomputed_buchner71 as optics
from drosophila_eye_map.util import save_as_python

left_tri = delaunay.Triangulation(x, y)
left_triangles = left_tri.triangle_nodes

# make EMD edges
left_edges = find_edges( left_triangles )

right_idx_offset = optics.receptor_dir_slicer['left'].stop

right_triangles = []
for tri in left_triangles:
    newtri = []
    for idx in tri:
        newtri.append( idx+right_idx_offset )
    right_triangles.append(newtri)
triangles = list(left_triangles) + right_triangles

right_edges = []
for edge in left_edges:
    newedge = []
    for idx in edge:
        newedge.append( idx+right_idx_offset )
    right_edges.append(newedge)
edges = list(left_edges) + right_edges

edge_slicer = {None:slice(0,len(edges),1),
               'left':slice(0,len(left_edges),1),
               'right':slice(len(left_edges),len(edges),1)}

if 1:
    fd = open('precomputed_buchner71_emd_edges.py','wb')
    fd.write( '# Automatically generated by %s\n'%os.path.split(__name__)[-1])
    save_as_python(fd, edge_slicer, 'edge_slicer',
                   fname_extra='_buchner71' )
    save_as_python(fd, edges, 'edges', fname_extra='_buchner_1971' )
    fd.close()


from __future__ import division
import os
from matplotlib import delaunay
from emd_util import find_edges
from drosophila_eye_map.precompute_buchner71_optics import x,y
import drosophila_eye_map.precomputed_buchner71 as optics
from drosophila_eye_map.util import save_as_python

left_tri = delaunay.Triangulation(x, y)
left_triangles = left_tri.triangle_nodes

# make EMD edges
left_edges = find_edges( left_triangles )

right_idx_offset = optics.receptor_dir_slicer['left'].stop

right_triangles = []
for tri in left_triangles:
    newtri = []
    for idx in tri:
        newtri.append( idx+right_idx_offset )
    right_triangles.append(newtri)
triangles = list(left_triangles) + right_triangles

right_edges = []
for edge in left_edges:
    newedge = []
    for idx in edge:
        newedge.append( idx+right_idx_offset )
    right_edges.append(newedge)
edges = list(left_edges) + right_edges

edge_slicer = {None:slice(0,len(edges),1),
               'left':slice(0,len(left_edges),1),
               'right':slice(len(left_edges),len(edges),1)}

if 1:
    fd = open('precomputed_buchner71_emd_edges.py','wb')
    fd.write( '# Automatically generated by %s\n'%os.path.split(__name__)[-1])
    save_as_python(fd, edge_slicer, 'edge_slicer',
                   fname_extra='_buchner71' )
    save_as_python(fd, edges, 'edges', fname_extra='_buchner_1971' )
    fd.close()


# make EMD edges