def _extract_sections(data_block):
structure_block = data_block[:, COLS.TYPE:COLS.COL_COUNT].astype(np.int)<EOL>id_map = {-<NUM_LIT:1>: -<NUM_LIT:1>}<EOL>for i, row in enumerate(structure_block):<EOL><INDENT>id_map[row[ID]] = i<EOL><DEDENT>sec_end_pts = _section_end_points(structure_block, id_map)<EOL>gap_sections = set()<EOL>sections = []<EOL>def new_section():<EOL><INDENT>'''<STR_LIT>'''<EOL>sections.append(DataBlockSection())<EOL>return sections[-<NUM_LIT:1>]<EOL><DEDENT>curr_section = new_section()<EOL>parent_section = {-<NUM_LIT:1>: -<NUM_LIT:1>}<EOL>for row in structure_block:<EOL><INDENT>row_id = id_map[row[ID]]<EOL>parent_id = id_map[row[PID]]<EOL>if not curr_section.ids:<EOL><INDENT>curr_section.ids.append(parent_id)<EOL>curr_section.ntype = row[TYPE]<EOL><DEDENT>gap = parent_id != curr_section.ids[-<NUM_LIT:1>]<EOL>if gap:<EOL><INDENT>sec_end_pts.add(row_id)<EOL><DEDENT>else:<EOL><INDENT>curr_section.ids.append(row_id)<EOL><DEDENT>if row_id in sec_end_pts:<EOL><INDENT>parent_section[curr_section.ids[-<NUM_LIT:1>]] = len(sections) - <NUM_LIT:1><EOL>if gap:<EOL><INDENT>curr_section = new_section()<EOL>curr_section.ids.extend((parent_id, row_id))<EOL>curr_section.ntype = row[TYPE]<EOL>gap_sections.add(len(sections) - <NUM_LIT:2>)<EOL><DEDENT>elif row_id != len(data_block) - <NUM_LIT:1>:<EOL><INDENT>curr_section = new_section()<EOL><DEDENT><DEDENT><DEDENT>for sec in sections:<EOL><INDENT>if sec.ids:<EOL><INDENT>sec.pid = parent_section[sec.ids[<NUM_LIT:0>]]<EOL><DEDENT>if sec.pid in gap_sections:<EOL><INDENT>_merge_sections(sections[sec.pid], sec)<EOL><DEDENT><DEDENT>return sections<EOL>
Make a list of sections from an SWC-style data wrapper block