Exemple #1
0
def PAddDir(newDir, err, URL=None):
    """
    Add a new FITS directory
    
    returns FITS disk number

    * newDir   = new directory path
    * err      = Python Obit Error/message stack
    * URL      = URL if on a remote host (Only if using OTObit/ParselTongue)
    """
    ################################################################
    global FITSdisks, nFITS
    # Checks
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be an OErr"
    #
    retDisk = Obit.FITSAddDir(newDir, err.me)
    FITSdisks.append(newDir)
    nFITS = len(FITSdisks)
    #print "DEBUG nFITS",nFITS
    if err.isErr:
        OErr.printErrMsg(err, "Error adding FITS directory")
        # Update ObitTalk stuff
    try:
        FITS.FITS.disks.append(FITS.FITSDisk(URL, retDisk, newDir))
    except:
        pass
    else:
        pass
    return retDisk
Exemple #2
0
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
Exemple #3
0
def PSetDir(disk, newName, err, URL=None):
    """
    Set the directory name for a given AIPS directory
    
    returns disk number actually used

    * disk     = AIPS disk number, <=0 => assign
    * newName  = new directory path
    * err      = Python Obit Error/message stack
    * URL      = URL if on a remote host (Only if using OTObit/ParselTongue)
    """
    ################################################################
    # Checks
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be an OErr"
    #
    retDisk = Obit.AIPSSetDirname(disk, newName, err.me)
    if err.isErr:
        OErr.printErrMsg(err, "Error setting AIPS directory name")
    AIPSdisks.append(newName)
    nAIPS = len(AIPSdisks)
    if (disk <= 0):
        try:
            AIPS.AIPS.disks.append(AIPS.AIPSDisk(URL, retDisk, newName))
        except:
            pass
        else:
            pass
    return retDisk
Exemple #4
0
def PInvertSN (SNTab, outUV, outVer, doRepl, err):
    """ Invert the calibration in an SN table

    Routine to reverse the effects of the calibration in the
    input SN table and create a new SN table on outUV
    Returns new SN table
    SNTab     = Input Python AIPS SN Table to invert
    outUV     = output UV data to which to attach the new SN table
    outVer    = Output SN table version number, 0=> create new
    doRepl    = If True, replace failed solutions with (1,0)
    err       = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not Table.PIsA(SNTab):
        raise TypeError("SNTab MUST be a Python Obit Table")
    if not UV.PIsA(outUV):
        raise TypeError('outUV Must be UV data ')
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be an OErr")
    #
    # Create output
    outSN  = Table.Table("None")
    # invert table
    outSN.me = Obit.SNInvert (SNTab.me, outUV.me, outVer, doRepl, err.me)
    if err.isErr:
        printErrMsg(err, "Error inverting solutions")
    return outSN
Exemple #5
0
def PCreate(name, dirty, beam, clean, err):
    """ Create CleanOTF  Object

    returns CleanOTF object
    name    = Name for clean
    dirty   = Python Obit dirty image
    beam    = Python Obit dirty beam
              Must have same cell spacing are dirty but need not be same size
              if None, use Gaussian the size of beamMaj in dirty
    clean   = Python Obit CLEAN image
              Should be defined but need not be instantiated.
    err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not Image.PIsA(dirty):
        raise TypeError, "dirty MUST be a Python Obit Image"
    if not Image.PIsA(clean):
        raise TypeError, "clean MUST be a Python Obit Image"
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be a Python ObitErr"
    if err.isErr:  # existing error?
        return None
    #
    if beam == None:
        lbeam = Image.Image("NoBeam")
    else:
        if not Image.PIsA(beam):
            raise TypeError, "beam MUST be a Python Obit Image"
        lbeam = beam
    out = CleanOTF(name, dirty.me, lbeam.me, clean.me, err.me)
    if beam:
        dirty.Beam = beam

    return out
