(roifile, outfile)
Convert rois.svg file (from previous versions of pycortex) to overlays.svg
Convert rois.svg file (from previous versions of pycortex) to overlays.svg
Convert rois . svg file ( from previous versions of pycortex ) to overlays . svg
def import_roi(roifile, outfile):
    """Convert rois.svg file (from previous versions of pycortex) to overlays.svg"""
    import warnings
    warnings.warn("Converting rois.svg to overlays.svg")
    svg = etree.parse(roifile, parser=parser)

    label_layer = None
    for layer in svg.findall("{%s}g[@{%s}label]"%(svgns, inkns)):
        name = layer.get("{%s}label"%inkns)
        if name == "data":
            #maintain data layer, do not process
            pass
        elif name == "roilabels": #label layer
            label_layer = layer
            layer.getparent().remove(layer)
        else:
            parent = _make_layer(layer.getparent(), name)
            layer.getparent().remove(layer)
            layer.attrib['id'] = '%s_shapes'%name
            layer.attrib['{%s}label'%inkns] = 'shapes'
            layer.attrib['clip-path'] = "url(#edgeclip)"
            parent.append(layer)
            labels = _make_layer(parent, "labels")
            labels.attrib['id'] = '%s_labels'%name

    if label_layer is not None:
        rois = _find_layer(svg, "rois")
        labels = _find_layer(rois, 'labels')
        rois.remove(labels)

        label_layer.attrib['id'] = 'rois_labels'
        label_layer.attrib['{%s}label'%inkns] = 'labels'
        rois.append(label_layer)


    with open(outfile, "wb") as fp:
        fp.write(etree.tostring(svg, pretty_print=True))

    # Final check for all layers
    svgo = SVGOverlay(outfile)
    for new_layer in ['sulci', 'cutouts', 'display']:
        if new_layer not in svgo.layers:
            svgo.add_layer(new_layer)
def import_roi ( roifile , outfile ) : import warnings warnings . warn ( "Converting rois.svg to overlays.svg" ) svg = etree . parse ( roifile , parser = parser ) label_layer = None for layer in svg . findall ( "{%s}g[@{%s}label]" % ( svgns , inkns ) ) : name = layer . get ( "{%s}label" % inkns ) if name == "data" : #maintain data layer, do not process pass elif name == "roilabels" : #label layer label_layer = layer layer . getparent ( ) . remove ( layer ) else : parent = _make_layer ( layer . getparent ( ) , name ) layer . getparent ( ) . remove ( layer ) layer . attrib [ 'id' ] = '%s_shapes' % name layer . attrib [ '{%s}label' % inkns ] = 'shapes' layer . attrib [ 'clip-path' ] = "url(#edgeclip)" parent . append ( layer ) labels = _make_layer ( parent , "labels" ) labels . attrib [ 'id' ] = '%s_labels' % name if label_layer is not None : rois = _find_layer ( svg , "rois" ) labels = _find_layer ( rois , 'labels' ) rois . remove ( labels ) label_layer . attrib [ 'id' ] = 'rois_labels' label_layer . attrib [ '{%s}label' % inkns ] = 'labels' rois . append ( label_layer ) with open ( outfile , "wb" ) as fp : fp . write ( etree . tostring ( svg , pretty_print = True ) ) # Final check for all layers svgo = SVGOverlay ( outfile ) for new_layer in [ 'sulci' , 'cutouts' , 'display' ] : if new_layer not in svgo . layers : svgo . add_layer ( new_layer )