예제 #1
0
def doFourPlot(specs, labels, file="None", \
           xlabel="Velocity (km/s)", ylabel="Flux Density (Jy)", \
           lwidth=1,csize=1,symbol=3):
    """ Plots and displays a simple spectrum

    accepts spectrum in a dictionary with entries
       vel = vel coordinate
       flux = flux
    specs  = list of input spectra (up to four) to plot with symbol
    labels = plot label list
    file   = name of output postscript file, if "None" ask
             "/xterm" gives xterm display
    xlabel = [optional] x axis label
    ylabel = [optional] y axis label
    lwidth = [optional] line width (integer)
    csize  = [optional] symbol size (integer)
    symbol = [optional] plot symbol code
    """
    ################################################################
    # Add "/PS" for postscript files
    if file != "None" and file != "/xterm":
        filename = file + "/ps"
    else:
        filename = file
    # Create plot object
    err = Image.err
    plot = OPlot.newOPlot("plot", err, output=filename, nx=2, ny=2)
    # Loop over plots
    for i in range(0, len(specs)):
        spec = specs[i]
        label = labels[i]
        xmin = 0.95 * min(spec['vel'])
        xmax = 1.05 * max(spec['vel'])
        ymin = 0.95 * min(spec['flux'])
        ymax = 1.05 * max(spec['flux'])
        # Set labeling on plot InfoList member
        info = plot.List
        dim = [1, 1, 1, 1, 1]
        InfoList.PPutFloat(info, "XMAX", dim, [xmax], err)
        InfoList.PPutFloat(info, "XMIN", dim, [xmin], err)
        InfoList.PPutFloat(info, "YMAX", dim, [ymax], err)
        InfoList.PPutFloat(info, "YMIN", dim, [ymin], err)
        InfoList.PPutInt(info, "LWIDTH", dim, [lwidth], err)
        InfoList.PPutInt(info, "CSIZE", dim, [csize], err)
        dim[0] = max(1, len(label))
        InfoList.PAlwaysPutString(info, "TITLE", dim, [label])
        dim[0] = max(1, len(xlabel))
        InfoList.PAlwaysPutString(info, "XLABEL", dim, [xlabel])
        dim[0] = max(1, len(ylabel))
        InfoList.PAlwaysPutString(info, "YLABEL", dim, [ylabel])
        x = spec["vel"]
        y = spec["flux"]
        OPlot.PXYPlot(plot, symbol, x, y, err)
        # end loop over plots
    OPlot.PShow(plot, err)
    del plot
예제 #2
0
파일: UVPolnUtil.py 프로젝트: mauch/Obit-1
def PlotPD (inUV, PDDict, plotfile, err, title="plot"):
    """
    Plot array of PD elipticities and orientations

    * inUV     = Obit UV data with tables
    * fitDict  = dict returned by ExtractPD with entries
     'Elip1' array of elipticities poln 1 in deg
     'Ori1'  array of orientations poln 1 in deg
     'Elip2' array of elipticities poln 2 in deg
     'Ori2'  array of orientations poln 2 in deg
     'Freqs' array of frequencies corresponding to data
     'refant' reference antenna
     'ant'    antenna
    * plotfile = name of postscript plot file
    * err      = Obit Error/message stack
    * title    = title for plot
    """
    Earr = []; Oarr = []
    Earr.append(PDDict['Elip1']); Oarr.append(PDDict['Ori1']);
    Earr.append(PDDict['Elip2']); Oarr.append(PDDict['Ori2']);
    xa = PDDict['Freqs']
    plot = OPlot.newOPlot("plot", err, output=plotfile+"/ps", nx=2, ny=2)
    nplot = len(Earr[0])
    if xa==None:
        x = []
        for i in range(0, len(Earr[0])):
            x.append(float(i))
    else:
        x = xa
    # Loop over poln
    pol = [" RCP"," LCP"]
    for ipol in range (0,2):
        symb = 2
        # Plot elipticities
        plot.List.set("TITLE",title+pol[ipol])
        if (max(Earr[ipol])>0. and max(Earr[ipol])<1000.) or  min(Earr[ipol])>0.:
            plot.List.set("YMIN",35.0); plot.List.set("YMAX",46.0);
            #print "RCP data", min(Earr[ipol])
        else:
            plot.List.set("YMIN",-46.0); plot.List.set("YMAX",-35.0);
            #print "LCP data", min(Earr[ipol])
        if xa==None:
            plot.List.set("XLABEL","Channel")
        else:
            plot.List.set("XLABEL","Frequency (GHz)")
        plot.List.set("YLABEL","Ellipticity (deg)")
        OPlot.PXYPlot(plot, symb, x, Earr[ipol], err)
        # Plot orientations
        symb = 2
        plot.List.set("TITLE","    ")
        plot.List.set("YMIN",-180.0); plot.List.set("YMAX",180.0);
        plot.List.set("YLABEL","Orientation (deg)")
        OPlot.PXYPlot(plot, symb, x, Oarr[ipol], err)
    # end poln loop
    OPlot.PShow(plot,err)
