Beispiel #1
0
def modelBHFitGrid(inFolder=None,plotOnly=False):
    # routine to conduct a grid search over SMBH positions

    cubeimg = pyfits.getdata(datadir + cuberoot + '_img.fits')
    xaxis = np.arange(cubeimg.shape[0]) * 0.05
    yaxis = np.arange(cubeimg.shape[1]) * 0.05

    # original angles
    Lorg = -42.8
    Iorg = 54.1
    Aorg = -34.5
    CPA = -56.

    # BH step size, in pixels
    dPix = 1.
    # number of steps away from the original angle in each direction (-/+)
    # halfN = 1 gives 3 total steps, =2 gives 5 steps
    halfN = 2.
    N = (halfN*2)+1
    startpos = [0.,0.]

    posgridx = np.arange(startpos[0]-(halfN*dPix),startpos[0]+(halfN*dPix)+0.5,dPix)
    posgridy = np.arange(startpos[1]-(halfN*dPix),startpos[1]+(halfN*dPix)+0.5,dPix)
        
    if not plotOnly:
        # create the new folder
        FORMAT = '%Y%m%d_%H-%M-%S'
        now = datetime.datetime.now().strftime(FORMAT)
        newfolder = modeldir+'nonaligned_SMBH_grid_'+now+'/'
        os.mkdir(newfolder)
        #newfolder='/Users/kel/Documents/Projects/M31/models/Peiris/2003/nonaligned_grid_rotate_20160919_17-09-05/'

        for pX in posgridx:
            for pY in posgridy:
                testpos = [pX,pY]
                modelConvertBin(testSMBH=testpos,l98bin=False,verbose=False,tess=True,pathstem=newfolder)
                modelCompRes(inModel=newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f.dat' % (testpos[0],testpos[1]),toPlot=False)

    # plotting
    py.close(2)
    py.figure(2, figsize=(17,12))
    py.subplots_adjust(left=0.05, right=0.94, top=0.95)
    nPlot = N**2
    # flux plots
    py.clf()
    plYY = np.fliplr([posgridy])[0]
    plXX = np.fliplr([posgridx])[0]
    pX,pY = np.meshgrid(plXX,plYY)
    pX = pX.flatten()
    pY = pY.flatten()
    for pp in np.arange(nPlot):
        py.subplot(N,N,pp+1)
        #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
        if inFolder:
            inRes = inFolder+'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (pX[pp],pY[pp])
        else:
            inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (pX[pp],pY[pp])
        res = ppxf_m31.modelFitResults(inRes)
        py.imshow(np.rot90(py.ma.masked_where(cubeimg==0.,res.nstar.T),3),vmin=-0.25,vmax=0.25,
                extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
        # with the rotation+transposition of the residual image, the sign of dx is flipped (dy stays the same)
        pltitle = '%.1f, %.1f' % (-1.*pX[pp],pY[pp])
        py.title(pltitle)
        py.xticks([])
        py.yticks([])
    cbar = py.colorbar(orientation='horizontal',ticks=[-.25,0.,.25])
    clab = 'Flux res., $\\bullet_{model}$ at dx,dy'
    cbar.set_label(clab)
    if inFolder:
        figname = inFolder + 'residuals_flux_SMBH.png'
    else:
        figname=newfolder + 'residuals_flux_SMBH.png'
    py.savefig(figname)

    # velocity plots - can probably integrate with flux plotting
    py.clf()
    for pp in np.arange(nPlot):
        py.subplot(N,N,pp+1)
        #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
        if inFolder:
            inRes = inFolder+'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (pX[pp],pY[pp])
        else:
            inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (pX[pp],pY[pp])
        res = ppxf_m31.modelFitResults(inRes)
        py.imshow(np.rot90(py.ma.masked_where(cubeimg==0.,res.velocity.T),3),vmin=-100.,vmax=200.,
                extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
        pltitle = '%.1f, %.1f' % (-1.*pX[pp],pY[pp])
        py.title(pltitle)
        py.xticks([])
        py.yticks([])
    cbar = py.colorbar(orientation='horizontal',ticks=[-100,0.,200])
    clab = 'Velocity res., $\\bullet_{model}$ at dx,dy'
    cbar.set_label(clab)
    if inFolder:
        figname = inFolder + 'residuals_velocity_SMBH.png'
    else:
        figname=newfolder + 'residuals_velocity_SMBH.png'
    py.savefig(figname)

    # sigma plots
    py.clf()
    for pp in np.arange(nPlot):
        py.subplot(N,N,pp+1)
        #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
        if inFolder:
            inRes = inFolder+'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (pX[pp],pY[pp])
        else:
            inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (pX[pp],pY[pp])
        res = ppxf_m31.modelFitResults(inRes)
        py.imshow(np.rot90(py.ma.masked_where(cubeimg==0.,res.sigma.T),3),vmin=-100.,vmax=100.,
                extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
        pltitle = '%.1f, %.1f' % (-1.*pX[pp],pY[pp])
        py.title(pltitle)
        py.xticks([])
        py.yticks([])
    cbar = py.colorbar(orientation='horizontal',ticks=[-100,0.,100])
    clab = 'Sigma res., $\\bullet_{model}$ at dx,dy'
    cbar.set_label(clab)
    if inFolder:
        figname = inFolder + 'residuals_sigma_SMBH.png'
    else:
        figname=newfolder + 'residuals_sigma_SMBH.png'
    py.savefig(figname)
Beispiel #2
0
def modelBHFitGrid(inFolder=None, plotOnly=False):
    # routine to conduct a grid search over SMBH positions

    cubeimg = pyfits.getdata(datadir + cuberoot + '_img.fits')
    xaxis = np.arange(cubeimg.shape[0]) * 0.05
    yaxis = np.arange(cubeimg.shape[1]) * 0.05

    # original angles
    Lorg = -42.8
    Iorg = 54.1
    Aorg = -34.5
    CPA = -56.

    # BH step size, in pixels
    dPix = 1.
    # number of steps away from the original angle in each direction (-/+)
    # halfN = 1 gives 3 total steps, =2 gives 5 steps
    halfN = 2.
    N = (halfN * 2) + 1
    startpos = [0., 0.]

    posgridx = np.arange(startpos[0] - (halfN * dPix),
                         startpos[0] + (halfN * dPix) + 0.5, dPix)
    posgridy = np.arange(startpos[1] - (halfN * dPix),
                         startpos[1] + (halfN * dPix) + 0.5, dPix)

    if not plotOnly:
        # create the new folder
        FORMAT = '%Y%m%d_%H-%M-%S'
        now = datetime.datetime.now().strftime(FORMAT)
        newfolder = modeldir + 'nonaligned_SMBH_grid_' + now + '/'
        os.mkdir(newfolder)
        #newfolder='/Users/kel/Documents/Projects/M31/models/Peiris/2003/nonaligned_grid_rotate_20160919_17-09-05/'

        for pX in posgridx:
            for pY in posgridy:
                testpos = [pX, pY]
                modelConvertBin(testSMBH=testpos,
                                l98bin=False,
                                verbose=False,
                                tess=True,
                                pathstem=newfolder)
                modelCompRes(
                    inModel=newfolder +
                    'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f.dat'
                    % (testpos[0], testpos[1]),
                    toPlot=False)

    # plotting
    py.close(2)
    py.figure(2, figsize=(17, 12))
    py.subplots_adjust(left=0.05, right=0.94, top=0.95)
    nPlot = N**2
    # flux plots
    py.clf()
    plYY = np.fliplr([posgridy])[0]
    plXX = np.fliplr([posgridx])[0]
    pX, pY = np.meshgrid(plXX, plYY)
    pX = pX.flatten()
    pY = pY.flatten()
    for pp in np.arange(nPlot):
        py.subplot(N, N, pp + 1)
        #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
        if inFolder:
            inRes = inFolder + 'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (
                pX[pp], pY[pp])
        else:
            inRes = newfolder + 'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (
                pX[pp], pY[pp])
        res = ppxf_m31.modelFitResults(inRes)
        py.imshow(np.rot90(py.ma.masked_where(cubeimg == 0., res.nstar.T), 3),
                  vmin=-0.25,
                  vmax=0.25,
                  extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
        # with the rotation+transposition of the residual image, the sign of dx is flipped (dy stays the same)
        pltitle = '%.1f, %.1f' % (-1. * pX[pp], pY[pp])
        py.title(pltitle)
        py.xticks([])
        py.yticks([])
    cbar = py.colorbar(orientation='horizontal', ticks=[-.25, 0., .25])
    clab = 'Flux res., $\\bullet_{model}$ at dx,dy'
    cbar.set_label(clab)
    if inFolder:
        figname = inFolder + 'residuals_flux_SMBH.png'
    else:
        figname = newfolder + 'residuals_flux_SMBH.png'
    py.savefig(figname)

    # velocity plots - can probably integrate with flux plotting
    py.clf()
    for pp in np.arange(nPlot):
        py.subplot(N, N, pp + 1)
        #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
        if inFolder:
            inRes = inFolder + 'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (
                pX[pp], pY[pp])
        else:
            inRes = newfolder + 'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (
                pX[pp], pY[pp])
        res = ppxf_m31.modelFitResults(inRes)
        py.imshow(np.rot90(py.ma.masked_where(cubeimg == 0., res.velocity.T),
                           3),
                  vmin=-100.,
                  vmax=200.,
                  extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
        pltitle = '%.1f, %.1f' % (-1. * pX[pp], pY[pp])
        py.title(pltitle)
        py.xticks([])
        py.yticks([])
    cbar = py.colorbar(orientation='horizontal', ticks=[-100, 0., 200])
    clab = 'Velocity res., $\\bullet_{model}$ at dx,dy'
    cbar.set_label(clab)
    if inFolder:
        figname = inFolder + 'residuals_velocity_SMBH.png'
    else:
        figname = newfolder + 'residuals_velocity_SMBH.png'
    py.savefig(figname)

    # sigma plots
    py.clf()
    for pp in np.arange(nPlot):
        py.subplot(N, N, pp + 1)
        #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
        if inFolder:
            inRes = inFolder + 'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (
                pX[pp], pY[pp])
        else:
            inRes = newfolder + 'nonaligned_OSIRIScoords_fit_full_smooth_SMBH_x%+.1f_y%+.1f_residuals.dat' % (
                pX[pp], pY[pp])
        res = ppxf_m31.modelFitResults(inRes)
        py.imshow(np.rot90(py.ma.masked_where(cubeimg == 0., res.sigma.T), 3),
                  vmin=-100.,
                  vmax=100.,
                  extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
        pltitle = '%.1f, %.1f' % (-1. * pX[pp], pY[pp])
        py.title(pltitle)
        py.xticks([])
        py.yticks([])
    cbar = py.colorbar(orientation='horizontal', ticks=[-100, 0., 100])
    clab = 'Sigma res., $\\bullet_{model}$ at dx,dy'
    cbar.set_label(clab)
    if inFolder:
        figname = inFolder + 'residuals_sigma_SMBH.png'
    else:
        figname = newfolder + 'residuals_sigma_SMBH.png'
    py.savefig(figname)
Beispiel #3
0
def modelMorphFitGrid(inFolder=None,plotOnly=False):
    # routine to conduct a grid search over the coordinate transformation angles
    # (angles in Peiris & Tremaine 2003 eq 4)

    cubeimg = pyfits.getdata(datadir + cuberoot + '_img.fits')
    xaxis = np.arange(cubeimg.shape[0]) * 0.05
    yaxis = np.arange(cubeimg.shape[1]) * 0.05

    # original angles
    Lorg = -42.8
    Iorg = 54.1
    Aorg = -34.5
    # not changing CPA
    CPA = -56.

    # angle step size, in degrees
    dAng = 3.
    # number of steps away from the original angle in each direction (-/+)
    # halfN = 1 gives 3 total steps, =2 gives 5 steps
    halfN = 1.
    N = (halfN*2)+1

    Lgrid = np.arange(Lorg-(halfN*dAng),Lorg+(halfN*dAng)+1,dAng)
    Igrid = np.arange(Iorg-(halfN*dAng),Iorg+(halfN*dAng)+1,dAng)
    Agrid = np.arange(Aorg-(halfN*dAng),Aorg+(halfN*dAng)+1,dAng)
        
    if not plotOnly:
        # create the new folder
        FORMAT = '%Y%m%d_%H-%M-%S'
        now = datetime.datetime.now().strftime(FORMAT)
        newfolder = modeldir+'nonaligned_grid_rotate_'+now+'/'
        os.mkdir(newfolder)
        #newfolder='/Users/kel/Documents/Projects/M31/models/Peiris/2003/nonaligned_grid_rotate_20160919_17-09-05/'

        for LL in Lgrid:
            for II in Igrid:
                for AA in Agrid:
                    testAng = [LL,II,AA,CPA]
                    modelConvertBin(testAngles=testAng,l98bin=False,verbose=False,tess=True,pathstem=newfolder)
                    modelCompRes(inModel=newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (testAng[0],testAng[1],testAng[2],testAng[3]),toPlot=False)

    # plotting
    py.close(2)
    py.figure(2)
    py.subplots_adjust(left=0.05, right=0.94, top=0.95)
    nPlot = N**2
    # flux plots
    for AA in Agrid:
        py.clf()
        plLL = np.fliplr([Lgrid])[0]
        pI,pL = np.meshgrid(Igrid,plLL)
        pI = pI.flatten()
        pL = pL.flatten()
        for pp in np.arange(nPlot):
            py.subplot(N,N,pp+1)
            #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
            if inFolder:
                inRes = inFolder + 'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (pL[pp],pI[pp],AA,CPA)
            else:
                inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (pL[pp],pI[pp],AA,CPA)
            res = ppxf_m31.modelFitResults(inRes)
            py.imshow(np.rot90(py.ma.masked_where(cubeimg==0.,res.nstar.T),3),vmin=-0.25,vmax=0.25,
                    extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
            pltitle = '$\\theta_l$ = %.1f, $\\theta_i$ = %.1f' % (pL[pp],pI[pp])
            py.title(pltitle)
            py.xticks([])
            py.yticks([])
        cbar = py.colorbar(orientation='horizontal',ticks=[-.25,0.,.25])
        clab = 'Flux residuals, $\\theta_a$ = %.1f' % (AA)
        cbar.set_label(clab)
        if inFolder:
            figname = inFolder + 'residuals_flux_thetaA_%.1f.png' %(AA)
        else:
            figname=newfolder + 'residuals_flux_thetaA_%.1f.png' %(AA)
        py.savefig(figname)

    # velocity plots - can probably integrate with flux plotting
    for AA in Agrid:
        py.clf()
        plLL = np.fliplr([Lgrid])[0]
        pI,pL = np.meshgrid(Igrid,plLL)
        pI = pI.flatten()
        pL = pL.flatten()
        for pp in np.arange(nPlot):
            py.subplot(N,N,pp+1)
            #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
            if inFolder:
                inRes = inFolder + 'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (pL[pp],pI[pp],AA,CPA)
            else:
                inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (pL[pp],pI[pp],AA,CPA)
            res = ppxf_m31.modelFitResults(inRes)
            py.imshow(np.rot90(py.ma.masked_where(cubeimg==0.,res.velocity.T),3),vmin=-100.,vmax=200.,
                    extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
            pltitle = '$\\theta_l$ = %.1f, $\\theta_i$ = %.1f' % (pL[pp],pI[pp])
            py.title(pltitle)
            py.xticks([])
            py.yticks([])
        cbar = py.colorbar(orientation='horizontal',ticks=[-100.,0.,200.])
        clab = 'Velocity residuals, $\\theta_a$ = %.1f' % (AA)
        cbar.set_label(clab)
        if inFolder:
            figname = inFolder + 'residuals_velocity_thetaA_%.1f.png' %(AA)
        else:
            figname=newfolder + 'residuals_velocity_thetaA_%.1f.png' %(AA)
        py.savefig(figname)

    # sigma plots
    for AA in Agrid:
        py.clf()
        plLL = np.fliplr([Lgrid])[0]
        pI,pL = np.meshgrid(Igrid,plLL)
        pI = pI.flatten()
        pL = pL.flatten()
        for pp in np.arange(nPlot):
            py.subplot(N,N,pp+1)
            #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
            if inFolder:
                inRes = inFolder + 'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (pL[pp],pI[pp],AA,CPA)
            else:
                inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (pL[pp],pI[pp],AA,CPA)
            res = ppxf_m31.modelFitResults(inRes)
            py.imshow(np.rot90(py.ma.masked_where(cubeimg==0.,res.sigma.T),3),vmin=-100.,vmax=100.,
                    extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
            pltitle = '$\\theta_l$ = %.1f, $\\theta_i$ = %.1f' % (pL[pp],pI[pp])
            py.title(pltitle)
            py.xticks([])
            py.yticks([])
        cbar = py.colorbar(orientation='horizontal',ticks=[-100.,0.,100.])
        clab = 'Sigma residuals, $\\theta_a$ = %.1f' % (AA)
        cbar.set_label(clab)
        if inFolder:
            figname = inFolder + 'residuals_sigma_thetaA_%.1f.png' %(AA)
        else:
            figname=newfolder + 'residuals_sigma_thetaA_%.1f.png' %(AA)
        py.savefig(figname)
Beispiel #4
0
def modelMorphFitGrid(inFolder=None, plotOnly=False):
    # routine to conduct a grid search over the coordinate transformation angles
    # (angles in Peiris & Tremaine 2003 eq 4)

    cubeimg = pyfits.getdata(datadir + cuberoot + '_img.fits')
    xaxis = np.arange(cubeimg.shape[0]) * 0.05
    yaxis = np.arange(cubeimg.shape[1]) * 0.05

    # original angles
    Lorg = -42.8
    Iorg = 54.1
    Aorg = -34.5
    # not changing CPA
    CPA = -56.

    # angle step size, in degrees
    dAng = 3.
    # number of steps away from the original angle in each direction (-/+)
    # halfN = 1 gives 3 total steps, =2 gives 5 steps
    halfN = 1.
    N = (halfN * 2) + 1

    Lgrid = np.arange(Lorg - (halfN * dAng), Lorg + (halfN * dAng) + 1, dAng)
    Igrid = np.arange(Iorg - (halfN * dAng), Iorg + (halfN * dAng) + 1, dAng)
    Agrid = np.arange(Aorg - (halfN * dAng), Aorg + (halfN * dAng) + 1, dAng)

    if not plotOnly:
        # create the new folder
        FORMAT = '%Y%m%d_%H-%M-%S'
        now = datetime.datetime.now().strftime(FORMAT)
        newfolder = modeldir + 'nonaligned_grid_rotate_' + now + '/'
        os.mkdir(newfolder)
        #newfolder='/Users/kel/Documents/Projects/M31/models/Peiris/2003/nonaligned_grid_rotate_20160919_17-09-05/'

        for LL in Lgrid:
            for II in Igrid:
                for AA in Agrid:
                    testAng = [LL, II, AA, CPA]
                    modelConvertBin(testAngles=testAng,
                                    l98bin=False,
                                    verbose=False,
                                    tess=True,
                                    pathstem=newfolder)
                    modelCompRes(
                        inModel=newfolder +
                        'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat'
                        % (testAng[0], testAng[1], testAng[2], testAng[3]),
                        toPlot=False)

    # plotting
    py.close(2)
    py.figure(2)
    py.subplots_adjust(left=0.05, right=0.94, top=0.95)
    nPlot = N**2
    # flux plots
    for AA in Agrid:
        py.clf()
        plLL = np.fliplr([Lgrid])[0]
        pI, pL = np.meshgrid(Igrid, plLL)
        pI = pI.flatten()
        pL = pL.flatten()
        for pp in np.arange(nPlot):
            py.subplot(N, N, pp + 1)
            #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
            if inFolder:
                inRes = inFolder + 'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (
                    pL[pp], pI[pp], AA, CPA)
            else:
                inRes = newfolder + 'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (
                    pL[pp], pI[pp], AA, CPA)
            res = ppxf_m31.modelFitResults(inRes)
            py.imshow(np.rot90(py.ma.masked_where(cubeimg == 0., res.nstar.T),
                               3),
                      vmin=-0.25,
                      vmax=0.25,
                      extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
            pltitle = '$\\theta_l$ = %.1f, $\\theta_i$ = %.1f' % (pL[pp],
                                                                  pI[pp])
            py.title(pltitle)
            py.xticks([])
            py.yticks([])
        cbar = py.colorbar(orientation='horizontal', ticks=[-.25, 0., .25])
        clab = 'Flux residuals, $\\theta_a$ = %.1f' % (AA)
        cbar.set_label(clab)
        if inFolder:
            figname = inFolder + 'residuals_flux_thetaA_%.1f.png' % (AA)
        else:
            figname = newfolder + 'residuals_flux_thetaA_%.1f.png' % (AA)
        py.savefig(figname)

    # velocity plots - can probably integrate with flux plotting
    for AA in Agrid:
        py.clf()
        plLL = np.fliplr([Lgrid])[0]
        pI, pL = np.meshgrid(Igrid, plLL)
        pI = pI.flatten()
        pL = pL.flatten()
        for pp in np.arange(nPlot):
            py.subplot(N, N, pp + 1)
            #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
            if inFolder:
                inRes = inFolder + 'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (
                    pL[pp], pI[pp], AA, CPA)
            else:
                inRes = newfolder + 'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (
                    pL[pp], pI[pp], AA, CPA)
            res = ppxf_m31.modelFitResults(inRes)
            py.imshow(np.rot90(
                py.ma.masked_where(cubeimg == 0., res.velocity.T), 3),
                      vmin=-100.,
                      vmax=200.,
                      extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
            pltitle = '$\\theta_l$ = %.1f, $\\theta_i$ = %.1f' % (pL[pp],
                                                                  pI[pp])
            py.title(pltitle)
            py.xticks([])
            py.yticks([])
        cbar = py.colorbar(orientation='horizontal', ticks=[-100., 0., 200.])
        clab = 'Velocity residuals, $\\theta_a$ = %.1f' % (AA)
        cbar.set_label(clab)
        if inFolder:
            figname = inFolder + 'residuals_velocity_thetaA_%.1f.png' % (AA)
        else:
            figname = newfolder + 'residuals_velocity_thetaA_%.1f.png' % (AA)
        py.savefig(figname)

    # sigma plots
    for AA in Agrid:
        py.clf()
        plLL = np.fliplr([Lgrid])[0]
        pI, pL = np.meshgrid(Igrid, plLL)
        pI = pI.flatten()
        pL = pL.flatten()
        for pp in np.arange(nPlot):
            py.subplot(N, N, pp + 1)
            #inRes = newfolder+'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f.dat' % (pL[pp],pI[pp],AA,CPA)
            if inFolder:
                inRes = inFolder + 'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (
                    pL[pp], pI[pp], AA, CPA)
            else:
                inRes = newfolder + 'nonaligned_OSIRIScoords_fit_full_smooth_%.1f_%.1f_%.1f_%.1f_residuals.dat' % (
                    pL[pp], pI[pp], AA, CPA)
            res = ppxf_m31.modelFitResults(inRes)
            py.imshow(np.rot90(py.ma.masked_where(cubeimg == 0., res.sigma.T),
                               3),
                      vmin=-100.,
                      vmax=100.,
                      extent=[xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]])
            pltitle = '$\\theta_l$ = %.1f, $\\theta_i$ = %.1f' % (pL[pp],
                                                                  pI[pp])
            py.title(pltitle)
            py.xticks([])
            py.yticks([])
        cbar = py.colorbar(orientation='horizontal', ticks=[-100., 0., 100.])
        clab = 'Sigma residuals, $\\theta_a$ = %.1f' % (AA)
        cbar.set_label(clab)
        if inFolder:
            figname = inFolder + 'residuals_sigma_thetaA_%.1f.png' % (AA)
        else:
            figname = newfolder + 'residuals_sigma_thetaA_%.1f.png' % (AA)
        py.savefig(figname)