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)
def _wrhd(self, name, val): """Provide write access to header items via low-level calls.""" item_type = itemtable[name] if item_type == "?": return self._wrhd_special(name, val) h = self.haccess(name, "write") if len(item_type) == 1: try: len(val) except TypeError: val = [val] if item_type == "a": offset = 0 else: offset = _miriad.hwrite_init(h, item_type) for v in val: offset += _miriad.hwrite(h, offset, v, item_type) else: offset = _miriad.hwrite_init(h, "b") for v, t in zip(val, item_type): offset += _miriad.hwrite(h, offset, v, t) _miriad.hdaccess(h)
def _wrhd_special(self, name, val): """Provide write access to special header items of type '?' to _wrhd.""" if name == "freqs": h = self.haccess(name, "write") _miriad.hwrite(h, 0, val[0], "i") offset = 8 for i, v in enumerate(val[1:]): if i % 3 == 0: _miriad.hwrite(h, offset, v, "i") else: _miriad.hwrite(h, offset, v, "d") offset += 8 _miriad.hdaccess(h) else: raise ValueError("Unknown special header: " + name)
def items(self): """ Get the list of available header items. Returns ------- list of str 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
def _rdhd(self, name): """ Provide read access to header items via low-level calls. Parameters ---------- name : str name of header item Returns ------- str or int or float value of header item """ 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": try: c = str(c[:o], "utf-8") except TypeError: 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 = _miriad.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)