예제 #1
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
예제 #2
0
파일: AIPSDir.py 프로젝트: mauch/Obit
def PTestCNO(disk, user, Aname, Aclass, Atype, seq, err):
    """
    Test if AIPS file exists
    
    returns AIPS cno, -1 => not found

    * disk     = AIPS disk number
    * user     = AIPS user number
    * Aname    = AIPS file name
    * Aclass   = AIPS class name
    * Atype    = 'MA' or 'UV' for image or uv data
    * seq      = AIPS sequence number
    * err      = Python Obit Error/message stack, 
    """
    ################################################################
    # Checks
    if err.isErr:
        return -1
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be an OErr"
    #
    # Print message stack to clear
    OErr.printErr(err)
    ret = Obit.AIPSDirFindCNO(disk, user, Aname, Aclass, Atype, seq, err.me)
    if err.isErr:
        return ret
    # Clear any couldn't find message
    OErr.PClear(err)
    return ret
예제 #3
0
 def exists(self, desc):
     try:
         self._init(desc, verbose=False)
     except OErr.OErr as err:
         OErr.PClear(err)
         return False
     return True
예제 #4
0
 def exists(self, desc):
     try:
         self._init(desc, verbose=False)
     except OErr.OErr, err:
         OErr.PClear(err)
         if self.doInit:   # Initialized Obit?
             OSystem.Shutdown(self.ObitSys)
         return False
예제 #5
0
파일: ImageMF.py 프로젝트: mauch/Obit
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
예제 #6
0
    def exists(self, desc):
        """Checks that this instance of AIPSData refers to a dataset that is
        actually present in the AIPS catalogue."""

        assert(not self.err.isErr)
        cno = Obit.AIPSDirFindCNO(desc['disk'], desc['userno'], desc['name'],
                                  desc['klass'], self.type,  desc['seq'],
                                  self.err.me)
        if cno == -1:
            OErr.PClear(self.err)
            return False
        return True
예제 #7
0
파일: ImageMF.py 프로젝트: mauch/Obit
def newPFImageMF(name, filename, disk, exists, err, verbose=True):
    """
    Create and initialize an FITS based ImageMF structure
    
    Create, set initial access information (full image, plane at a time)
    and if exists verifies the file.
    isOK member set to indicate success
    Returns the Python ImageMF object

    * name     = name desired for object (labeling purposes)
    * filename = name of FITS file
    * disk     = FITS directory 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(name)
    out.isOK = True  # until proven otherwise
    # Does it really previously exist?
    out.exist = FITSDir.PExist(filename, disk, err)
    Obit.ImageMFSetFITS(out.me, 2, disk, filename, blc, trc, err.me)
    if exists:
        Obit.ImagefullInstantiate(out.cast("ObitImage"), 1, err.me)
    # show any errors if wanted
    if verbose and err.isErr:
        out.isOK = False
        OErr.printErrMsg(err, "Error creating FITS image object")
    elif err.isErr:
        out.isOK = False
        OErr.PClear(err)  # Clear unwanted messages
    # Check if really uvtab data and not an image
    outd = out.Desc.Dict
    if outd["inaxes"][0] == 777777701:
        out.isOK = False
        raise TypeError, "Error: Object probably uvtab (UV) data"

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

    out.FileType = 'FITS'
    out.FileName = filename
    out.Fname = filename
    out.Disk = disk
    out.Otype = "Image"
    return out  # seems OK
예제 #8
0
파일: AIPSData.py 프로젝트: mauch/Obit-1
    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 as err:
            OErr.PClear(err)
            if doInit:   # Initialized Obit?
                OSystem.Shutdown(ObitSys)
                self.doInit = False
            return []

        catalog = []
        for slot in range(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
예제 #9
0
    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 []
예제 #10
0
파일: ImageMF.py 프로젝트: mauch/Obit
def newPAImage(name, Aname, Aclass, disk, seq, exists, err, verbose=False):
    """
    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

    * name     = name desired for object (labeling purposes)
    * Aname    = AIPS name of file
    * Aclass   = AIPS class of file
    * seq      = AIPS sequence number of file
    * disk     = FITS directory 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(name)
    out.isOK = True  # until proven otherwise
    cno = -1
    user = OSystem.PGetAIPSuser()
    # print "disk, aseq", disk, seq
    # Does it really previously exist?
    test = AIPSDir.PTestCNO(disk, user, Aname, Aclass, "MA", seq, err)
    out.exist = test > 0
    if exists:  # If user thinks file exists...
        if out.exist:  # If file is defined in catalog -> verify that file exists
            OErr.PLog(err, OErr.Info, Aname + " image found. Now verifying...")
            if verbose: OErr.printErr(err)
            cno = AIPSDir.PFindCNO(disk, user, Aname, Aclass, "MA", seq, err)
            Obit.ImageMFSetAIPS(out.me, 2, disk, cno, user, blc, trc, err.me)
            Obit.ImagefullInstantiate(out.cast("ObitImage"), 1, err.me)
            #print "found",Aname,Aclass,"as",cno
        else:  # If file not defined in catalog -> error
            OErr.PLog(err, OErr.Error, Aname + " image does not exist")
            out.isOK = False
    else:  # exists=False
        # Create new image entry in catalog; if image already defined, this
        # has no effect
        OErr.PLog(err, OErr.Info,
                  "Creating new image: " + Aname + ", " + Aclass)
        if verbose: OErr.printErr(err)
        cno = AIPSDir.PAlloc(disk, user, Aname, Aclass, "MA", seq, err)
        Obit.ImageMFSetAIPS(out.me, 2, disk, cno, user, blc, trc, err.me)
        #print "assigned",Aname,Aclass,"to",cno

    # show any errors if wanted
    if verbose and err.isErr:
        out.isOK = False
        OErr.printErrMsg(err, "Error creating AIPS Image object")
    elif err.isErr:
        out.isOK = False
        OErr.PClear(err)  # Clear unwanted messages
    else:
        OErr.PClear(err)  # Clear non-error messages

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

    # Add File info
    out.FileType = 'AIPS'
    out.Disk = disk
    out.Aname = Aname
    out.Aclass = Aclass
    out.Aseq = seq
    out.Otype = "Image"
    out.Acno = cno
    return out  # seems OK
