def __init__(self, uv, **kwargs): """ Constructor Parameters ---------- uv: :class:`UV` or :class:`AIPSPath` Either a Obit UV object or an AIPSPath describing it mode: string Mode string passed through to :function:`open_uv` if `uv` is supplied with a :class:`AIPSPath` """ self._err = err = obit_err() self._open_logic(uv, err, **kwargs)
def parse_aips_config(aips_cfg_file): """ Parses an AIPS config file into a dictionary with schema :code:`{ option: [type, dimensions, value]}` :code:`type_` is an enum. Look at ObitTypes.h to figure it out. :code:`dims` indicate dimensionality of input For scalar types :code:`[64,1,1,1,1]` indicates a 1D array of length 64 floats. String dims need to be handled slightly differently First dimension indicates string length so for e.g. :code:`["obit", " ", "abcd"]` has dims :code:`[4,3,1,1,1]` So a :code:`[4,1,1,1,1]` implies one string of length 4 :code:`value` will always be a list and is probably nested if :code:`dims is setup appropriately. Parameters ---------- aips_cfg_file : str AIPS configuration file Returns ------- dict A dictionary of AIPS configuration options """ err = obit_err() info_list = InfoList.InfoList() ParserUtil.PParse(aips_cfg_file, info_list, err) handle_obit_err( "Error parsing Obit configuration file '{}'".format(aips_cfg_file), err) return InfoList.PGetDict(info_list)
def next_seq_nr(aips_path): """ Returns the highest available sequence number for which a catalogue entry does not exist Parameters ---------- aips_path : :class:`AIPSPath` An AIPS path Returns ------- integer Highest sequence number """ from AIPSDir import PHiSeq, PTestCNO from OSystem import PGetAIPSuser err = obit_err() aips_user = PGetAIPSuser() hi_seq = PHiSeq(Aname=aips_path.name, user=aips_user, disk=aips_path.disk, Aclass=aips_path.aclass, Atype=aips_path.atype, err=err) handle_obit_err("Error finding highest sequence number", err) while True: cno = PTestCNO(disk=aips_path.disk, user=aips_user, Aname=aips_path.name, Aclass=aips_path.aclass, Atype=aips_path.atype, seq=hi_seq, err=err) handle_obit_err("Error finding catalogue entry", err) if cno == -1: return hi_seq hi_seq += 1
def open_img(aips_path, mode=None, MF=False): """ Opens an AIPS/FITS Image file and returns a wrapped :class:`ImageFacade` object. Parameters ---------- aips_path: :class:`AIPSPath` Obit file object. mode(optional): str "r" to read, "w" to write, "rw" to read and write. Defaults to "r" MF(optional): boolean Open as an ImageMF? Returns ------- :class:`Image` An Obit Image object """ err = obit_err() if mode is None: mode = "r" img_mode = img_file_mode(mode) exists = False # Test if the file exists if aips_path.dtype == "AIPS": if MF: img_open = ImageMF.newPAImage else: img_open = Image.newPAImage try: img = img_open(aips_path.label, aips_path.name, aips_path.aclass, aips_path.disk, aips_path.seq, exists, err) except Exception: raise ValueError("Error calling newPAImage on '%s'" % aips_path) elif aips_path.dtype == "FITS": raise NotImplementedError("newPFImage calls do not currently work") try: img = Image.newPFImage(aips_path.label, aips_path.name, aips_path.disk, exists, err) except Exception: raise ValueError("Error calling newPFImage on '%s'" % aips_path) else: raise ValueError("Invalid dtype '{}'".format(aips_path.dtype)) handle_obit_err("Error opening '%s'" % aips_path, err) err_msg = "Error opening '%s'" % aips_path try: img.Open(img_mode, err) except Exception: raise ValueError(err_msg) handle_obit_err(err_msg, err) return img
def __init__(self, img, **kwargs): self._err = err = obit_err() self._open_logic(img, err, **kwargs)
def open_uv(aips_path, nvispio=1024, mode=None): """ Opens an AIPS/FITS UV file and returns a wrapped :class:`UVFacade` object. Parameters ---------- aips_path: :class:`AIPSPath` Obit file object. nvispio: integer Number of visibilities to read/write per I/O operation mode(optional): str "r" to read, "w" to write, "rw" to read and write. Defaults to "r" Returns ------- :class:`UV` An Obit UV object """ err = obit_err() if mode is None: mode = "r" uv_mode = uv_file_mode(mode) exists = False # Test if the file exists if aips_path.dtype == "AIPS": try: uv = UV.newPAUV(aips_path.label, aips_path.name, aips_path.aclass, aips_path.disk, aips_path.seq, exists, err, nvis=nvispio) except Exception: raise ValueError("Error calling newPAUV on '%s'" % aips_path) elif aips_path.dtype == "FITS": raise NotImplementedError("newPFUV calls do not currently work") try: uv = UV.newPFUV(aips_path.label, aips_path.name, aips_path.disk, exists, err, nvis=nvispio) except Exception: raise ValueError("Error calling newPFUV on '%s'" % aips_path) else: raise ValueError("Invalid dtype '{}'".format(aips_path.dtype)) handle_obit_err("Error opening '%s'" % aips_path, err) try: uv.Open(uv_mode, err) except Exception: raise ValueError("Error opening '%s'" % aips_path) handle_obit_err("Error opening '%s'" % aips_path, err) return uv