Ejemplo n.º 1
0
 def _rdhd(self, name):
     """Provide read access to header items via low-level calls."""
     itype = itemtable[name]
     if itype == '?': return self._rdhd_special(name)
     h = self.haccess(name, 'read')
     rv = []
     if len(itype) == 1:
         if itype == 'a': offset = 0
         else:
             t, offset = _miriad.hread_init(h)
             assert(itype == t)
         while True:
             try: c, o = _miriad.hread(h, offset, itype)
             except(IOError): break
             if itype == 'a': c = c[:o]
             rv.append(c)
             offset += o
         if itype == 'a': rv = ''.join(rv)
     else:
         t, offset = _miriad.hread_init(h); assert(t == 'b')
         for t in itype:
             v, o = _miread.hread(h, offset, t)
             rv.append(v); offset += o
     _miriad.hdaccess(h)
     if len(rv) == 1: return rv[0]
     elif type(rv) == str: return rv
     else: return np.array(rv)
Ejemplo n.º 2
0
 def _rdhd(self, name):
     """Provide read access to header items via low-level calls."""
     itype = itemtable[name]
     if itype == '?': return self._rdhd_special(name)
     h = self.haccess(name, 'read')
     rv = []
     if len(itype) == 1:
         if itype == 'a': offset = 0
         else:
             t, offset = _miriad.hread_init(h)
             assert(itype == t)
         while True:
             try: c, o = _miriad.hread(h, offset, itype)
             except(IOError): break
             if itype == 'a': c = c[:o]
             rv.append(c)
             offset += o
         if itype == 'a': rv = ''.join(rv)
     else:
         t, offset = _miriad.hread_init(h); assert(t == 'b')
         for t in itype:
             v, o = _miread.hread(h, offset, t)
             rv.append(v); offset += o
     _miriad.hdaccess(h)
     if len(rv) == 1: return rv[0]
     elif type(rv) == str: return rv
     else: return n.array(rv)
Ejemplo n.º 3
0
 def items(self):
     """Return a list of available header items."""
     items = []
     for i in itemtable:
         try:
             _miriad.hdaccess(self.haccess(i, 'read'))
             items.append(i)
         except(IOError): pass
     return items
Ejemplo n.º 4
0
 def items(self):
     """Return a list of available header items."""
     items = []
     for i in itemtable:
         try:
             _miriad.hdaccess(self.haccess(i, 'read'))
             items.append(i)
         except(IOError): pass
     return items
Ejemplo n.º 5
0
 def _wrhd_special(self, name, val):
     """Provide write access to special header items of type '?' to _rdhd"""
     if name == 'freqs':
         h = self.haccess(name, 'write')
         o = _miriad.hwrite(h, 0, val[0], 'i')
         offset = 8
         for i,v in enumerate(val[1:]):
             if i % 3 == 0: o = _miriad.hwrite(h, offset, v, 'i')
             else: o = _miriad.hwrite(h, offset, v, 'd')
             offset += 8
         _miriad.hdaccess(h)
     else: raise ValueError('Unknown special header: ' + name)
Ejemplo n.º 6
0
 def _wrhd_special(self, name, val):
     """Provide write access to special header items of type '?' to _rdhd"""
     if name == 'freqs':
         h = self.haccess(name, 'write')
         o = _miriad.hwrite(h, 0, val[0], 'i')
         offset = 8
         for i,v in enumerate(val[1:]):
             if i % 3 == 0: o = _miriad.hwrite(h, offset, v, 'i')
             else: o = _miriad.hwrite(h, offset, v, 'd')
             offset += 8
         _miriad.hdaccess(h)
     else: raise ValueError('Unknown special header: ' + name)
Ejemplo n.º 7
0
 def _wrhd(self, name, val):
     """Provide write access to header items via low-level calls."""
     type = itemtable[name]
     if type == '?': return self._wrhd_special(name, val)
     h = self.haccess(name, 'write')
     if len(type) == 1:
         try: len(val)
         except(TypeError): val = [val]
         if type == 'a': offset = 0
         else: offset = _miriad.hwrite_init(h, type)
         for v in val: offset += _miriad.hwrite(h, offset, v, type)
     else:
         offset = _miriad.hwrite_init(h, 'b')
         for v, t in zip(val,type): offset += _miriad.hwrite(h,offset,v,t)
     _miriad.hdaccess(h)
Ejemplo n.º 8
0
 def _wrhd(self, name, val):
     """Provide write access to header items via low-level calls."""
     type = itemtable[name]
     if type == '?': return self._wrhd_special(name, val)
     h = self.haccess(name, 'write')
     if len(type) == 1:
         try: len(val)
         except(TypeError): val = [val]
         if type == 'a': offset = 0
         else: offset = _miriad.hwrite_init(h, type)
         for v in val: offset += _miriad.hwrite(h, offset, v, type)
     else:
         offset = _miriad.hwrite_init(h, 'b')
         for v, t in zip(val,type): offset += _miriad.hwrite(h,offset,v,t)
     _miriad.hdaccess(h)
Ejemplo n.º 9
0
 def _rdhd_special(self, name):
     """Provide read access to special header items of type '?' to _rdhd"""
     if name == 'freqs':
         h = self.haccess(name, 'read')
         c, o = _miriad.hread(h, 0, 'i')
         rv = [c]; offset = 8
         while True:
             try:
                 c, o = _miriad.hread(h, offset, 'i')
                 rv.append(c); offset += 8
                 c, o = _miriad.hread(h, offset, 'd')
                 rv.append(c); offset += 8
                 c, o = _miriad.hread(h, offset, 'd')
                 rv.append(c); offset += 8
             except(IOError): break
         _miriad.hdaccess(h)
         return rv
     else: raise ValueError('Unknown special header: ' + name)
Ejemplo n.º 10
0
 def _rdhd_special(self, name):
     """Provide read access to special header items of type '?' to _rdhd"""
     if name == 'freqs':
         h = self.haccess(name, 'read')
         c, o = _miriad.hread(h, 0, 'i')
         rv = [c]; offset = 8
         while True:
             try:
                 c, o = _miriad.hread(h, offset, 'i')
                 rv.append(c); offset += 8
                 c, o = _miriad.hread(h, offset, 'd')
                 rv.append(c); offset += 8
                 c, o = _miriad.hread(h, offset, 'd')
                 rv.append(c); offset += 8
             except(IOError): break
         _miriad.hdaccess(h)
         return rv
     else: raise ValueError('Unknown special header: ' + name)