예제 #3
0
def doPlot(spec, spec2, label, file="None", \
           xlabel="Velocity (km/s)", ylabel="Flux Density (Jy)", \
           lwidth=1,csize=1,symbol=3):
    """ Plots and displays a spectrum

    accepts spectrum in a dictionary with entries
       vel = vel coordinate
       flux = flux
    spec   = input spectrum to plot with solid line
    spec2  = input spectrum to plot with symbol
    label  = plot label
    file   = name of output postscript file, if "None" ask
             "/xterm" gives xterm display
    xlabel = [optional] x axis label
    ylabel = [optional] y axis label
    lwidth = [optional] line width (integer)
    csize  = [optional] symbol size (integer)
    symbol = [optional] plot symbol code
    """
    ################################################################
    xmin = min(min(spec['vel']), min(spec2['vel']))
    xmax = max(max(spec['vel']), max(spec2['vel']))
    ymin = 1.05 * min(min(spec['flux']), min(spec2['flux']))
    ymax = 1.1 * max(max(spec['flux']), max(spec2['flux']))
    # Add "/PS" for postscript files
    if file != "None" and file != "/xterm":
        filename = file + "/ps"
    else:
        filename = file
    # Create plot object
    err = Image.err
    plot = OPlot.newOPlot("plot", err, output=filename)
    # Set labeling on plot InfoList member
    info = plot.List
    dim = [1, 1, 1, 1, 1]
    InfoList.PPutFloat(info, "XMAX", dim, [xmax], err)
    InfoList.PPutFloat(info, "XMIN", dim, [xmin], err)
    InfoList.PPutFloat(info, "YMAX", dim, [ymax], err)
    InfoList.PPutFloat(info, "YMIN", dim, [ymin], err)
    InfoList.PPutInt(info, "LWIDTH", dim, [lwidth], err)
    InfoList.PPutInt(info, "CSIZE", dim, [csize], err)
    dim[0] = max(1, len(label))
    InfoList.PAlwaysPutString(info, "TITLE", dim, [label])
    dim[0] = max(1, len(xlabel))
    InfoList.PAlwaysPutString(info, "XLABEL", dim, [xlabel])
    dim[0] = max(1, len(ylabel))
    InfoList.PAlwaysPutString(info, "YLABEL", dim, [ylabel])
    x = spec["vel"]
    y = spec["flux"]
    OPlot.PXYPlot(plot, -1, x, y, err)
    x = spec2["vel"]
    y = spec2["flux"]
    OPlot.PXYOver(plot, symbol, x, y, err)
    OPlot.PShow(plot, err)
예제 #4
0
파일: UVPolnUtil.py 프로젝트: mauch/Obit-1
def PlotRM(inUV, fitDict, plotFile, title, err):
    """
    Plot data and model
    
    Return list of channel lambda^2 (m^2)
    * inUV     = Obit UV data with tables
    * fitDict  = dict returned by PFitSource
    * plotFile = output ps plotfile name
    * title    = plot title
    * err      = Python Obit Error/message stack
    """
    ################################################################
    plot=OPlot.newOPlot("Plot", err,output=plotFile+"/ps",ny=2)
    # Extract data, fits
    RM    = fitDict["RM"];     RMErr    = fitDict["RMErr"];
    EVPA0 = fitDict["EVPA0"];  EVPAErr  = fitDict["EVPAErr"];
    lamb2 = fitDict["Lamb2"];  refLamb2 = fitDict["RefLamb2"];
    EVPA  = fitDict["EVPA"];   fpol     = fitDict["FPol"];
    # angles to deg
    EVPA0 = math.degrees(EVPA0); EVPAErr = math.degrees(EVPAErr); 
    phs = []
    for angle in EVPA :
        phs.append(math.degrees(angle))
    
    # Plot EVPA
    plot.List.set("TITLE","%s RM=%6.2f (%5.2f) EVPA=%6.2f (%5.2f) "\
                      %(title, RM, RMErr, EVPA0, EVPAErr))
    plot.List.set("YLABEL","EVPA (deg)")
    plot.List.set("CSIZE",1)
    plot.List.set("SSIZE",3)
    plot.List.set("LWIDTH",3)
    OPlot.PXYPlot(plot, 2, lamb2, phs, err)
    # Plot RM fit
    nspec = len(lamb2)
    x1 = lamb2[0] - refLamb2
    y1 = EVPA0 + math.degrees(RM*x1)
    x2 = lamb2[nspec-1] - refLamb2
    y2 = EVPA0 + math.degrees(RM*x2)
    OPlot.PDrawLine(plot, lamb2[0], y1, lamb2[nspec-1], y2, err)
    # Plot fractional poln
    plot.List.set("TITLE"," ")
    plot.List.set("XLABEL","#gl#u2#d (m#u2#d)")
    plot.List.set("YLABEL","frac. pol.")
    plot.List.set("XMAX",lamb2[0])
    plot.List.set("XMIN",lamb2[nspec-1])
    plot.List.set("YMIN",0.0)
    plot.List.set("YMAX",0.1)
    OPlot.PXYPlot(plot, 2, lamb2, fpol, err)
    OPlot.PShow(plot,err)
