Example #1
0
 def __init__(self,tag='in'):
     if isinstance(tag,File):
         # copy file
         self.__init__(tag.tag)
     else:
         self.file = c_rsf.sf_input(tag)
         _File.__init__(self,tag)
Example #2
0
 def __init__(self,tag='in'):
     if isinstance(tag,File):
         # copy file
         self.__init__(tag.tag)
     else:
         self.file = c_rsf.sf_input(tag)
         _File.__init__(self,tag)
Example #3
0
 def __init__(self, tag='in'):
     self.file = None
     if isinstance(tag, File):
         # copy file
         self.__init__(tag.tag)
     else:
         if _swig_:
             if python2:
                 # c function only knows utf-8 (ascii).  translate the unicode
                 tag = tag.encode('utf-8')
             self.file = c_rsf.sf_input(tag)
         else:
             self.file = _RSF(True, tag)
     _File.__init__(self, tag)
Example #4
0
    def __array__(self,context=None):
        'numpy array'
        if _swig_:
            # danger: dangling open file descriptor
            if None == self.narray:
                if not hasattr(self,'file'):
                    self.file = c_rsf.sf_input(self.tag)
                self.narray = c_rsf.rsf_array(self.file)
            return self.narray
        else:
            # gets only the real part of complex arrays
            val = os.popen('%s < %s' % 
                           (Filter('disfil')(number=False),self)).read()

            return map(lambda x: float(x.rstrip(',')),val.split())
Example #5
0
    def __array__(self,context=None):
        'numpy array'
        if _swig_:
            # danger: dangling open file descriptor
            if None == self.narray:
                if not hasattr(self,'file'):
                    self.file = c_rsf.sf_input(self.tag)
                self.narray = c_rsf.rsf_array(self.file)
            return self.narray
        else:
            # gets only the real part of complex arrays
            val = os.popen('%s < %s' % 
                           (Filter('disfil')(number=False),self)).read()

            return map(lambda x: float(x.rstrip(',')),val.split())
Example #6
0
 def size(self, dim=0):
     if _swig_:
         if hasattr(self, 'file'):
             f = self.file
         else:
             f = c_rsf.sf_input(self.tag)
         s = c_rsf.sf_leftsize(f, dim)
         if not hasattr(self, 'file'):
             c_rsf.sf_fileclose(f)
     else:
         s = 1
         for axis in range(dim + 1, 10):
             n = self.int("n%d" % axis)
             if n:
                 s *= n
             else:
                 break
     return s
Example #7
0
 def __init__(self,tag='out',src=None):
     if not tag:
         self.tag = Temp()
         self.temp = True
     else:
         self.tag = tag
         self.temp = False
     self.file = c_rsf.sf_output(self.tag)
     if src: # clone source file
         if hasattr(src,'file'):
            srcfile = src.file
            srctype = src.type
         else:
            srcfile = c_rsf.sf_input(self.tag)
            srctype = c_rsf.sf_gettype(srcfile)
         c_rsf.sf_settype(self.file,_File.type.index(srctype))
         c_rsf.sf_fileflush(self.file,srcfile)
     _File.__init__(self,self.tag)
Example #8
0
 def size(self,dim=0):
     if _swig_:
         if hasattr(self,'file'):
             f = self.file
         else:
             f = c_rsf.sf_input(self.tag)
         s = c_rsf.sf_leftsize(f,dim)
         if not hasattr(self,'file'):
             c_rsf.sf_fileclose(f)
     else:
         s = 1
         for axis in range(dim+1,10):
             n = self.int("n%d" % axis)
             if n:
                 s *= n
             else:
                 break
     return s    
Example #9
0
 def __init__(self,tag='out',src=None):
     if not tag:
         self.tag = Temp()
         self.temp = True
     else:
         self.tag = tag
         self.temp = False
     self.file = c_rsf.sf_output(self.tag)
     if src: # clone source file
         if hasattr(src,'file'):
            srcfile = src.file
            srctype = src.type
         else:
            srcfile = c_rsf.sf_input(self.tag)
            srctype = c_rsf.sf_gettype(srcfile)
         c_rsf.sf_settype(self.file,_File.type.index(srctype))
         c_rsf.sf_fileflush(self.file,srcfile)
     _File.__init__(self,self.tag)
Example #10
0
File: m8r.py Project: aashish24/src
 def __array__(self,context=None):
     'numpy array'
     if False and _swig_: #kls I broke path that uses c_rsf.sf_input
         if None == self.narray:
             if not hasattr(self,'f'):
                 f = c_rsf.sf_input(self.tag)
             else:
                 f = self.f
             self.narray = c_rsf.rsf_array(f)
             if not hasattr(self,'f'):
                 c_rsf.sf_fileclose(f)
         return self.narray
     else:
         # gets only the real part of complex arrays
         # should be able to dp something like this, which is used in 
         # class Input.read()
         #sys.stderr.write('in __array__\n')
         tempinput=Input(self.filename)
         #sys.stderr,write('call getall\n')
         return tempinput.getalldata()
Example #11
0
File: m8r.py Project: clintz1/src
 def __array__(self,context=None):
     'create narray'
     if [] == self.narray:
         if _swig_:
             if not hasattr(self,'file'):
                 f = c_rsf.sf_input(self.tag)
             else:
                 f = self.file
             self.narray = c_rsf.rsf_array(f)
             if not hasattr(self,'file'):
                 c_rsf.sf_fileclose(f)
         else:
             # gets only the real part of complex arrays ##kls
             if not hasattr(self,'file'):
                 f=Input(self.tag)
             else:
                 f=self.file
             self.narray=np.memmap(f.string('in'),dtype=f.datatype,
                                   mode='r+',
                                   shape=f.shape())
     return self.narray