def to_hdf5(ramon, hdf5=None):
if issubclass(type(ramon), RAMONBase) is False:<EOL><INDENT>raise InvalidRAMONError("<STR_LIT>")<EOL><DEDENT>import h5py<EOL>import numpy<EOL>if hdf5 is None:<EOL><INDENT>tmpfile = tempfile.NamedTemporaryFile(delete=False)<EOL><DEDENT>else:<EOL><INDENT>tmpfile = hdf5<EOL><DEDENT>with h5py.File(tmpfile.name, "<STR_LIT:a>") as hdf5:<EOL><INDENT>grp = hdf5.create_group(str(ramon.id))<EOL>grp.create_dataset("<STR_LIT>", (<NUM_LIT:1>,),<EOL>numpy.uint32,<EOL>data=AnnotationType.get_int(type(ramon)))<EOL>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>if ramon.cutout is not None:<EOL><INDENT>grp.create_dataset('<STR_LIT>', ramon.cutout.shape,<EOL>ramon.cutout.dtype, data=ramon.cutout)<EOL>grp.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>numpy.uint32, data=ramon.resolution)<EOL>grp.create_dataset('<STR_LIT>', (<NUM_LIT:3>,),<EOL>numpy.uint32, data=ramon.xyz_offset)<EOL><DEDENT><DEDENT>metadata = grp.create_group('<STR_LIT>')<EOL>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>dtype=h5py.special_dtype(vlen=str),<EOL>data=ramon.author)<EOL>fstring = StringIO()<EOL>csvw = csv.writer(fstring, delimiter='<STR_LIT:U+002C>')<EOL>csvw.writerows([r for r in six.iteritems(ramon.kvpairs)])<EOL>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>dtype=h5py.special_dtype(vlen=str),<EOL>data=fstring.getvalue())<EOL>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,), numpy.float,<EOL>data=ramon.confidence)<EOL>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,), numpy.uint32,<EOL>data=ramon.status)<EOL>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>',<EOL>data=numpy.asarray(ramon.segments,<EOL>dtype=numpy.uint32))<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,), numpy.uint32,<EOL>data=ramon.synapse_type)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>numpy.float, data=ramon.weight)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>numpy.uint32, data=ramon.neuron)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,), numpy.uint32,<EOL>data=ramon.segmentclass)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (len(ramon.synapses),),<EOL>numpy.uint32, data=ramon.synapses)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>',<EOL>(len(ramon.organelles),),<EOL>numpy.uint32,<EOL>data=ramon.organelles)<EOL><DEDENT>if hasattr(ramon, '<STR_LIT>'):<EOL><INDENT>metadata.create_dataset('<STR_LIT>', (<NUM_LIT:1>,),<EOL>numpy.uint32,<EOL>data=ramon.organelle_class)<EOL><DEDENT>hdf5.flush()<EOL>tmpfile.seek(<NUM_LIT:0>)<EOL>return tmpfile<EOL><DEDENT>return False<EOL>
Exports a RAMON object to an HDF5 file object.

Arguments:
    ramon (RAMON): A subclass of RAMONBase
    hdf5 (str): Export filename

Returns:
    hdf5.File

Raises:
    InvalidRAMONError: if you pass a non-RAMON object