def determine_kxky_error():
    #Load fiducial bar model
    spvlos= galpy_simulations.vlos('../sim/bar_rect_alpha0.015%s.sav' % _HIVRESSTR)[1::2,1::2]
    #spvlos= galpy_simulations.vlos('../sim/spiral_rect_omegas0.33_alpha-14%s.sav' % _HIVRESSTR)[1::2,1::2]*0.85
    #spvlos= galpy_simulations.vlos('../sim/spiral_rect_omegas0.33_alpha-7%s.sav' % _HIVRESSTR)[1::2,1::2]*0.25
    psd2d= bovy_psd.psd2d(spvlos)
    kmax= 1./_RCDX
    #Calculate maximum
    psd2d[psd2d.shape[0]/2-1:psd2d.shape[0]/2+2,psd2d.shape[1]/2-1:psd2d.shape[1]/2+2]= 0.
    tmax= numpy.unravel_index(numpy.argmax(psd2d),psd2d.shape)
    tmax0= float(psd2d.shape[0]/2-tmax[0])/psd2d.shape[0]*2
    tmax1= float(tmax[1]-psd2d.shape[1]/2)/psd2d.shape[1]*2
    print tmax0*kmax, tmax1*kmax
    bovy_plot.bovy_print()
    bovy_plot.bovy_dens2d(psd2d.T,origin='lower',cmap='jet',
                          interpolation='nearest',
                          xrange=[-kmax,kmax],
                          yrange=[-kmax,kmax],
                          xlabel=r'$k_x\,(\mathrm{kpc}^{-1})$',
                          ylabel=r'$k_y\,(\mathrm{kpc}^{-1})$')
    bovy_plot.bovy_end_print('/Users/bovy/Desktop/test.png')
    #Read the data for the noise
    data= apread.rcsample()
    if _ADDLLOGGCUT:
        data= data[data['ADDL_LOGG_CUT'] == 1]
    #Cut
    indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.)
    print "Using %i stars for low-Z 2D kinematics analysis" % numpy.sum(indx)
    data= data[indx]
    #Get residuals
    dx= _RCDX
    pix= pixelize_sample.pixelXY(data,
                                 xmin=_RCXMIN,xmax=_RCXMAX,
                                 ymin=_RCYMIN,ymax=_RCYMAX,
                                 dx=dx,dy=dx)
    resvunc= pix.plot('VHELIO_AVG',
                      func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)),
                      returnz=True,justcalc=True)
    #Now do 1000 MC simulations to determine the error on kmax
    nmc= 1000
    kxmax= numpy.zeros(nmc)
    kymax= numpy.zeros(nmc)
    for ii in range(nmc):
        newresv= spvlos+numpy.random.normal(size=spvlos.shape)*resvunc/220.
        simpsd2d= bovy_psd.psd2d(newresv*220.)
        simpsd2d[simpsd2d.shape[0]/2-1:simpsd2d.shape[0]/2+2,simpsd2d.shape[1]/2-1:simpsd2d.shape[1]/2+2]= 0.
        tmax= numpy.unravel_index(numpy.argmax(simpsd2d),psd2d.shape)
        tmax0= float(psd2d.shape[0]/2-tmax[0])/psd2d.shape[0]*2
        tmax1= float(tmax[1]-psd2d.shape[1]/2)/psd2d.shape[1]*2
        kmax= 1./_RCDX
        kxmax[ii]= tmax0*kmax
        kymax[ii]= tmax1*kmax
    print numpy.mean(kxmax), numpy.std(kxmax)
    print numpy.mean(kymax), numpy.std(kymax)
    return None
Beispiel #2
0
def plot_psd2d(plotfilename):
    data= apread.rcsample()
    if _ADDLLOGGCUT:
        data= data[data['ADDL_LOGG_CUT'] == 1]
    #Cut
    indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.)
    print "Using %i stars for low-Z 2D kinematics analysis" % numpy.sum(indx)
    data= data[indx]
    #Get residuals
    dx= _RCDX
    binsize= .8#.765
    pix= pixelize_sample.pixelXY(data,
                                 xmin=_RCXMIN,xmax=_RCXMAX,
                                 ymin=_RCYMIN,ymax=_RCYMAX,
                                 dx=dx,dy=dx)
    resv= pix.plot(lambda x: dvlosgal(x,vtsun=220.+22.6),
                   returnz=True,justcalc=True)
    resvunc= pix.plot('VHELIO_AVG',
                      func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)),
                      returnz=True,justcalc=True)
    psd2d= bovy_psd.psd2d(resv)
    tmax= numpy.unravel_index(numpy.argmax(psd2d),psd2d.shape)
    tmax0= float(psd2d.shape[0]/2-tmax[0])/psd2d.shape[0]*2
    tmax1= float(tmax[1]-psd2d.shape[1]/2)/psd2d.shape[1]*2
    kmax= 1./_RCDX
    print tmax0*kmax, tmax1*kmax
    #kmax= numpy.amax(numpy.fft.fftfreq(resv.shape[0]*2,_RCDX))
    bovy_plot.bovy_print()
    bovy_plot.bovy_dens2d(psd2d.T,origin='lower',cmap='jet',
                          interpolation='nearest',
                          xrange=[-kmax,kmax],
                          yrange=[-kmax,kmax],
                          xlabel=r'$k_x\,(\mathrm{kpc}^{-1})$',
                          ylabel=r'$k_y\,(\mathrm{kpc}^{-1})$')
    bovy_plot.bovy_end_print(plotfilename)
    if True:
        spvlos= galpy_simulations.vlos('../sim/bar_rect_alpha0.015_hivres.sav')[1::2,1::2]
        potscale= 1.
Beispiel #3
0
    kmax= 1./_RCDX
    print tmax0*kmax, tmax1*kmax
    #kmax= numpy.amax(numpy.fft.fftfreq(resv.shape[0]*2,_RCDX))
    bovy_plot.bovy_print()
    bovy_plot.bovy_dens2d(psd2d.T,origin='lower',cmap='jet',
                          interpolation='nearest',
                          xrange=[-kmax,kmax],
                          yrange=[-kmax,kmax],
                          xlabel=r'$k_x\,(\mathrm{kpc}^{-1})$',
                          ylabel=r'$k_y\,(\mathrm{kpc}^{-1})$')
    bovy_plot.bovy_end_print(plotfilename)
    if True:
        spvlos= galpy_simulations.vlos('../sim/bar_rect_alpha0.015_hivres.sav')[1::2,1::2]
        potscale= 1.
k        spvlos+= numpy.random.normal(size=spvlos.shape)*resvunc/220./potscale
        simpsd2d= bovy_psd.psd2d(spvlos*220.*potscale)
        bovy_plot.bovy_print()
        bovy_plot.bovy_dens2d(simpsd2d.T,
                              origin='lower',cmap='jet', 
                              interpolation='nearest',
                              xrange=[-kmax,kmax],
                              yrange=[-kmax,kmax],
                              xlabel=r'$k_x\,(\mathrm{kpc}^{-1})$',
                              ylabel=r'$k_y\,(\mathrm{kpc}^{-1})$')
        fileparts= re.split(r'\.',plotfilename)
        nparts= len(fileparts)
        simfilename= ''
        for ii in range(nparts):
            if ii == nparts-2: simfilename+= fileparts[ii]+'_simpsd2d.'
            elif ii == nparts-1: simfilename+= fileparts[ii]
            else: simfilename+= fileparts[ii]+'.'