<jupyter_start><jupyter_text>Create neuroglancer link with bboxes for FAFBv15  <NAME> ingested updated montages of FAFB for the v15 alignment. For each z index in the final reference frame, he ingested multiple cloudvolume indices, one for each connected component of image tiles with tissue. He provided us the bboxes of each connected component, and we want to visualize them to understand where there is data in this latest ingest.<jupyter_code>import json
from cloudvolume.lib import Bbox, Vec
from itertools import combinations
import matplotlib.pyplot as plt
with open('191015_tm_fafb_v15_bboxes.json', 'r') as f:
    bboxes = json.load(f)
bboxes[0]
def add_bbox(state, minx, miny, maxx, maxy, z, k):
    ann = state['layers'][0]['annotations']
    bbox = {'pointA': [minx, miny, z],
            'pointB': [maxx, maxy, z+1],
            'type': 'axis_aligned_bounding_box',
            'id': str(k)}
    ann.append(bbox)
    
def add_point(state, x, y, z, k):
    ann = state['layers'][0]['annotations']
    bbox = {'point': [x, y, z],
            'type': 'point',
            'id': str(k)}
    ann.append(bbox)    
with open('191015_tm_fafb_ng_state.json', 'r') as f:
    ng_state = json.load(f)
for i in range(len(bboxes)):
    d = bboxes[i]
    # add_bbox(ng_state, d['minX'], d['minY'], d['maxX'], d['maxY'], float(d['sectionId']), i)
    if d['z'] == float(d['sectionId'])*100:
        # add_point(ng_state, (d['minX']+d['maxX']) / 2, (d['minY']+d['maxY']) / 2, float(d['sectionId']), i+0.1)
        add_bbox(ng_state, d['minX'], d['minY'], d['maxX'], d['maxY'], float(d['sectionId']), i)
# print(json.dumps(ng_state))<jupyter_output><empty_output><jupyter_text>How many bboxes intersect for each section?<jupyter_code>sections = {}
for d in bboxes:
    z = int(round(float(d['sectionId'])))
    if z not in sections:
        sections[z] = []
    bbox = Bbox(Vec(d['minX'], d['minY'], z), Vec(d['maxX'], d['maxY'], z+1))
    sections[z].append(bbox)
intersections = {}
for z, s in sections.items():
    inter = 0
    for p,q in combinations(s, 2):
        inter += Bbox.intersects(p,q)
    intersections[z] = inter
len(intersections)
f, ax = plt.subplots(1, 1, figsize=(12,6))
ax.hist(intersections.values(), bins=max(intersections.values()));
ax.set_title('Bbox intersections per section');
x = [z for z, v in sections.items() for k in v]
y = [k.volume() for z, v in sections.items() for k in v]
f, ax = plt.subplots(1, 1, figsize=(12,6))
ax.scatter(x, y);
ax.set_xlabel('z')
ax.set_title('Bbox volume');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1720345640219953, 'fraction_numerical': 0.016496465043205028, 'mean_word_length': 4.229979466119096, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '415786', 'license': 'MIT', 'n_tokens_mistral': 968, 'n_tokens_neox': 944, 'n_words': 255, 'path': 'inference/params/191015_tm_fafbv15_bboxes.ipynb', 'repo_name': 'emitch/SEAMLeSS', 'size': '2550'}