Exemple #6
0
def PPosition(inFI, coord, err):
    """
    Interpolate value at requested coordinate in array.
    
    Interpolate value at requested coordinate in array.
    The object must have an image descriptor to allow determing
    pixel coordinates.
    Interpolation between planes is not supported.
    return the value at specified coordinate
    * inFI    = Python Obit input FInterpolate
    * coord   = coordinate as array of float
    * err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not PIsA(inFI):
        raise TypeError("inFI MUST be a Python Obit FInterpolate")
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be a Python ObitErr")
    if err.isErr:  # existing error?
        return None
    #
    ret = Obit.FInterpolatePosition(inFI.me, coord, err.me)
    if err.isErr:
        printErrMsg(err, "Error interpolating pixel value")
    return ret
Exemple #7
0
    def CopyTables(self, outOData, exclude, include, err):
        """
        Copy Tables from one OData to another

        * self      = Python OData object
        * outOData     = Output Python OData object, must be defined
        * exclude   = list of table types to exclude (list of strings)
          has priority
        * include   = list of table types to include (list of strings)
        * err       = Python Obit Error/message stack
        """
        ################################################################
        # Checks
        if not self.ODataIsA():
            raise TypeError, "self MUST be a Python Obit OData"
        if not outOData.ODataIsA():
            raise TypeError, "outOData MUST be a Python Obit OData"
        if not OErr.OErrIsA(err):
            raise TypeError, "err MUST be an OErr"
        #
        ret = Obit.ODataCopyTables  (self.cast(myClass), outOData.cast(myClass), \
                                     exclude, include, err.me)
        if err.isErr:
            OErr.printErrMsg(err, "Error copying Tables")
        return ret
Exemple #8
0
def PFitCal(inOTF, detect, err):
    """ Fits calibrator scans

    Gets calibrator information from the Target table (position, flux density)
    Input values on inOTF
    "Scans"    OBIT_Int (1,1,1) Scan numbers to process, should be 4 scans
    "Tau0"     OBIT_float (1,1,1) Zenith opacity in nepers [def 0].
    "ATemp"    OBIT_float (*,1,1) Effective atmospheric temperature in data units.
        i.e. the additional offset per airmass due to the atmosphere.
        per detector in units of the cal. [def 300]
    "doPlot"   OBIT_Bool (1,1,1) If present and True, plot data and models [def FALSE]
    Output values on inOTF
    "TRx"      OBIT_float (*,1,1) Receiver temperature per detector in units of the cal
    "calJy"    OBIT_float (*,1,1) Noise cal value in Jy, per detector
    "RAoff"    OBIT_float (*,1,1) Offset in deg to add to RA
    "Decoff"   OBIT_float (*,1,1) Offset in deg to add to Dec
    "Timeoff"  OBIT_float (*,1,1) Offset in time (day) (actual-expected peak)
    
    inOTF   = Python Obit OTF
    detect  = detector number (0-rel), -1 => all
    err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not OTF.PIsA(inOTF):
        raise TypeError, "inOTF MUST be a Python Obit OTF"
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be a Python ObitErr"
    if err.isErr:  # existing error?
        return
    #
    Obit.OTFUtilFitCal(inOTF.me, detect, err.me)
