Exemplo n.º 1
0
def plot_maps(inputfile, outputfile, eps=False, exclude=[], sky=False, labelfibers=True, MLWA=True):

    if MLWA:
        data = np.loadtxt(inputfile, usecols=(12,), unpack=True)
        label = "Mean Light Weighted Age [Gyr]"
        minval = np.nanmin(data)
        maxval = np.nanmax(data)
    else:
        data = np.loadtxt(inputfile, usecols=(11,), unpack=True)
        label = "Mean Mass Weighted Age [Gyr]"
        minval = np.nanmin(data)  # 7
        maxval = np.nanmax(data)  # 10

    map_ax = GPP.plot_img(
        data,
        fitsfile="/d/monk/eigenbrot/WIYN/14B-0456/NGC_891.fits",
        imrot=67.0,
        pa=295.787,
        center=[35.6034125, 42.32349444],
        clabel=label,
        method="cubic",
        cmap="gnuplot2",
        exclude=exclude,
        sky=sky,
        minval=minval,
        maxval=maxval,
    )

    fiber_ax = GPP.plot(
        data,
        fitsfile="/d/monk/eigenbrot/WIYN/14B-0456/NGC_891.fits",
        imrot=67.0,
        pa=295.787,
        center=[35.6034125, 42.32349444],
        clabel=label,
        cmap="gnuplot2",
        labelfibers=labelfibers,
        exclude=exclude,
        sky=sky,
        minval=minval,
        maxval=maxval,
    )

    if eps:
        fiber_name = outputfile + "_fibers.eps"
        map_name = outputfile + "_map.eps"

        fiber_ax.figure.savefig(fiber_name, format="eps")
        map_ax.figure.savefig(map_name, format="eps")
    else:
        pp = PDF(outputfile)
        pp.savefig(fiber_ax.figure)
        pp.savefig(map_ax.figure)
        pp.close()

    # plt.close(fiber_ax.figure)
    # plt.close(map_ax.figure)

    return fiber_ax
Exemplo n.º 2
0
def all_maps(
    output,
    col=12,
    inputprefix="NGC_891",
    inputsuffix="fit.dat",
    labelfibers=False,
    label="Mean Light Weighted Age [Gyr]",
    log=False,
    plotbins=False,
    minval=None,
    maxval=None,
    exclude=None,
    binned=False,
    cmap="gnuplot2",
):

    pp = PDF(output)
    centers = [
        [35.603413, 42.323494],
        [35.615154, 42.3426],
        [35.636325, 42.37935],
        [35.625617, 42.35935],
        [35.591642, 42.304247],
        [35.648196, 42.401217],
    ]

    ax = None
    if exclude is None:
        exclude = [[], [], [], [], [], []]
    figlist = []
    for i in range(6):
        print i
        try:
            inputfile = glob("{}*P{}*{}".format(inputprefix, i + 1, inputsuffix))[0]
        except IndexError:
            print "Could not find P{} data, skipping".format(i + 1)
            continue

        print inputfile

        if binned:
            fitsname = glob("{}*P{}*ms*fits".format(inputprefix, i + 1))[0]
            print fitsname
            binhead = pyfits.open(fitsname)[0].header
        else:
            binhead = None

        data = np.loadtxt(inputfile, usecols=(col,), unpack=True)
        if col == 12:
            label = "Mean Light Weighted Age [Gyr]"
            minval = 0
            maxval = 13  # np.nanmax(data)
        elif col == 11:
            label = "Mean Mass Weighted Age [Gyr]"
            minval = 0  # np.nanmin(data)#7
            maxval = 10  # np.nanmax(data)#10
        elif col == 13:
            label = "$A_V$"
            data *= 1.086
            minval = 0
            maxval = 6
        elif col == 19:
            data = np.log10(data)
            label = r"Log( Metallicity [$Z_{\odot}$] )"
            # cmap = mplcolors.ListedColormap(['black','blue','green','yellow','red','white'])
            # norm = mplcolors.BoundaryNorm([0,0.005,0.02,0.2,0.4,1,2.5], cmap.N)
            minval = -4
            maxval = 1
        elif col == 65:
            data *= 1.086

        if log:
            data = np.log10(data)
            if i == 0:
                label = "Log( {} )".format(label)
        print "excluding", exclude[i]
        ax = GPP.plot(
            data,
            ax=ax,
            binheader=binhead,
            plotbins=plotbins,
            figsize=(8, 4),
            fitsfile="/d/monk/eigenbrot/WIYN/14B-0456/NGC_891.fits",
            wcsax=False,
            imrot=67,  # 64.213,
            pa=295.787,
            center=centers[i],
            clabel=label,
            cmap=cmap,
            labelfibers=labelfibers,
            exclude=exclude[i],
            sky=False,
            minval=minval,
            maxval=maxval,
            alpha=1,
        )

        # Do it again, for the single-pointing figure
        sax = GPP.plot(
            data,
            ax=None,
            binheader=binhead,
            plotbins=plotbins,
            figsize=(8, 4),
            fitsfile="/d/monk/eigenbrot/WIYN/14B-0456/NGC_891.fits",
            wcsax=False,
            imrot=67,  # 64.213,
            pa=295.787,
            center=centers[i],
            clabel=label,
            cmap=cmap,
            labelfibers=labelfibers,
            exclude=exclude[i],
            sky=False,
            minval=minval,
            maxval=maxval,
            alpha=1,
        )
        sax.text(
            0.5, 0.8, "P{}".format(i + 1), color="r", fontsize=20, transform=sax.transAxes, ha="center", va="center"
        )
        figlist.append(sax.figure)

    ax.set_xlim(160, 755)
    ax.set_ylim(350, 600)
    header = pyfits.open("/d/monk/eigenbrot/WIYN/14B-0456/NGC_891.fits")[0].header
    hw = pywcs.WCS(header)
    centpx = hw.wcs_sky2pix([[35.63689, 42.34633]], 0)[0]
    xticks = np.arange(-300, 301, 100) / (header["CDELT1"] * 3600.0) + centpx[0]
    yticks = np.arange(-100, 201, 100) / (header["CDELT2"] * 3600.0) + centpx[1]
    ax.set_xticks(xticks)
    ax.set_yticks(yticks)
    xlabs = ["{:3.0f}".format((centpx[0] - i) * header["CDELT1"] * 3600.0) for i in ax.get_xticks()]
    ylabs = ["{:3.0f}".format((i - centpx[1]) * header["CDELT2"] * 3600.0) for i in ax.get_yticks()]
    ax.set_xticklabels(xlabs)
    ax.set_yticklabels(ylabs)
    ax.set_xlabel("arcsec")
    ax.set_ylabel("arcsec")
    pp.savefig(ax.figure)
    for f in figlist:
        pp.savefig(f)
    pp.close()
    plt.close("all")
    return ax