예제 #5
0
def labelLogPlot(plot, xmin, xmax, ymin, ymax, err, vals=None):
    """ Label log-log plots - plPlot is completely incompetent at this

    plot   = plot to label
    xmin   = xmin of plot, normal units
    xmax   = xmax of plot, normal units
    ymin   = ymin of plot, normal units
    ymax   = ymax of plot, normal units
    vals   = list of strings of values to plot
    """
    ################################################################
    # Default values of labels
    defvals = ["0.002", "0.003", "0.004", "0.005", "0.007", \
               "0.02", "0.03", "0.04", "0.05", "0.07", \
               "0.2", "0.3", "0.4", "0.5", "0.7", \
               "2", "3", "4", "5", "6", "7", "8", "9", \
               "20", "30", "40", "50", "70", \
               "200", "300", "400", "500", "700", \
               "2000", "3000", "4000", "5000", "7000", \
               ]
    if vals == None:
        pltVals = defvals
    else:
        pltVals = vals

    # logs of extrema
    logxmin = math.log10(xmin)
    logxmax = math.log10(xmax)
    logymin = math.log10(ymin)
    logymax = math.log10(ymax)

    # X axis
    fjust = 0.5
    for val in pltVals:
        num = float(val)
        if (num >= xmin) and (num <= xmax):
            disp = len(val)
            coord = (math.log10(num) - logxmin) / (logxmax - logxmin)
            OPlot.PRelText(plot, "B", disp, coord, fjust, val, err)
    # end loop
    # Y axis
    fjust = 0.0
    for val in pltVals:
        num = float(val)
        if (num >= ymin) and (num <= ymax):
            disp = len(val)
            coord = (math.log10(num) - logymin) / (logymax - logymin)
            OPlot.PRelText(plot, "LV", disp, coord, fjust, val, err)
예제 #6
0
파일: VEGASUtil.py 프로젝트: mauch/Obit-1
def PlotSpectrum (inData, targets, scans, feed, Stokes, channs, err, \
              output="None", bgcolor=0):
    """ Plot selected data

    Plot data in inData selected by targets and scans
    inData  = OTF data set to be plotted, any calibration and editing will be applied
    targets = list of target names, empty list = all
    scans   = Range of scan number, 0's => all
    feed    = feed to plot
    Stokes  = Stokes product 0=XX, 1=YY, 2=Real(XY), 3=Imag(XY)
    channs  = [first, last] channels to plot, 1-rel
    err     = Python Obit Error/message stack
    output  = name and type of output device:
              "None"  interactive prompt
              "xwin"  X-Window (Xlib)
              "gcw"   Gnome Canvas Widget (interacts with ObitTalk)
              "ps"    PostScript File (monochrome)
              "psc"   PostScript File (color)
              "xfig"  Fig file
              "png"   PNG file
              "jpeg"  JPEG file
              "gif"   GIF file
              "null"  Null device
    bgcolor   = background color index (1-15), symbolic names:
                BLACK, RED(default), YELLOW, GREEN, 
                AQUAMARINE, PINK, WHEAT, GRAY, BROWN,
                BLUE, BLUEVIOLET, CYAN, TURQUOISE,
                MAGENTA, SALMON, WHITE
    """
    # Set selection
    inInfo = inData.List
    inInfo.set("doCalSelect", True)  # Do selection
    if len(targets) > 0:
        inInfo.set("Targets", targets)  # select only target data
    if scans[0] > 0 and scans[1] > 0:
        lscans = scans
    else:
        lscans = [1, 10000000]
    inInfo.set("Scans", lscans)
    inInfo.set("Feeds", [feed])
    inInfo.set("BChan", channs[0])
    inInfo.set("EChan", channs[1])

    inData.Open(OTF.READONLY, err)
    d = inData.Desc.Dict
    nrec = d["nrecord"]
    nchan = d["inaxes"][d["jlocf"]]
    incs = d["incs"] / 2
    incf = d["incf"] / 2
    off = Stokes * incs
    # Init accumulators
    spec = []
    wt = []
    for i in range(0, nchan):
        spec.append(0.0)
        wt.append(0.0)
    # Loop over data
    for i in range(1, nrec + 1):
        rec = inData.ReadRec(err)
        # eod of file?
        eof = 'EOF' in rec.__dict__
        if eof:
            break
        OErr.printErrMsg(err, "Error reading OTF data")
        for j in range(0, nchan):
            indx = off + j * incf
            if (rec.data[indx][1] != 0.0) and (rec.data[indx][0] !=
                                               FArray.fblank):
                spec[j] += rec.data[indx][0] * rec.data[indx][1]
                wt[j] += rec.data[indx][1]
    # end loop over data
    inData.Close(err)

    ch = []
    for j in range(0, nchan):
        ch.append(float(j + channs[0]))

        if wt[j] > 0.0:
            spec[j] /= wt[j]
            #spec[j] = min(spec[j],1000.0)
        else:  # Hide at 0
            spec[j] = FArray.fblank
            ch[j] = ch[0]
    # Anything selected
    if len(spec) <= 0:
        raise RuntimeError, 'No data selected to plot'
    # plot
    plot = OPlot.newOPlot("plot", err, output=output, bgcolor=bgcolor)
    plotInfo = plot.List
    plotInfo.set("XLABEL", "Channel")
    plotInfo.set("YLABEL", "Flux density")
    plotInfo.set("XMIN", 1)
    #plotInfo.set("YMIN",0.0)
    #plotInfo.set("YMAX",1000.0)
    plotInfo.set("TITLE", "Poln " + str(Stokes))
    #print spec
    OPlot.PXYPlot(plot, 2, ch, spec, err)
    OPlot.PShow(plot, err)
    OErr.printErrMsg(err, "Error plotting OTF/VEGAS data")