Exemple #9
0
def PFitTip(inOTF, err):
    """ Fits tipping scans

    Gets reciever/sky brightness/tau0 from tipping scan
    Input values on inOTF
    "Scan"     OBIT_Int (1,1,1) Scan number to process, should be a tipping scan
    "TCal"     OBIT_float (*,1,1) Noise cal value in K, per detector
    "TSky"     OBIT_float (1,1,1) Physical temperature of the sky (K) [def 300]
    "minEl"    OBIT_float (1,1,1) Min. elevation (deg).
                                  This may be needed to cut off low elevations where the
                                  mountains are in the beam.
    "doPlot"   OBIT_Bool (1,1,1) If present and True, plot data and models [def FALSE]
    Output values on inOTF
    "Tau0"     OBIT_float (1,1,1) Zenith opacity in nepers 
    "ATemp"    OBIT_float (*,1,1) Effective atmospheric temperature in data units.
               i.e. the additional offset per airmass due to the atmosphere.
               per detector in units of the cal.
    "TRx"      OBIT_float (*,1,1) Receiver temperature per detector in units of the cal
    "TipRMS"   OBIT_float (*,1,1) RMS residual (K) per detector
    
    inOTF   = Python Obit OTF
    err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not OTF.PIsA(inOTF):
        raise TypeError, "inOTF MUST be a Python Obit OTF"
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be a Python ObitErr"
    if err.isErr:  # existing error?
        return
    #
    Obit.OTFCalUtilFitTip(inOTF.me, err.me)
Exemple #10
0
def PEdit (inHis, startr, endr, err):
    """
    Edit History
    
    Deletes a range of history records.
    return 0 on success, else failure

    * inHis    = input Python History
    * startr   = first (1-rel) history record to delete
    * endr     = highest (1-rel) history record to delete, 0=>to end
    * err      = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not PIsA(inHis):
        raise TypeError("inHis MUST be a History")
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be an OErr")
    #
    ret = POpen (inHis, READWRITE, err)
    ret = Obit.HistoryEdit(inHis.me, startr, endr, err.me)
    OErr.printErr(err)
    if err.isErr:
        OErr.printErrMsg(err, "Error Editing History")
    ret = PClose (inHis, err)
    return ret
Exemple #11
0
def PCreateImage(inOTF, err):
    """ Create basic ObitImage structure and fill out descriptor.

    Imaging parameters are on the inOTF info member.
    "nx"     int scalar Dimension of image in RA [no default].
    "ny"     int scalar Dimension of image in declination[no default]
    "RA"     float scalar Right Ascension of center of image
             Default is observed position center in inOTF 
    "Dec"    float scalar Declination of center of image
             Default is observed position center in inOTF 
    "xCells" float scalar X (=RA) cell spacing in degrees [no default]
    "yCells" float scalar Y (=dec) cell spacing in degrees [no default]
    "Proj"   string (4,1,1) Projection string "-SIN", "-ARC", "-TAN"
             [Default "-SIN"]
    returns Image
    inOTF   = Python Obit OTF from which the solution is to be determined
    err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not OTF.PIsA(inOTF):
        raise TypeError, "inOTF MUST be a Python Obit OTF"
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be a Python ObitErr"
    #
    out = Image.Image("None")
    if err.isErr:  # existing error?
        return out
    out.me = Obit.OTFUtilCreateImage(inOTF.me, err.me)
    return out
Exemple #12
0
def PAtmEm(inOTF, outOTF, err):
    """ Set atmospheric emission corrections for an OTF dataset.

    Set atmospheric emission corrections into the detector offsets for an OTF dataset
    Results are placed in a newly created OTFSoln table.
    Calibration parameters are on the inOTF info member.
    "solInt"   float (1,1,1) Solution interval in days [def 10 sec].
    "AtmEm"    float (*,1,1) Equivalent zenith atmospheric brightness in Jy [0]
    "Tau0"     float (1,1,1) Zenith opacity in nepers [def 0].

    returns OTFSoln table with solutions
    inOTF   = Python Obit OTF from which the solution is to be determined
    outOTF  = Python Obit OTF onto which the solution table is to be appended.
    err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not OTF.PIsA(inOTF):
        raise TypeError,"inOTF MUST be a Python Obit OTF"
    if not OTF.PIsA(outOTF):
        raise TypeError,"outOTF MUST be a Python Obit OTF"
    if not OErr.OErrIsA(err):
        raise TypeError,"err MUST be a Python ObitErr"
    #
    out = Table.Table(" ")
    if err.isErr: # existing error?
        return out
    out.me = Obit.OTFGetAtmEm (inOTF.me, outOTF.me, err.me)
    return out
