docstr: Advanced storage system for tractography based on HDF5
  
  Parameters
  ----------
  fname : str, full filename
  mode : 'r' read
   'w' write
   'r+' read and write only if file already exists
  compression : 0 no compression to 9 maximum compression
  
  Examples
  --------
  >>> import os
  >>> from tempfile import mkstemp #temp file
  >>> from dipy.io.dpy import Dpy
  >>> def dpy_example():
  ...     fd,fname = mkstemp()
  ...     fname += '.dpy'#add correct extension
  ...     dpw = Dpy(fname,'w')
  ...     A=np.ones((5,3))
  ...     B=2*A.copy()
  ...     C=3*A.copy()
  ...     dpw.write_track(A)
  ...     dpw.write_track(B)
  ...     dpw.write_track(C)
  ...     dpw.close()
  ...     dpr = Dpy(fname,'r')
  ...     dpr.read_track()
  ...     dpr.read_track()
  ...     dpr.read_tracksi([0, 1, 2, 0, 0, 2])
  ...     dpr.close()
  ...     os.remove(fname) #delete file from disk
  >>> dpy_example()
docstr_tok: ["Advanced","storage","system","for","tractography","based","on","HDF5","Parameters","--","--","--","--","--","fname",":","str",",","full","filename","mode",":","'","r","'","read","'","w","'","write","'","r+","'","read","and","write","only","if","file","already","exists","compression",":","0","no","compression","to","9","maximum","compression","Examples","--","--","--","--",">",">",">","import","os",">",">",">","from","tempfile","import","mkstemp","#","temp","file",">",">",">","from","dipy.io.dpy","import","Dpy",">",">",">","def","dpy_example","(",")",":","...","fd",",","fname","=","mkstemp","(",")","...","fname","+=","'.dpy","'","#","add","correct","extension","...","dpw","=","Dpy","(","fname",",","'","w","'",")","...","A=np.ones","(","(","5,3",")",")","...","B=2","*","A.copy","(",")","...","C=3","*","A.copy","(",")","...","dpw.write_track","(","A",")","...","dpw.write_track","(","B",")","...","dpw.write_track","(","C",")","...","dpw.close","(",")","...","dpr","=","Dpy","(","fname",",","'","r","'",")","...","dpr.read_track","(",")","...","dpr.read_track","(",")","...","dpr.read_tracksi","(","[","0",",","1",",","2",",","0",",","0",",","2","]",")","...","dpr.close","(",")","...","os.remove","(","fname",")","#","delete","file","from","disk",">",">",">","dpy_example","(",")"]
code: def __init__(self, fname, mode="r", compression=0):
      """Advanced storage system for tractography based on HDF5
  
      Parameters
      ----------
      fname : str, full filename
      mode : 'r' read
       'w' write
       'r+' read and write only if file already exists
      compression : 0 no compression to 9 maximum compression
  
      Examples
      --------
      >>> import os
      >>> from tempfile import mkstemp #temp file
      >>> from dipy.io.dpy import Dpy
      >>> def dpy_example():
      ...     fd,fname = mkstemp()
      ...     fname += '.dpy'#add correct extension
      ...     dpw = Dpy(fname,'w')
      ...     A=np.ones((5,3))
      ...     B=2*A.copy()
      ...     C=3*A.copy()
      ...     dpw.write_track(A)
      ...     dpw.write_track(B)
      ...     dpw.write_track(C)
      ...     dpw.close()
      ...     dpr = Dpy(fname,'r')
      ...     dpr.read_track()
      ...     dpr.read_track()
      ...     dpr.read_tracksi([0, 1, 2, 0, 0, 2])
      ...     dpr.close()
      ...     os.remove(fname) #delete file from disk
      >>> dpy_example()
      """
  
      self.mode = mode
      self.f = h5py.File(fname, mode=self.mode)
      self.compression = compression
  
      if self.mode == "w":
          self.f.attrs["version"] = "0.0.1"
  
          self.streamlines = self.f.create_group("streamlines")
  
          self.tracks = self.streamlines.create_dataset(
              "tracks",
              shape=(0, 3),
              dtype="f4",
              maxshape=(None, 3),
              chunks=True,
          )
  
          self.offsets = self.streamlines.create_dataset(
              "offsets",
              shape=(1,),
              dtype="i8",
              maxshape=(None,),
              chunks=True,
          )
  
          self.curr_pos = 0
          self.offsets[:] = np.array([self.curr_pos]).astype(np.int64)
  
      if self.mode == "r":
          self.tracks = self.f["streamlines"]["tracks"]
          self.offsets = self.f["streamlines"]["offsets"]
          self.track_no = len(self.offsets) - 1
          self.offs_pos = 0
  
file_path: dipy/dipy/io/dpy.py
imports: import numpy
  import h5py
  from nibabel.streamlines import ArraySequence
label_desc: Use image node_id 1 to create a new Dpy object  with example: obj = Dpy(fname, mode, compression)