예제 #7
0
    Image.PGetPlane(icube, None, plane, err)
    rms.append(icube.FArray.RMS)  # Plane RMS
    # Interpolate positions
    for j in range(0, len(pixels)):
        pixel = pixels[j]
        val = FInterpolate.PPixel(fi, pixel, err)
        print(i, j, val, rms[i], freqs[i])
        if val > 0.0:
            vals[j][i] = val

# end loop over planes
OErr.printErrMsg(err, message='Interpolating values')

# Plot
pname = name
plot = OPlot.newOPlot("Plot", err, output=pname + ".ps/ps")
i = -1
for s in srcpos:
    i += 1
    plot.List.set("TITLE"," %s %s %s %s"\
                  %(name, s[0], s[1],s[2]))
    plot.List.set("YLABEL", "Flux density (Jy)")
    plot.List.set("XLABEL", "Frequency (GHz)")
    plot.List.set("XOPT", "LBCN")
    plot.List.set("YOPT", "LBCN")
    #plot.List.set("XMAX",1.1*max(freqs))
    #plot.List.set("XMIN",0.9*min(freqs))
    ymn = 0.9 * 10**int(-0.9 + math.log10(min(vals[i])))
    #ymx = ymn * 10.
    print(ymn, min(vals[i]))
    plot.List.set("YMIN", ymn)
예제 #8
0
ObitSys = OSystem.OSystem("Plot", 1, 100, 0, ["None"], 1, [dataDir], 1, 0, err)
OErr.printErrMsg(err, "Error with Obit startup")

# Contour plot
file = "AGNVLA.fits"
plotfile = "testCont.ps"
lev = 0.1
cntfac = 2.0**0.5
blc = [230, 119]
trc = [285, 178]
img = Image.newPFImage("in image", file, 1, True, err)
info = img.List
info.set("BLC", blc)
info.set("TRC", trc)

cont = OPlot.newOPlot("cont", err, output=plotfile + "/ps")
OPlot.PContour(cont, "Some AGN", img, lev, cntfac, err)
# Text
txt=[(265.0,155.0,"A"), \
     (258.0,155.0,"B"), \
     (251.0,152.0,"C"), \
     (247.0,149.0,"D"), \
     (241.0,146.0,"E"), \
     (244.0,141.0,"F")]
OPlot.PSetCharSize(cont, 1, err)
for ss in txt:
    x = -(ss[0] - 1. - 250.9) * 2.0 / 60.0
    y = (ss[1] - 1. - 150.1) * 2.0 / 60.0
    OPlot.PText(cont, x, y, 180.0, 0.5, ss[2], err)