Exemple #13
0
def PConvGauss(inImage, maj, min, pa, rescale, outImage, err):
    """
    Convolve an Image with a Gaussian and write outImage
    
    This routine convolves all selected planes in inImage with a Gaussian
    Operations are performed using FFTs 

    * inImage  = Obit Image to be convolved
    * maj      = Major axis of Gaussian in image plane (arcsec)
    * min      = Minor axis of Gaussian in image plane  (arcsec)
    * pa       = Position angle of Gaussian in image plane, from N thru E, (deg)
    * rescale  = Multiplication factor to scale output to correct units
    * outImage = Output ObitImage must be a clone of inImage
      Actual convolution size must be set externally 
    * err      = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not Image.PIsA(inImage):
        print "Actually ", inImage.__class__
        raise TypeError, "inImage MUST be a Python Obit Image"
    if not Image.PIsA(outImage):
        print "Actually ", outImage.__class__
        raise TypeError, "outImage MUST be a Python Obit Image"
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be an OErr"
    #
    Obit.ConvUtilConvGauss(inImage.me, maj, min, pa, rescale, outImage.me,
                           err.me)
Exemple #14
0
def PConv(inImage, convFn, doDivide, rescale, outImage, err):
    """
    (de)Convolve an Image with an FArray and write outImage
    
    This routine convolves all selected planes in inImage with convFn if  
    doDivide is FALSE, else it does a linear deconvolution 
    Operations are performed using FFTs 

    * inImage  = Obit Image to be convolved
    * convFn   = Obit/FArray Convolving Function 
    * doDovide = If true divide FT of convFn into FT of inImage, else multiply.
    * rescale  = Multiplication factor to scale output to correct units
    * outImage = Output ObitImage must be a clone of inImage
      Actual convolution size must be set externally 
    * err      = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not Image.PIsA(inImage):
        print "Actually ", inImage.__class__
        raise TypeError, "inImage MUST be a Python Obit Image"
    if not FArray.PIsA(convFn):
        print "Actually ", convFn.__class__
        raise TypeError, "convFn MUST be a Python Obit FArray"
    if not Image.PIsA(outImage):
        print "Actually ", outImage.__class__
        raise TypeError, "outImage MUST be a Python Obit Image"
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be an OErr"
    #
    Obit.ConvUtilConv(inImage.me, convFn.me, doDivide, rescale, outImage.me,
                      err.me)
Exemple #15
0
def PGetPos (inID, inPixel, err):
    """
    Return position of pixel inPixel in inID
    
    returns array of 2 floats giving (RA, Dec) in deg of pixel inPixel

    * inID    = Python Obit ImageDesc for input
    * inPixel = array of floats giving position in image described by inID
      only first 2 used.
    * err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not PIsA(inID):
        raise TypeError,"inID MUST be a Python Obit ImageDesc"
    if not OErr.OErrIsA(err):
        raise TypeError,"err MUST be an OErr"
    if inPixel[0].__class__ != float:
        print "class is" , inPixel[0].__class__
        raise TypeError,"inPixel MUST be float"
    if len(inPixel) < 2:
        raise RuntimeError,"inPixel has fewer then 2 entries"
    #
    outTmp = Obit.ImageDescGetPos (inID.me, inPixel, err.me)
    if err.isErr:
        OErr.printErrMsg(err, "Error converting pixel location to position")
    out = outTmp[0:2]
    return out
Exemple #16
0
def PSubImage(inOTF, outOTF, image, desc, err):
    """ Subtract a 2D ObitFArray from an OTF

    inOTF   = input Python Obit OTF
    outOTF  = output Python Obit OTF, must be previously defined
    image   = Python Obit Image data to subtract, as FArray
    desc    = Python Obit ImageDesc for image
    err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not OTF.PIsA(inOTF):
        raise TypeError, "inOTF MUST be a Python Obit OTF"
    if not OTF.PIsA(outOTF):
        raise TypeError, "outOTF MUST be a Python Obit OTF"
    if not FArray.PIsA(image):
        raise TypeError, "image MUST be a Python Obit FArray"
    if not ImageDesc.PIsA(desc):
        raise TypeError, "desc MUST be a Python Obit ImageDesc"
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be a Python ObitErr"
    if err.isErr:  # existing error?
        return
    #
    Obit.OTFUtilSubImage(inOTF.me, outOTF.me, image.me, desc.me, err.me)
