def neighborhood_cortical_magnification(mesh, coordinates):
idcs = _cmag_coord_idcs(coordinates)<EOL>neis = mesh.tess.indexed_neighborhoods<EOL>coords_vis = np.asarray(coordinates if len(coordinates) == <NUM_LIT:2> else coordinates.T)<EOL>coords_srf = mesh.coordinates<EOL>res = np.full((mesh.vertex_count, <NUM_LIT:3>), np.nan, dtype=np.float)<EOL>res = np.array([row for row in [(np.nan,np.nan,np.nan)] for _ in range(mesh.vertex_count)],<EOL>dtype=np.float)<EOL>for idx in idcs:<EOL><INDENT>nei = neis[idx]<EOL>pts_vis = coords_vis[:,nei]<EOL>pts_srf = coords_srf[:,nei]<EOL>x0_vis = coords_vis[:,idx]<EOL>x0_srf = coords_srf[:,idx]<EOL>if any(u is None or np.isnan(u) for pt in pts_vis for u in pt): continue<EOL>x0col_vis = np.asarray([x0_vis]).T<EOL>x0col_srf = np.asarray([x0_srf]).T<EOL>voronoi_vis = (pts_vis - x0col_vis) * <NUM_LIT:0.5> + x0col_vis<EOL>voronoi_srf = (pts_srf - x0col_srf) * <NUM_LIT:0.5> + x0col_srf<EOL>area_vis = np.sum([geo.triangle_area(x0_vis, a, b)<EOL>for (a,b) in zip(voronoi_vis.T, np.roll(voronoi_vis, <NUM_LIT:1>, axis=<NUM_LIT:1>).T)])<EOL>area_srf = np.sum([geo.triangle_area(x0_srf, a, b)<EOL>for (a,b) in zip(voronoi_srf.T, np.roll(voronoi_srf, <NUM_LIT:1>, axis=<NUM_LIT:1>).T)])<EOL>res[idx,<NUM_LIT:2>] = np.inf if np.isclose(area_vis, <NUM_LIT:0>) else area_srf/area_vis<EOL>pts_vis = voronoi_vis<EOL>pts_srf = voronoi_srf<EOL>segs_srf = (pts_srf, np.roll(pts_srf, -<NUM_LIT:1>, axis=<NUM_LIT:1>))<EOL>segs_vis = (pts_vis, np.roll(pts_vis, -<NUM_LIT:1>, axis=<NUM_LIT:1>))<EOL>segs_vis_t = np.transpose(segs_vis, (<NUM_LIT:2>,<NUM_LIT:0>,<NUM_LIT:1>))<EOL>segs_srf_t = np.transpose(segs_srf, (<NUM_LIT:2>,<NUM_LIT:0>,<NUM_LIT:1>))<EOL>x0norm_vis = npla.norm(x0_vis)<EOL>if not np.isclose(x0norm_vis, <NUM_LIT:0>):<EOL><INDENT>dirvecs = x0_vis / x0norm_vis<EOL>dirvecs = np.asarray([dirvecs, [-dirvecs[<NUM_LIT:1>], dirvecs[<NUM_LIT:0>]]])<EOL>for dirno in [<NUM_LIT:0>,<NUM_LIT:1>]:<EOL><INDENT>dirvec = dirvecs[dirno]<EOL>line = (x0_vis, x0_vis + dirvec)<EOL>try:<EOL><INDENT>isects_vis = np.asarray(geo.line_segment_intersection_2D(line, segs_vis))<EOL>isect_idcs = np.unique(np.where(np.logical_not(np.isnan(isects_vis)))[<NUM_LIT:1>])<EOL><DEDENT>except Exception:<EOL><INDENT>isect_idcs = []<EOL><DEDENT>if len(isect_idcs) != <NUM_LIT:2>:<EOL><INDENT>res[idx,dirno] = np.nan<EOL>continue<EOL><DEDENT>isects_vis = isects_vis[:,isect_idcs].T<EOL>len_vis = npla.norm(isects_vis[<NUM_LIT:0>] - isects_vis[<NUM_LIT:1>])<EOL>if np.isclose(len_vis, <NUM_LIT:0>): res[idx,dirno] = np.inf<EOL>else:<EOL><INDENT>fsegs_srf = segs_srf_t[isect_idcs]<EOL>fsegs_vis = segs_vis_t[isect_idcs]<EOL>s02lens_vis = npla.norm(fsegs_vis[:,<NUM_LIT:0>] - fsegs_vis[:,<NUM_LIT:1>], axis=<NUM_LIT:1>)<EOL>s01lens_vis = npla.norm(fsegs_vis[:,<NUM_LIT:0>] - isects_vis, axis=<NUM_LIT:1>)<EOL>vecs_srf = fsegs_srf[:,<NUM_LIT:1>] - fsegs_srf[:,<NUM_LIT:0>]<EOL>s02lens_srf = npla.norm(vecs_srf, axis=<NUM_LIT:1>)<EOL>isects_srf = np.transpose([(s01lens_vis/s02lens_vis)]) * vecs_srf+ fsegs_srf[:,<NUM_LIT:0>]<EOL>len_srf = np.sum(npla.norm(isects_srf - x0_srf, axis=<NUM_LIT:1>))<EOL>res[idx,dirno] = len_srf / len_vis<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return res<EOL>
neighborhood_cortical_magnification(mesh, visual_coordinates) yields a list of neighborhood-
based cortical magnification values for the vertices in the given mesh if their visual field
coordinates are given by the visual_coordinates matrix (must be like [x_values, y_values]). If
either x-value or y-value of a coordinate is either None or numpy.nan, then that cortical
magnification value is numpy.nan.