OPlot.PShow(cont, err)
예제 #9
0
def doVPlot(spec, spec2, label, fact2=1.0, file="None", \
           xlabel="Velocity (km/s)", ylabel="Flux Density (Jy)", \
           lwidth=2,csize=1,symbol=3, Stokes="V"):
    """ Plots and displays an I and Stokes Stokes spectrum 

    accepts spectrum in a dictionary with entries
       vel = vel coordinate
       flux = flux
    spec   = IPol spectrum
    spec2  = VPol spectrum to plot with solid line, scaled on return
    fact2  = Factor to multiple times spec2 flux
    label  = plot label
    file   = name of output postscript file, if "None" ask
             "/xterm" gives xterm display
    xlabel = [optional] x axis label
    ylabel = [optional] y axis label
    lwidth = [optional] line width (integer)
    csize  = [optional] symbol size (integer)
    symbol = [optional] plot symbol code
    """
    ################################################################
    # Scale second spectrum
    if fact2 != 1.0:
        for i in range(0, len(spec2["flux"])):
            spec2["flux"][i] *= fact2

    xmin = min(min(spec['vel']), min(spec2['vel']))
    xmax = max(max(spec['vel']), max(spec2['vel']))
    ymin = 1.05 * min(min(spec['flux']), min(spec2['flux']))
    ymax = 1.1 * max(max(spec['flux']), max(spec2['flux']))
    # Add "/PS" for postscript files
    if file != "None" and file != "/xterm":
        filename = file + "/ps"
    else:
        filename = file
    # Create plot object
    err = Image.err
    plot = OPlot.newOPlot("plot", err, output=filename)
    # Set labeling on plot InfoList member
    info = plot.List
    dim = [1, 1, 1, 1, 1]
    InfoList.PPutFloat(info, "XMAX", dim, [xmax], err)
    InfoList.PPutFloat(info, "XMIN", dim, [xmin], err)
    InfoList.PPutFloat(info, "YMAX", dim, [ymax], err)
    InfoList.PPutFloat(info, "YMIN", dim, [ymin], err)
    InfoList.PPutInt(info, "LWIDTH", dim, [lwidth], err)
    InfoList.PPutInt(info, "CSIZE", dim, [csize], err)
    dim[0] = max(1, len(label))
    InfoList.PAlwaysPutString(info, "TITLE", dim, [label])
    dim[0] = max(1, len(xlabel))
    InfoList.PAlwaysPutString(info, "XLABEL", dim, [xlabel])
    dim[0] = max(1, len(ylabel))
    InfoList.PAlwaysPutString(info, "YLABEL", dim, [ylabel])
    x = spec["vel"]
    y = spec["flux"]
    OPlot.PXYPlot(plot, -1, x, y, err)
    x = spec2["vel"]
    y = spec2["flux"]
    OPlot.PXYOver(plot, symbol, x, y, err)
    # Label
    tx = xmin + 0.02 * (xmax - xmin)
    ty = ymax - 0.05 * (ymax - ymin)
    OPlot.PText(plot, tx, ty, 0.0, 0.0, "Line = I", err)
    ty = ymax - 0.09 * (ymax - ymin)
    OPlot.PText(plot, tx, ty, 0.0, 0.0, "* = " + Stokes + "*" + str(fact2),
                err)
    OPlot.PShow(plot, err)