Exemple #17
0
def GetTargetPos(OTF, Target, err):
    """ Get target position from OTFTarget table

    return [raepo, decepo] in deg
    Loop through target table on OTF looking for Target and return position
    
    OTF      = OTF data file to check
    Target   = Name of target e.g. "MARS"
    """
    ################################################################
    # Checks
    if not OTF.OTFIsA():
        raise TypeError, "OTF MUST be a Python Obit OTF"
    if type(Target) != str:
        raise TypeError, "Target MUST be a string"
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be an OErr"

    tarTab = OTF.NewTable(Table.READONLY, "OTFTarget", 1, err)
    tarTab.Open(Table.READONLY, err)
    OErr.printErrMsg(err, "Error with OTFTarget table")
    norow = tarTab.Desc.Dict["nrow"]
    for irow in range(1, norow + 1):
        row = tarTab.ReadRow(irow, err)
        if row["TARGET"][0].strip() == Target.strip():
            out = [row["RAEPO"][0], row["DECEPO"][0]]
            tarTab.Close(err)
            return out

    tarTab.Close(err)
    # Didn't find it if it gets here
    OErr.printErrMsg(err, "Error getting Target")
    raise RuntimeError, "Failed to find target " + Target + " in OTFTarget on " + OTF.GetName(
    )
    return [None, None]
Exemple #18
0
def PFitNod(inOTF, err):
    """ Fits nodding scans

    Gets cal values in units of Jy
    Input values on inOTF
    "Scan"     OBIT_Int   (1,1,1) Scan number to process, should be a nodding scan
    "calFlux"  OBIT_float (1,1,1) If given, the calibrator flux density, otherwise
                                  get from OTFTarget table
    Output values on inOTF
    "TRx"      OBIT_float (*,1,1) Receiver temperature per detector in units of the cal
    "calJy"    OBIT_float (*,1,1) Equivalent Jy per detector of the cal.
    
    inOTF   = Python Obit OTF
    err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not OTF.PIsA(inOTF):
        raise TypeError, "inOTF MUST be a Python Obit OTF"
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be a Python ObitErr"
    if err.isErr:  # existing error?
        return
    #
    Obit.OTFCalUtilFitNod(inOTF.me, -1, err.me)
Exemple #19
0
    def ZapTable(self, tabType, tabVer, err):
        """
        Destroy specified table
        
        Returns 0 on success

        * self      = Python OData object
        * tabType   = Table type, e.g. "AIPS CC"
        * tabVer    = table version, integer
        * err       = Python Obit Error/message stack
        """
        inOData = self
        # Checks
        if not self.ODataIsA():
            raise TypeError, "input MUST be a Python Obit OData"
        if not OErr.OErrIsA(err):
            raise TypeError, "err MUST be an OErr"
        #
        # Open/Close to (re)Read header to be sure it's up to date
        inOData.Open(READONLY, err)
        inOData.Close(err)

        # delete table
        ret = Obit.ODataZapTable(inOData.cast(myClass), tabType, tabVer,
                                 err.me)
        if err.isErr:
            OErr.printErrMsg(err, "Error Zapping OData data Table")
        # Update header
        inOData.UpdateTables(err)
        return ret
Exemple #20
0
def PConvBeam(CCTab, Beam, Template, err):
    """ Convolve a set of Clean components with a beam image

    CCTab      CC Table, following parameters on infoList member
       "BComp" OBIT_int (1,1,1) Start CC to use, 1-rel [def 1 ]
       "EComp" OBIT_int (1,1,1) Highest CC to use, 1-rel [def to end ]
    Beam       Beam Image to convolve with CCs
    Template   Template FArray for output array
    err        Obit Error stack
    Returns an ObitFArray whose size is that of Template, spacing is that of Beam
        with the CCs in CCTab convolved with Beam and the (0,0) position is
        (nx/2,ny/2) (0-rel)
    """
    ################################################################
    # Checks
    if not Table.PIsA(CCTab):
        raise TypeError, "CCTab MUST be a Python Obit Table"
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be a Python ObitErr"
    #
    out = FArray.FArray("Convolved CCs")
    if err.isErr:  # existing error?
        return out
    out.me = Obit.OTFUtilConvBeam(CCTab.me, Beam.me, Template.me, err.me)
    return out
Exemple #21
0
def PDeselSN (inSC, SNTab, isuba, fgid, ants, timerange, err):
    """ Deselect entries in an SN table

    Routine to deselect records in an SN table if they match a given
    subarray, have a selected FQ id, appear on a list of antennas and
    are in a given timerange.
    inSC      = Selfcal object
    SNTab     = Python AIPS SN Table
    isuba     = subarray, <=0 -> any
    fqid      = Selected FQ id, <=0 -> any
    ants      = array of integer antenna numbers, 0->all
    timerange = timerange (days)
    err       = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not PIsA(inSC):
        raise TypeError('Bad input selfcalibrator')
    if not Table.PIsA(SNTab):
        raise TypeError("SNTab MUST be a Python Obit Table")
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be an OErr")
    #
    nantf = len(ants)
    Obit.UVSolnDeselSN (SNTab.me, isuba, fqid, nantf, ants, timerange,
                           err.me)
    if err.isErr:
        printErrMsg(err, "Error deselecting solutions")
