def from_json(json, cutout=None):
    """
    Converts JSON to a python list of RAMON objects. if `cutout` is provided,
    the `cutout` attribute of the RAMON object is populated. Otherwise, it's
    left empty. `json` should be an ID-level dictionary, like so:

        {
            16: {
                type: "segment",
                metadata: {
                    . . .
                }
            },
        }

    NOTE: If more than one item is in the dictionary, then a Python list of
    RAMON objects is returned instead of a single RAMON.

    Arguments:
        json (str or dict): The JSON to import to RAMON objects
        cutout: Currently not supported.

    Returns:
        [RAMON]
    """
    if type(json) is str:
        json = jsonlib.loads(json)

    out_ramons = []
    for (rid, rdata) in six.iteritems(json):
        _md = rdata['metadata']
        r = AnnotationType.RAMON(rdata['type'])(
            id=rid,
            author=_md['author'],
            status=_md['status'],
            confidence=_md['confidence'],
            kvpairs=copy.deepcopy(_md['kvpairs'])
        )

        if rdata['type'] == 'segment':
            r.segmentclass = _md.get('segmentclass')
            r.neuron = _md.get('neuron')
            if 'synapses' in _md:
                r.synapses = _md['synapses'][:]
            if 'organelles' in _md:
                r.organelles = _md['organelles'][:]

        elif rdata['type'] in ['neuron', 'synapse']:
            if 'segments' in _md:
                r.segments = _md['segments'][:]

        elif rdata['type'] == 'organelle':
            r.organelle_class = _md['organelleclass'][:]

        elif rdata['type'] == 'synapse':
            r.synapse_type = _md.get('synapse_type')
            r.weight = _md.get('weight')

        out_ramons.append(r)

    return out_ramons
def from_json(json, cutout=None):
    """
    Converts JSON to a python list of RAMON objects. if `cutout` is provided,
    the `cutout` attribute of the RAMON object is populated. Otherwise, it's
    left empty. `json` should be an ID-level dictionary, like so:

        {
            16: {
                type: "segment",
                metadata: {
                    . . .
                }
            },
        }

    NOTE: If more than one item is in the dictionary, then a Python list of
    RAMON objects is returned instead of a single RAMON.

    Arguments:
        json (str or dict): The JSON to import to RAMON objects
        cutout: Currently not supported.

    Returns:
        [RAMON]
    """
    if type(json) is str:
        json = jsonlib.loads(json)

    out_ramons = []
    for (rid, rdata) in six.iteritems(json):
        _md = rdata['metadata']
        r = AnnotationType.RAMON(rdata['type'])(
            id=rid,
            author=_md['author'],
            status=_md['status'],
            confidence=_md['confidence'],
            kvpairs=copy.deepcopy(_md['kvpairs'])
        )

        if rdata['type'] == 'segment':
            r.segmentclass = _md.get('segmentclass')
            r.neuron = _md.get('neuron')
            if 'synapses' in _md:
                r.synapses = _md['synapses'][:]
            if 'organelles' in _md:
                r.organelles = _md['organelles'][:]

        elif rdata['type'] in ['neuron', 'synapse']:
            if 'segments' in _md:
                r.segments = _md['segments'][:]

        elif rdata['type'] == 'organelle':
            r.organelle_class = _md['organelleclass'][:]

        elif rdata['type'] == 'synapse':
            r.synapse_type = _md.get('synapse_type')
            r.weight = _md.get('weight')

        out_ramons.append(r)

    return out_ramons
def from_json ( json , cutout = None ) : if type ( json ) is str : json = jsonlib . loads ( json ) out_ramons = [ ] for ( rid , rdata ) in six . iteritems ( json ) : _md = rdata [ 'metadata' ] r = AnnotationType . RAMON ( rdata [ 'type' ] ) ( id = rid , author = _md [ 'author' ] , status = _md [ 'status' ] , confidence = _md [ 'confidence' ] , kvpairs = copy . deepcopy ( _md [ 'kvpairs' ] ) ) if rdata [ 'type' ] == 'segment' : r . segmentclass = _md . get ( 'segmentclass' ) r . neuron = _md . get ( 'neuron' ) if 'synapses' in _md : r . synapses = _md [ 'synapses' ] [ : ] if 'organelles' in _md : r . organelles = _md [ 'organelles' ] [ : ] elif rdata [ 'type' ] in [ 'neuron' , 'synapse' ] : if 'segments' in _md : r . segments = _md [ 'segments' ] [ : ] elif rdata [ 'type' ] == 'organelle' : r . organelle_class = _md [ 'organelleclass' ] [ : ] elif rdata [ 'type' ] == 'synapse' : r . synapse_type = _md . get ( 'synapse_type' ) r . weight = _md . get ( 'weight' ) out_ramons . append ( r ) return out_ramons
Converts JSON to a python list of RAMON objects. if `cutout` is provided,
    the `cutout` attribute of the RAMON object is populated. Otherwise, it's
    left empty. `json` should be an ID-level dictionary, like so:

        {
            16: {
                type: "segment",
                metadata: {
                    . . .
                }
            },
        }

    NOTE: If more than one item is in the dictionary, then a Python list of
    RAMON objects is returned instead of a single RAMON.

    Arguments:
        json (str or dict): The JSON to import to RAMON objects
        cutout: Currently not supported.

    Returns:
        [RAMON]
Converts JSON to a python list of RAMON objects . if cutout is provided the cutout attribute of the RAMON object is populated . Otherwise it s left empty . json should be an ID - level dictionary like so :