예제 #10
0
def doSimpleLogPlot(spec, label, file="None", \
           xlabel="Freq (MHz)", ylabel="Flux Density (mJy)", \
           lwidth=1,csize=1,symbol=3):
    """ Plots and displays a simple log=log spectrum

    accepts spectrum in a dictionary with entries
       freq    = freq coordinate (MHz)
       flux    = flux (mJy)
       refFreq = reference frequency
       fitSpec = fitted spectrum, plotted as line if given
    spec   = input spectrum to plot with symbol
    label  = plot label
    file   = name of output postscript file, if "None" ask
             "/xterm" gives xterm display
    xlabel = [optional] x axis label
    ylabel = [optional] y axis label
    lwidth = [optional] line width (integer)
    csize  = [optional] symbol size (integer)
    symbol = [optional] plot symbol code
    """
    ################################################################
    xmin = 0.95 * min(spec['freq'])
    xmax = 1.05 * max(spec['freq'])
    ymin = 0.95 * min(spec['flux'])
    ymax = 1.05 * max(spec['flux'])
    # Add "/PS" for postscript files
    if file != "None" and file != "/xterm":
        filename = file + "/ps"
    else:
        filename = file
    # Create plot object
    err = Image.err
    plot = OPlot.newOPlot("plot", err, output=filename)
    # Set labeling on plot InfoList member
    info = plot.List
    dim = [1, 1, 1, 1, 1]
    InfoList.PPutFloat(info, "XMAX", dim, [xmax], err)
    InfoList.PPutFloat(info, "XMIN", dim, [xmin], err)
    InfoList.PPutFloat(info, "YMAX", dim, [ymax], err)
    InfoList.PPutFloat(info, "YMIN", dim, [ymin], err)
    InfoList.PPutInt(info, "LWIDTH", dim, [lwidth], err)
    InfoList.PPutInt(info, "CSIZE", dim, [csize], err)
    dim[0] = max(1, len(label))
    InfoList.PAlwaysPutString(info, "TITLE", dim, [label])
    dim[0] = max(1, len(xlabel))
    InfoList.PAlwaysPutString(info, "XLABEL", dim, [xlabel])
    dim[0] = max(1, len(ylabel))
    InfoList.PAlwaysPutString(info, "YLABEL", dim, [ylabel])
    xopt = "BCLTS"
    dim[0] = max(1, len(xopt))
    InfoList.PAlwaysPutString(info, "XOPT", dim, [xopt])
    yopt = "BCLTS"
    dim[0] = max(1, len(yopt))
    InfoList.PAlwaysPutString(info, "YOPT", dim, [yopt])
    x = spec["freq"]
    y = spec["flux"]
    OPlot.PXYPlot(plot, symbol, x, y, err)
    # Fitted spectrum given?
    if ("fitSpec" in spec) and (spec["fitSpec"] != None) and (len(
            spec["fitSpec"]) > 0):
        refFreq = spec["refFreq"] * 1.0e-9
        ss = spec["fitSpec"]
        x = []
        y = []
        deltax = xmax - xmin
        for i in range(0, 101):
            f = xmin + i * 0.01 * deltax
            x.append(f)
            ll = math.log(f / refFreq)
            lll = math.log(f / refFreq)
            arg = 0.0
            for t in ss[1:]:
                arg += t * lll
                lll *= ll
            y.append(ss[0] * 1000.0 * math.exp(arg))
        OPlot.PXYOver(plot, 0, x, y, err)
        if len(ss) >= 3:
            speclabel = "S#d%5.1f GHz#u=%5.3f mJy, #ga= %5.2f, #gb=%5.3f" % (
                refFreq, ss[0] * 1000.0, ss[1], ss[2])
        elif len(ss) == 2:
            speclabel = "S#d%5.1f GHz#u=%5.3f mJy, #ga= %5.2f" % (
                refFreq, ss[0] * 1000.0, ss[1])
        OPlot.PRelText(plot, "T", -01.0, 0.3, 0.0, speclabel, err)

    labelLogPlot(plot, xmin, xmax, ymin, ymax, err)
    OPlot.PShow(plot, err)
    del plot
예제 #11
0
def PlotElev (inData, targets, scans, feeds, err, \
              output="None", bgcolor=0, nx=1, ny=1):
    """ Plot selected data vs elevation

    Plot data in inData selected by targets and scans
    inData  = OTF data set to be plotted, any calibration and editing will be applied
    targets = list of target names, empty list = all
    scans   = Range of scan number, 0's => all
    feeds   = list of feeds to plot
    err     = Python Obit Error/message stack
    output  = name and type of output device:
              "None"  interactive prompt
              "xwin"  X-Window (Xlib)
              "gcw"   Gnome Canvas Widget (interacts with ObitTalk)
              "ps"    PostScript File (monochrome)
              "psc"   PostScript File (color)
              "xfig"  Fig file
              "png"   PNG file
              "jpeg"  JPEG file
              "gif"   GIF file
              "null"  Null device
    bgcolor   = background color index (1-15), symbolic names:
                BLACK, RED(default), YELLOW, GREEN, 
                AQUAMARINE, PINK, WHEAT, GRAY, BROWN,
                BLUE, BLUEVIOLET, CYAN, TURQUOISE,
                MAGENTA, SALMON, WHITE
    nx        = Number of horizontal subpages
    ny        = Number of vertical subpages
    """
    # Set selection
    inInfo = inData.List
    inInfo.set("doCalSelect", True)  # Do selection
    if len(targets) > 0:
        inInfo.set("Targets", targets)  # select only target data
    if scans[0] > 0 and scans[1] > 0:
        lscans = scans
    else:
        lscans = [1, 10000000]
    inInfo.set("Scans", lscans)
    if len(feeds) > 0 and feeds[0] > 0:
        lfeeds = feeds
    else:
        lfeeds = []
        naxis = inData.Desc.Dict["inaxes"]
        nfeed = naxis[1] * max(naxis[2], 1) * max(naxis[3], 1) * max(
            naxis[4], 1)
        for i in range(0, nfeed):
            lfeeds.append(i + 1)

    inData.Open(OTF.READONLY, err)
    ag = inData.ArrayGeom  # Get array geometry
    nrec = inData.Desc.Dict["nrecord"]
    plotdata = [[]]  # time
    datagood = [False]  # data validity
    for j in lfeeds:
        plotdata.append([])
        datagood.append(False)
    # Loop over data
    for i in range(1, nrec + 1):
        rec = inData.ReadRec(err)
        # eod of file?
        eof = 'EOF' in rec.__dict__
        if eof:
            break
        OErr.printErrMsg(err, "Error reading OTF data")
        elev = ag.Elev(rec.time, rec.ra, rec.dec)
        plotdata[0].append(elev)  # Save elev
        k = 1
        for j in lfeeds:
            if rec.data[j - 1][1] != 0.0:
                plotdata[k].append(rec.data[j - 1][0])
                datagood[k] = rec.data[j - 1][0] != 0.0
            else:
                plotdata[k].append(FArray.fblank)
            k += 1

    inData.Close(err)

    # Anything selected
    if len(plotdata[0]) <= 0:
        raise RuntimeError, 'No data selected to plot'
    # plot
    plot = OPlot.newOPlot("plot",
                          err,
                          nx=nx,
                          ny=ny,
                          output=output,
                          bgcolor=bgcolor)
    plotInfo = plot.List
    plotInfo.set("XLABEL", "Elev(deg)")
    plotInfo.set("YLABEL", "Flux density(Jy)")
    nplot = len(plotdata) - 1
    for i in range(0, nplot):
        plotInfo.set("TITLE", "Detector " + str(lfeeds[i]))
        if datagood[i + 1] and max(plotdata[i + 1]) > min(plotdata[i + 1]):
            OPlot.PXYPlot(plot, 2, plotdata[0], plotdata[i + 1], err)
        # Tolerate error and keep going
        if err.isErr:
            err.Clear()
            print "ERROR occured in plotting detector", i + 1
    OPlot.PShow(plot, err)
    OErr.printErrMsg(err, "Error plotting OTF data")