예제 #11
0
파일: VLACal.py 프로젝트: mauch/Obit
def VLAUVLoad(filename, inDisk, Aname, Aclass, Adisk, Aseq, err, logfile=''):
    """ Read FITS uvtab file into AIPS

    Read a UVTAB FITS UV data file and write an AIPS data set
    filename   = name of FITS file
    inDisk     = FITS directory number
    Aname      = AIPS name of file
    Aclass     = AIPS class of file
    Aseq       = AIPS sequence number of file, 0=> create new
    Adisk      = FITS directory number
    err        = Python Obit Error/message stack
    logfile    = logfile for messages
    returns AIPS UV data object
    """
    ################################################################
    #
    # Checks
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be an OErr"
    #
    # Get input
    inUV = UV.newPFUV("FITS UV DATA", filename, inDisk, True, err)
    if err.isErr:
        OErr.printErrMsg(err, "Error with FITS data")
    # Get output, create new if seq=0
    if Aseq < 1:
        OErr.printErr(err)  # Print any outstanding messages
        user = OSystem.PGetAIPSuser()
        Aseq = AIPSDir.PHiSeq(Adisk, user, Aname, Aclass, "MA", err)
        # If it already exists, increment seq
        if AIPSDir.PTestCNO(Adisk, user, Aname, Aclass, "MA", Aseq, err) > 0:
            Aseq = Aseq + 1
        OErr.PClear(err)  # Clear any message/error
    mess = "Creating AIPS UV file " + Aname + "." + Aclass + "." + str(
        Aseq) + " on disk " + str(Adisk)
    printMess(mess, logfile)
    outUV = UV.newPAUV("AIPS UV DATA", Aname, Aclass, Adisk, Aseq, False, err)
    if err.isErr:
        OErr.printErrMsg(err, "Error creating AIPS data")
    # Copy
    UV.PCopy(inUV, outUV, err)
    if err.isErr:
        OErr.printErrMsg(err, "Error copying UV data to AIPS")
    # Copy History
    inHistory = History.History("inhistory", inUV.List, err)
    outHistory = History.History("outhistory", outUV.List, err)
    History.PCopyHeader(inHistory, outHistory, err)
    # Add history
    outHistory.Open(History.READWRITE, err)
    outHistory.TimeStamp(" Start Obit uvlod", err)
    outHistory.WriteRec(
        -1, "uvlod   / FITS file " + filename + " disk " + str(inDisk), err)
    outHistory.Close(err)
    #
    # Copy Tables
    exclude = [
        "AIPS HI", "AIPS AN", "AIPS FQ", "AIPS SL", "AIPS PL", "History"
    ]
    include = []
    UV.PCopyTables(inUV, outUV, exclude, include, err)
    return outUV  # return new object