In [1]:
prefix="/groups/flyem/data/medulla-FIB-Z1211-25-production/align2/base_stacks/shinya1-13_20140516"
In [2]:
def process_focused_output(xshift, yshift, session_files, bookmark_files, original_orphan_file, result_directory):
import glob
import json
import os
# create bookmark output directory and file
bookmark_list = glob.glob(bookmark_files)
try:
os.makedirs(result_directory)
except OSError:
pass
bookmark_output = open(result_directory + "/bookmarks.json", 'w')
bookmarks = []
num_bookmarks = 0
# read and accumulate bookmarks
for bookmark_file in bookmark_list:
data = json.load(open(bookmark_file))
for bookmark in data["data"]:
bookmark["location"][0] += xshift
bookmark["location"][1] += yshift
bookmarks.append(bookmark)
num_bookmarks += 1
# write bookmark file
bookmark_data = {}
bookmark_data["data"] = bookmarks
bookmark_data["metadata"] = {"file version": 1, "description": "bookmarks"}
bookmark_output.write(json.dumps(bookmark_data, indent=4))
bookmark_output.close()
# retrieve all body locations
orphan_data = json.load(open(original_orphan_file))
body_locations = {}
unexamined_bodies = set()
num_synapses = {}
for body in orphan_data["Bodies"]:
body_locations[body["id"]] = body["marker"]
if not body["cross_substack"] and body["size"] < 100000:
unexamined_bodies.add(body["id"])
num_synapses[body["id"]] = body["num_synapses"]
# create accumulation file
merge_output = open(result_directory + "/pointstolink.json", 'w')
num_merges = 0
num_total = 0
bodylink_list = []
# accumulate all merges
total_synapses_fixed = 0
session_list = glob.glob(session_files)
for session_file in session_list:
data = json.load(open(session_file))
for edge in data["edge_list"]:
num_total += 1
if edge["weight"] == 0.0:
num_merges += 1
point_pair = []
# copy points out and then shift so we don't shift stored data
# via references:
x1, y1, z1 = body_locations[edge["node1"]]
x2, y2, z2 = body_locations[edge["node2"]]
x1 += xshift
x2 += xshift
y1 += yshift
y2 += yshift
# make sure unexamined node is second
if edge["node1"] in unexamined_bodies:
point_pair.append([x2, y2, z2])
point_pair.append([x1, y1, z1])
total_synapses_fixed += num_synapses[edge["node1"]]
else:
if edge["node2"] not in unexamined_bodies:
print "Node must not be examined to go first"
point_pair.append([x1, y1, z1])
point_pair.append([x2, y2, z2])
total_synapses_fixed += num_synapses[edge["node2"]]
bodylink_list.append(point_pair)
bodylink_data = {}
bodylink_data["data"] = bodylink_list
bodylink_data["metadata"] = {"file version": 1, "description": "link-save export"}
merge_output.write(json.dumps(bodylink_data, indent=4))
merge_output.close()
print "Number of bookmarks: ", num_bookmarks
print "Number of total edges: ", num_total
print "Number of merged edges: ", num_merges
print "Number of synapse annotations added to examined volume: ", total_synapses_fixed
In [3]:
# call function with x offset 1878 and y offset 2364
process_focused_output(1878, 2364, prefix + "/focused-debug-output/sessionpriority_debug_orphan/*.json",
prefix + "/focused-debug-output/bookmarks_debug_orphan/*.json",
prefix + "/focused-debug/input/input.json", prefix + "/focused-debug-results")