예제 #12
0
def PlotPower (inData, targets, scans, feeds, err, \
              output="None", bgcolor=0, nx=1, ny=1):
    """ Plot power spectrum of selected data

    Plot data in inData selected by targets and scans
    inData  = OTF data set to be plotted, any calibration and editing will be applied
    targets = list of target names, empty list = all
    scans   = Range of scan number, 0's => all
    feeds   = list of feeds to plot
    err     = Python Obit Error/message stack
    output  = name and type of output device:
              "None"  interactive prompt
              "xwin"  X-Window (Xlib)
              "gcw"   Gnome Canvas Widget (interacts with ObitTalk)
              "ps"    PostScript File (monochrome)
              "psc"   PostScript File (color)
              "xfig"  Fig file
              "png"   PNG file
              "jpeg"  JPEG file
              "gif"   GIF file
              "null"  Null device
    bgcolor   = background color index (1-15), symbolic names:
                BLACK, RED(default), YELLOW, GREEN, 
                AQUAMARINE, PINK, WHEAT, GRAY, BROWN,
                BLUE, BLUEVIOLET, CYAN, TURQUOISE,
                MAGENTA, SALMON, WHITE
    nx        = Number of horizontal subpages
    ny        = Number of vertical subpages
    """
    # Set selection
    inInfo = inData.List
    inInfo.set("doCalSelect", True)  # Do selection
    if len(targets) > 0:
        inInfo.set("Targets", targets)  # select only target data
    if scans[0] > 0 and scans[1] > 0:
        lscans = scans
    else:
        lscans = [1, 10000000]
    inInfo.set("Scans", lscans)
    if len(feeds) > 0 and feeds[0] > 0:
        lfeeds = feeds
    else:
        lfeeds = []
        naxis = inData.Desc.Dict["inaxes"]
        nfeed = naxis[1] * max(naxis[2], 1) * max(naxis[3], 1) * max(
            naxis[4], 1)
        for i in range(0, nfeed):
            lfeeds.append(i + 1)

    inData.Open(OTF.READONLY, err)
    nrec = inData.Desc.Dict["nrecord"]
    plotdata = [[]]  # time
    datagood = [False]  # data validity
    for j in lfeeds:
        plotdata.append([])
        datagood.append(False)
    # Loop over data
    for i in range(1, nrec + 1):
        rec = inData.ReadRec(err)
        # eod of file?
        eof = 'EOF' in rec.__dict__
        if eof:
            break
        OErr.printErrMsg(err, "Error reading OTF data")
        plotdata[0].append(rec.time * 24.0)  # Save time
        k = 1
        for j in lfeeds:
            if rec.data[j - 1][1] != 0.0:
                plotdata[k].append(rec.data[j - 1][0])
                datagood[k] = rec.data[j - 1][0] != 0.0
            else:
                plotdata[k].append(FArray.fblank)
            k += 1

    inData.Close(err)

    # Create/populate TimeSeries
    ts = TimeFilter.newTimeFilter("timeSeries", len(plotdata[0]), len(lfeeds))
    k = 1
    nTime = len(plotdata[0])
    dTime = (plotdata[0][nTime - 1] - plotdata[0][0]) / nTime
    for j in lfeeds:
        TimeFilter.PGridTime(ts, k - 1, dTime, nTime, plotdata[0], plotdata[k])
        k += 1
    # Determine spectra
    TimeFilter.P2Freq(ts)

    # Anything selected
    if len(plotdata[0]) <= 0:
        raise RuntimeError, 'No data selected to plot'
    # plot
    plot = OPlot.newOPlot("plot",
                          err,
                          nx=nx,
                          ny=ny,
                          output=output,
                          bgcolor=bgcolor)
    plotInfo = plot.List
    plotInfo.set("XLABEL", "Frequency (Hz)")
    plotInfo.set("YLABEL", "Spectral Power")
    plotInfo.set("YOPT", "BCTSL")
    nplot = len(plotdata) - 1
    for i in range(0, nplot):
        # Get power spectra
        powerDict = TimeFilter.PGetPower(ts, i)
        # Zero first term
        powerDict["data"][0] = powerDict["data"][1]
        plotInfo.set("TITLE", "Detector " + str(lfeeds[i]))
        if datagood[i + 1] and max(plotdata[i + 1]) > min(plotdata[i + 1]):
            OPlot.PXYPlot(plot, 2, powerDict["freq"], powerDict["data"], err)
        OErr.printErrMsg(err, "Error plotting OTF data")
    OPlot.PShow(plot, err)
    OErr.printErrMsg(err, "Error plotting OTF data")
