Esempio n. 1
0
def newPACNO(disk, cno, exists, err, verbose=True):
    """
    Create and initialize an AIPS based Image structure
    
    Create, set initial access information (full image, plane at a time)
    and if exists verifies the file.
    Returns the Python Image object
    isOK member set to indicate success

    * disk     = AIPS directory number
    * cno      = AIPS catalog number
    * exists   = if true then the file is opened and closed to verify
    * err      = Python Obit Error/message stack
    * verbose  = If true any give error messages, else suppress
    """
    ################################################################
    out = ImageMF("AIPS Image")
    user = OSystem.PGetAIPSuser()
    out.isOK = True  # until proven otherwise
    # print "disk, aseq", disk, seq
    # Does it really previously exist?
    test = AIPSDir.PInfo(disk, user, cno, err)
    out.exist = test != None

    if exists:
        Obit.ImageMFSetAIPS(out.me, 2, disk, cno, user, blc, trc, err.me)
        Obit.ImagefullInstantiate(out.cast("ObitImage"), 1, err.me)
    else:
        Obit.ImageMFSetAIPS(out.me, 2, disk, cno, user, blc, trc, err.me)

    # show any errors if wanted
    if verbose and err.isErr:
        out.isOK = False
        OErr.printErrMsg(err, "Error finding AIPS catalog entry")
    elif err.isErr:
        out.isOK = False
        OErr.PClear(err)  # Clear unwanted messages

    # It work?
    if not out.isOK:
        return out

    # Add File info
    out.FileType = 'AIPS'
    out.Disk = disk
    out.Acno = cno
    # Lookup name etc
    s = AIPSDir.PInfo(disk, user, cno, err)
    # parse returned string
    Aname = s[0:12]
    Aclass = s[13:19]
    Aseq = int(s[20:25])
    Atype = s[26:28]
    out.Aname = Aname
    out.Aclass = Aclass
    out.Aseq = Aseq
    out.Otype = "Image"
    return out  # seems OK
Esempio n. 2
0
    def cat(self, disk, userno):
        _userno = OSystem.PGetAIPSuser()
        OSystem.PSetAIPSuser(userno)

        try:
            num_slots = AIPSDir.PNumber(disk, userno, self.err)
        except OErr.OErr as err:
            OErr.PClear(err)
            return []

        catalog = []
        for cno in range(1, num_slots):
            entry = AIPSDir.PInfo(disk, userno, cno, self.err)
            if entry:
                dict = {}
                dict['cno'] = cno
                dict['name'] = entry[0:12].strip()
                dict['klass'] = entry[13:19].strip()
                dict['seq'] = int(entry[20:25])
                dict['type'] = entry[26:28]
                dict['date'] = entry[29:40]
                dict['time'] = entry[41:49]
                catalog.append(dict)
                pass
            continue
        OSystem.PSetAIPSuser(_userno)
        return catalog
Esempio n. 3
0
def getname(cno, disk=Adisk):
    """
    Return Obit object for AIPS file in cno on disk

    * cno       = AIPS catalog slot number 
    * disk      = AIPS disk number
    """
    ################################################################
    Adisk = disk
    user = AIPS.AIPS.userno
    s = AIPSDir.PInfo(disk, user, cno, err)
    OErr.printErrMsg(err, "Error with AIPS catalog")
    # parse returned string
    Aname = s[0:12]
    Aclass = s[13:19]
    Aseq = int(s[20:25])
    Atype = s[26:28]
    if Atype == 'MA':
        out = Image.newPAImage("AIPS image", Aname, Aclass, disk, Aseq, True,
                               err)
        print("AIPS Image", Aname, Aclass, disk, Aseq)
    elif Atype == 'UV':
        out = UV.newPAUV("AIPS UV data", Aname, Aclass, disk, Aseq, True, err)
        print("AIPS UV", Aname, Aclass, disk, Aseq)
    out.Aname = Aname
    out.Aclass = Aclass
    out.Aseq = Aseq
    out.Atype = Atype
    out.Disk = disk
    out.Acno = cno
    return out
Esempio n. 4
0
class AIPSCat:
    def __init__(self):
        self.err = OErr.OErr()
        #self.sys = OSystem.OSystem("ObitTalk", 1, 1, -1, [], -1, [],
        #                           True, False, self.err)
        return

    def cat(self, disk, userno, url, AIPSdirs):
        # Init Obit if needed
        if not OSystem.PIsInit():
            popsno = 1
            if not self.err:
                self.err=OErr.OErr()
            ObitSys=OSystem.OSystem ("", popsno, userno, \
                                     len(AIPSdirs), AIPSdirs, \
                                     0, [], True, False, self.err)
            OErr.printErrMsg(self.err, "Error with Obit startup")
            doInit = True
        else:
            doInit = False
        _userno = OSystem.PGetAIPSuser()
        OSystem.PSetAIPSuser(userno)

        try:
            num_slots = AIPSDir.PNumber(disk, userno, self.err)
        except OErr.OErr, err:
            OErr.PClear(err)
            if doInit:   # Initialized Obit?
                OSystem.Shutdown(ObitSys)
                self.doInit = False
            return []

        catalog = []
        for slot in xrange(1, num_slots):
            entry = AIPSDir.PInfo(disk, userno, slot, self.err)
            if entry:
                catalog.append((slot, entry))
                pass
            continue
        # Restore Obit to initial state
        OSystem.PSetAIPSuser(_userno)
        if doInit:   # Initialized Obit?
            OSystem.Shutdown(ObitSys)
            self.doInit = False
        OErr.printErrMsg(self.err, "Error with AIPS Catalog")
        return catalog