Exemple #22
0
def PModelImage(inOTF, outOTF, image, desc, err):
    """ Replace OTF data with the model in a 2D ObitFArray

    inOTF   = input Python Obit OTF
    outOTF  = output Python Obit OTF, must be previously defined
    image   = Python Obit Image model to use, as FArray
    desc    = Python Obit ImageDesc for image
    err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not OTF.PIsA(inOTF):
        raise TypeError, "inOTF MUST be a Python Obit OTF"
    if not OTF.PIsA(outOTF):
        raise TypeError, "outOTF MUST be a Python Obit OTF"
    if not FArray.PIsA(image):
        raise TypeError, "image MUST be a Python Obit FArray"
    if not ImageDesc.PIsA(desc):
        raise TypeError, "desc MUST be a Python Obit ImageDesc"
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be a Python ObitErr"
    if err.isErr:  # existing error?
        return
    #
    Obit.OTFUtilModelImage(inOTF.me, outOTF.me, image.me, desc.me, err.me)
Exemple #23
0
def PWriteCirc(sttab, im, center, radius, err):
    """ Write an entry for drawing a circle
    
    sttab  = Python Table object, must be open with write enabled
    im     = Obit Image on which to attach ST Table
    center = [x,y] pixels
    radius = radius in pixels
    err    = Python Obit Error/message stack
    """
    ################################################################
    # Check
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be an OErr")
    if err.isErr:  # existing error?
        return None
    # Get image descriptor
    id = im.Desc.Dict
    # Get row
    row = newRow(im)
    # Convert pixels to positions
    pos = ImageDesc.PGetPos(im.Desc, center, err)
    if err.isErr:
        printErrMsg(err, "Error converting pixel location to position")
    row[id["ctype"][0].strip()] = [pos[0]]
    row[id["ctype"][1].strip()] = [pos[1]]
    row['MAJOR AX'] = [radius * abs(id["cdelt"][0])]
    row['MINOR AX'] = row['MAJOR AX']
    row['POSANG'] = [0.0]
    row['STARTYPE'] = [3.0]
    row['LABEL'] = ["    "]
    # Write
    sttab.WriteRow(-1, row, err)
    if err.isErr:
        printErrMsg(err, "Error Writing ST table")
Exemple #24
0
def PCvtPixel(inID, inPixel, outID, err):
    """
    Return pixel location in outID corresponding to pixel inPixel in inID
    
    returns array of 2 floats giving pixel position in outID.

    * inID    = Python Obit ImageDesc for input
    * inPixel = array of floats giving position in image described by inID
      only first 2 used.
    * outID   = Python Obit ImageDesc for output
    * err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not PIsA(inID):
        raise TypeError("inID MUST be a Python Obit ImageDesc")
    if not PIsA(outID):
        raise TypeError("outID MUST be a Python Obit ImageDesc")
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be an OErr")
    if inPixel[0].__class__ != float:
        print("class is", inPixel[0].__class__)
        raise TypeError("inPixel MUST be float")
    if len(inPixel) < 2:
        raise RuntimeError("inPixel has fewer then 2 entries")
    #
    outTmp = Obit.ImageDescCvtPixel(inID.me, outID.me, inPixel, err.me)
    if err.isErr:
        OErr.printErrMsg(err, "Error converting pixel location")
    out = outTmp[0:2]
    return out