예제 #13
0
ObitSys=OSystem.OSystem ("Plot", 1, 100, 0, ["None"], 1, ["../testIt/"], 1, 0, err)
OErr.printErrMsg(err, "Error with Obit startup")

# Contour plot
file = "AGNVLA.fits"
plotfile = "testCont.ps"
lev=0.1
cntfac = 2.0**0.5
blc =[ 230,119]
trc = [285,178]
img = Image.newPFImage("in image",file, 1, True, err)
info=img.List
info.set("BLC",blc)
info.set("TRC",trc)

cont = OPlot.newOPlot("cont", err, output=plotfile+"/ps")
OPlot.PContour(cont, "Some AGN", img, lev, cntfac, err)
# Text
txt=[(265.0,155.0,"A"), \
     (258.0,155.0,"B"), \
     (251.0,152.0,"C"), \
     (247.0,149.0,"D"), \
     (241.0,146.0,"E"), \
     (244.0,141.0,"F")]
OPlot.PSetCharSize(cont, 1 ,err)
for ss in txt:
    x=-(ss[0]-1.-250.9)*2.0/60.0; y=(ss[1]-1.-150.1)*2.0/60.0;
    OPlot.PText(cont, x, y, 180.0, 0.5, ss[2],err)

OPlot.PShow(cont,err)
print "Coutour plot of",file,"written to",plotfile
예제 #14
0
파일: PangleOTF.py 프로젝트: mauch/Obit-1
                                math.atan2(uflux[ip], qflux[ip]))

    # Remove phase wraps
    for ip in range(1, nsamp):
        if phs[ip] - phs[ip - 1] > 130.:
            phs[ip] -= 180.
        if phs[ip] - phs[ip - 1] < -130.:
            phs[ip] += 180.

    # Fit RM
    refLamb2 = lamb2[nspec / 2]
    RMParms = RMFit.PSingle(refLamb2, lamb2, qflux, qRMS, uflux, uRMS, err)

    pname = "Poln%4.4d.%4.4d" % (pixel[0], pixel[1])
    print "Plot", pname
    plot = OPlot.newOPlot("Plot", err, output=pname + ".ps/ps", ny=2)
    # Plot EVPA
    plot.List.set("TITLE","Pixel %d %d, RM=%6.2f (%5.2f)"\
                  %(pixel[0],pixel[1], RMParms[0], RMParms[2]))
    plot.List.set("YLABEL", "EVPA (deg)")
    plot.List.set("CSIZE", 1)
    plot.List.set("SSIZE", 3)
    plot.List.set("LWIDTH", 3)
    OPlot.PXYErr(plot, 2, l2, phs, ephs, err)
    # Plot RM fit - a few times
    noff = 7
    offs = [0.0, 180, -180., 360., -360, 540. - 540.]
    for off in offs:
        x1 = lamb2[0] - refLamb2
        y1 = math.degrees(RMParms[1] + RMParms[0] * x1) + off
        x2 = lamb2[nspec - 1] - refLamb2