Exemple #25
0
def PBackFFT(FFTrev, inArray, outArray, err):
    """
    Back transform half plane complex to real
    
    inArray is FFTed (half plane complex - real) to outArray

    * FFTref   = FFT object to FT inArray
    * inArray  = CArray with image to be FFTed
      must be a size compatable with FFTrev
    * outArray = FArray for output
      must be a size compatable with FT of inArray
    * err      = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not FFT.PIsA(FFTrev):
        print("Actually ",FFTrev.__class__)
        raise TypeError("FFTrev MUST be a Python Obit FFT")
    if not CArray.PIsA(inArray ):
        print("Actually ",inArray.__class__)
        raise TypeError("inArray MUST be a Python Obit CArray")
    if not FArray.PIsA(outArray ):
        print("Actually ",outArray.__class__)
        raise TypeError("outArray MUST be a Python Obit FArray")
    if not OErr.OErrIsA(err):
        raise TypeError("err MUST be an OErr")
    #
    # FFT
    PFFTC2R (FFTrev, inArray, outArray)

    FArray.PCenter2D (outArray)
Exemple #26
0
def POverlap (inID1, inID2, err):
    """
    Determine if there is any overlap between images
    
    Compares ImageDesc objects to see if the associated
    images overlap on the sky.
    Returns True if so sles False

    * inID1   = First Python Obit ImageDesc for test
    * inID2   = Second Python Obit ImageDesc for test
    * err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not PIsA(inID1):
        raise TypeError,"inID1 MUST be a Python Obit ImageDesc"
    if not PIsA(inID2):
        raise TypeError,"inID2 MUST be a Python Obit ImageDesc"
    if not OErr.OErrIsA(err):
        raise TypeError,"err MUST be an OErr"
    #
    res = Obit.ImageDescOverlap (inID1.me, inID2.me, err.me)
    if err.isErr:
        OErr.printErrMsg(err, "Error determining overlap")
    return res!=0
Exemple #27
0
def PInfo(disk, user, cno, err):
    """
    Get information for a  AIPS catalog slot number
    
    Returned string s:
        ======  =============
        Aname   s[0:12]
        Aclass  s[13:19]
        Aseq    int(s[20:25])
        Atype   s[26:28]
        ======  =============
    
    returns string describing entry, None=>empty

    * disk     = AIPS disk number
    * user     = AIPS user number
    * cno      = AIPS catalog slot to deassign
    * err      = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be an OErr"
    #
    ret = Obit.AIPSDirInfo(disk, user, cno, err.me)
    if err.isErr:
        OErr.printErrMsg(err, "Error reading AIPS catalog header")
    return ret
Exemple #28
0
def PGetPixel (inID, inPos, err):
    """
    Return pixel location in inID corresponding position inPos
    
    returns array of 2 floats giving pixel position in outID.

    * inID    = Python Obit ImageDesc for input
    * inPos   = array of floats (RA, dec) in deg
    * err     = Python Obit Error/message stack
    """
    ################################################################
    # Checks
    if not PIsA(inID):
        raise TypeError,"inID MUST be a Python Obit ImageDesc"
    if not OErr.OErrIsA(err):
        raise TypeError,"err MUST be an OErr"
    if inPos[0].__class__ != float:
        print "class is" , inPos[0].__class__
        raise TypeError,"inPos MUST be float"
    if len(inPos) < 2:
        raise RuntimeError,"inPos has fewer then 2 entries"
    #
    outTmp = Obit.ImageDescGetPixel (inID.me, inPos, err.me)
    if err.isErr:
        OErr.printErrMsg(err, "Error determining pixel")
    out = outTmp[0:2]
    return out
Exemple #29
0
def PAllDest(disk, err, Atype="  ", Aname=None, Aclass=None, Aseq=0):
    """
    Delete selected AIPS catalog entries
    
    Entries can be selected using Atype, Aname, Aclass, Aseq,
    using AIPS wildcards
    A "?" matches one of any character, "*" matches any string
    all blanks matches anything

    * disk     = AIPS disk number, 0=>all
    * err      = Python Obit Error/message stack
    * type     = optional file type
    * Aname    = desired name, using AIPS wildcards, None -> don't check
    * Aclass   = desired class, using AIPS wildcards, None -> don't check
    * Aseq     = desired sequence, 0=> any
    * first    = optional first slot number (1-rel)
    * last     = optional last slot number
    * giveList = If true, return list of CNOs matching
    """
    ################################################################
    # Checks
    if not OErr.OErrIsA(err):
        raise TypeError, "err MUST be an OErr"
    #
    if (disk < 0) or (disk > (len(AIPS.AIPS.disks) + 1)):
        raise RuntimeError, "Disk " + str(disk) + " out of range"
    # disks
    if disk > 0:
        disks = [disk]
    else:
        disks = range(1, len(AIPS.AIPS.disks))
    user = OSystem.PGetAIPSuser()
    # loop over disks
    for dsk in disks:
        ncno = PNumber(dsk, user, err)
        OErr.printErrMsg(err, "Error getting number of cnos")

        for cno in range(1, ncno):
            line = PInfo(dsk, user, cno, err)
            OErr.printErrMsg(err, "Error reading entry")
            if WantDir(line, type=Atype, Aname=Aname, Aclass=Aclass,
                       Aseq=Aseq):
                # parse directory string
                Tname = line[0:12]
                Tclass = line[13:19]
                Tseq = int(line[20:25])
                Ttype = line[26:28]
                z = None
                if Ttype == 'MA':
                    z = Image.newPAImage("Zap image", Tname, Tclass, dsk, Tseq, True, err, \
                               verbose=False)
                    print "Zap AIPS Image", Tname, Tclass, dsk, Tseq
                elif Ttype == 'UV':
                    z = UV.newPAUV("Zap UV data", Tname, Tclass, dsk, Tseq, True, err, \
                                   verbose=False)
                    print "Zap AIPS UV", Tname, Tclass, dsk, Tseq
                # Delete entry
                if z:
                    z.Zap(err)
                    del z
Exemple #30
0
def PTableCCT2Spec (inImage, outImage, nTerm,
                    inCCVer, outCCVer, err, startCC=0, endCC=0):
    """ Convert an (tabulated) TSpec CC Table to spectral parameter table

    Output CC Table will have fitted spectra rather than tabulated spectra.
    Tabulated spectrum fitted with spectrum weighting by primary beam
    inImage   input Obit Python Image 1
              Must have freq axis type = "SPECLNMF"
              Optional parameters on List member:
                 "dropNeg" boolean if True drop negative components [True] 
                 "doPBCor" boolean if True Primary beam correct [False] 
    outImage  output Obit Python image must be type ObitImageWB
              This can be created by ImageUtil.PImageT2Spec
    nTerm     Number of output Spectral terms, 2=SI, 3=also curve.
    inCCVer   Input CCTable to convert, 0=> highest
    outCCVer  Output CCTable, 0=>1
    err       Python Obit Error/message stack
    startCC   First 1-rel component to convert
    endCC     Last 1-rel component to convert, 0=> all
    """
    ################################################################
    # Checks
    if not Image.PIsA(inImage):
        raise TypeError,"inImage MUST be a Python Obit Image"
    if not Image.PIsA(outImage):
        raise TypeError,"outImage MUST be a Python Obit Image"
    if not OErr.OErrIsA(err):
        raise TypeError,"err MUST be an OErr"
    #
    Obit.TableCCUtilT2Spec(inImage.me, outImage.me, nTerm, inCCVer, \
                           outCCVer, startCC, endCC, err.me)
    if err.isErr:
        OErr.printErrMsg(err, "Error Converting CC Table")