def process_mock_densdata(options): print("Using mock Pal 5 data from %s" % options.mockfilename) # Read and prep data for mocks xvid= numpy.loadtxt(options.mockfilename) xv= xvid[:,:6] xv= xv[numpy.argsort(xvid[:,6])] XYZ= bovy_coords.galcenrect_to_XYZ(xv[:,0],xv[:,1],xv[:,2], Xsun=R0,Zsun=0.025) lbd= bovy_coords.XYZ_to_lbd(XYZ[0],XYZ[1],XYZ[2],degree=True) radec= bovy_coords.lb_to_radec(lbd[:,0],lbd[:,1],degree=True) xieta= pal5_util.radec_to_pal5xieta(radec[:,0],radec[:,1],degree=True) # make sure the progenitor is at (0,0) xieta[:,0]-= numpy.median(xieta[:,0]) xieta[:,1]-= numpy.median(xieta[:,1]) h,e= numpy.histogram(xieta[:,0],range=[0.2,14.3],bins=141) xdata= numpy.arange(0.25,14.35,0.1) # Compute power spectrum tdata= h-0. pp= Polynomial.fit(xdata,tdata,deg=options.polydeg,w=1./numpy.sqrt(h+1.)) tdata/= pp(xdata) ll= xdata py= signal.csd(tdata,tdata,fs=1./(ll[1]-ll[0]),scaling='spectrum', nperseg=len(ll))[1] py= py.real # Also compute the bispectrum Bspec, Bpx= bispectrum.bispectrum(numpy.vstack((tdata,tdata)).T, nfft=len(tdata),wind=7,nsamp=1,overlap=0) ppyr= numpy.fabs(Bspec[len(Bspec)//2+_BISPECIND,len(Bspec)//2:].real) ppyi= numpy.fabs(Bspec[len(Bspec)//2+_BISPECIND,len(Bspec)//2:].imag) return (numpy.sqrt(py*(ll[-1]-ll[0])),numpy.sqrt(h+1.)/pp(xdata), ppyr,ppyi)
def convert_dens_to_obs(sdf_pepper, apars, dens, mO, dens_smooth, minxi=0.25, maxxi=14.35): """ NAME: convert_dens_to_obs PURPOSE: Convert track to observed coordinates INPUT: sdf_pepper - streampepperdf object apars - parallel angles dens - density(apars) dens_smooth - smooth density(apars) mO= (None) mean parallel frequency (1D) [needs to be set to get density on same grid as track] minxi= (0.25) minimum xi to consider OUTPUT: (xi,dens/smooth) """ mT = sdf_pepper.meanTrack(apars, _mO=mO, coord='lb') mradec = bovy_coords.lb_to_radec(mT[0], mT[1], degree=True) mxieta = pal5_util.radec_to_pal5xieta(mradec[:, 0], mradec[:, 1], degree=True) outll = np.arange(minxi, maxxi, 0.1) # Interpolate density ipll = interpolate.InterpolatedUnivariateSpline(mxieta[:, 0], apars) ipdens = interpolate.InterpolatedUnivariateSpline(apars, dens / dens_smooth) return (outll, ipdens(ipll(outll)))
def process_mock_densdata(options): print ("Using mock Pal 5 data from %s" % options.mockfilename) # Read and prep data for mocks xvid = numpy.loadtxt(options.mockfilename) xv = xvid[:, :6] xv = xv[numpy.argsort(xvid[:, 6])] XYZ = bovy_coords.galcenrect_to_XYZ(xv[:, 0], xv[:, 1], xv[:, 2], Xsun=R0, Zsun=0.025) lbd = bovy_coords.XYZ_to_lbd(XYZ[0], XYZ[1], XYZ[2], degree=True) radec = bovy_coords.lb_to_radec(lbd[:, 0], lbd[:, 1], degree=True) xieta = pal5_util.radec_to_pal5xieta(radec[:, 0], radec[:, 1], degree=True) # make sure the progenitor is at (0,0) xieta[:, 0] -= numpy.median(xieta[:, 0]) xieta[:, 1] -= numpy.median(xieta[:, 1]) h, e = numpy.histogram(xieta[:, 0], range=[0.2, 14.3], bins=141) xdata = numpy.arange(0.25, 14.35, 0.1) # Compute power spectrum tdata = h - 0.0 pp = Polynomial.fit(xdata, tdata, deg=options.polydeg, w=1.0 / numpy.sqrt(h + 1.0)) tdata /= pp(xdata) ll = xdata py = signal.csd(tdata, tdata, fs=1.0 / (ll[1] - ll[0]), scaling="spectrum", nperseg=len(ll))[1] py = py.real # Also compute the bispectrum Bspec, Bpx = bispectrum.bispectrum(numpy.vstack((tdata, tdata)).T, nfft=len(tdata), wind=7, nsamp=1, overlap=0) ppyr = numpy.fabs(Bspec[len(Bspec) // 2 + _BISPECIND, len(Bspec) // 2 :].real) ppyi = numpy.fabs(Bspec[len(Bspec) // 2 + _BISPECIND, len(Bspec) // 2 :].imag) return (numpy.sqrt(py * (ll[-1] - ll[0])), numpy.sqrt(h + 1.0) / pp(xdata), ppyr, ppyi)
def convert_dens_to_obs(sdf_pepper, apars, dens, mO, dens_smooth, minxi=0.25, maxxi=14.35): """ NAME: convert_dens_to_obs PURPOSE: Convert track to observed coordinates INPUT: sdf_pepper - streampepperdf object apars - parallel angles dens - density(apars) dens_smooth - smooth density(apars) mO= (None) mean parallel frequency (1D) [needs to be set to get density on same grid as track] minxi= (0.25) minimum xi to consider OUTPUT: (xi,dens/smooth) """ mT = sdf_pepper.meanTrack(apars, _mO=mO, coord="lb") mradec = bovy_coords.lb_to_radec(mT[0], mT[1], degree=True) mxieta = pal5_util.radec_to_pal5xieta(mradec[:, 0], mradec[:, 1], degree=True) outll = numpy.arange(minxi, maxxi, 0.1) # Interpolate density ipll = interpolate.InterpolatedUnivariateSpline(mxieta[:, 0], apars) ipdens = interpolate.InterpolatedUnivariateSpline(apars, dens / dens_smooth) return (outll, ipdens(ipll(outll)))
def get_star_dx(pepperdf, n=1000, returnapar=False, returnxi=False): (Omega, angle, dt) = pepperdf.sample(n=n, returnaAdt=True) RvR = pepperdf._approxaAInv(Omega[0], Omega[1], Omega[2], angle[0], angle[1], angle[2]) vo = pepperdf._vo ro = pepperdf._ro R0 = pepperdf._R0 Zsun = pepperdf._Zsun vsun = pepperdf._vsun XYZ = bovy_coords.galcencyl_to_XYZ(RvR[0] * ro, RvR[5], RvR[3] * ro, Xsun=R0, Zsun=Zsun).T slbd = bovy_coords.XYZ_to_lbd(XYZ[0], XYZ[1], XYZ[2], degree=True) sradec = bovy_coords.lb_to_radec(slbd[:, 0], slbd[:, 1], degree=True) xieta = pal5_util.radec_to_pal5xieta(sradec[:, 0], sradec[:, 1], degree=True) l = slbd[:, 0] b = slbd[:, 1] r = slbd[:, 2] if returnapar: closesttrackindexes = np.zeros(len(r)) for i in np.arange(len(r)): closesttrackindexes[i] = pepperdf.find_closest_trackpoint( RvR[0][i], RvR[1][i], RvR[2][i], RvR[3][i], RvR[4][i], RvR[5][i], interp=True) starapar = pepperdf._interpolatedThetasTrack[( closesttrackindexes).astype(int)] return starapar if returnxi: return xieta[:, 0] else: return None
def convert_track_to_obs(apars,mO,coord): """ NAME: convert_track_to_obs PURPOSE: Convert track to observed coordinates INPUT: apars - parallel angles mO - mean parallel frequency (1D) coord - coordinate to convert to (1: eta, 2: distance, 3: vlos, 4: pmll, 5: pmbb) OUTPUT: (longitude,(track-smooth)[coord]) """ mT= sdf_pepper.meanTrack(apars,_mO=mO,coord='lb') mradec= bovy_coords.lb_to_radec(mT[0],mT[1],degree=True) mxieta= pal5_util.radec_to_pal5xieta(mradec[:,0],mradec[:,1],degree=True) mT[0]= mxieta[:,0] mT[1]= mxieta[:,1] # Interpolate ipll= interpolate.InterpolatedUnivariateSpline(mT[0],apars) ipcoord= interpolate.InterpolatedUnivariateSpline(apars,mT[coord]) outll= numpy.arange(minxi,14.35,0.1) return (outll,ipcoord(ipll(outll))-smooth_track[coord](smooth_ll(outll)))
def convert_dens_to_obs(apars,dens,dens_smooth,mO,poly_deg=3): """ NAME: convert_dens_to_obs PURPOSE: Convert track to observed coordinates INPUT: apars - parallel angles dens - density(apars) dens_smooth - smooth-stream density(apars) mO= (None) mean parallel frequency (1D) [needs to be set to get density on same grid as track] poly_deg= (3) degree of the polynomial to fit for the 'smooth' stream OUTPUT: (xi,dens/smooth) """ mT= sdf_pepper.meanTrack(apars,_mO=mO,coord='lb') mradec= bovy_coords.lb_to_radec(mT[0],mT[1],degree=True) mxieta= pal5_util.radec_to_pal5xieta(mradec[:,0],mradec[:,1],degree=True) outll= numpy.arange(minxi,14.35,0.1) # Interpolate density ipll= interpolate.InterpolatedUnivariateSpline(mxieta[:,0],apars) ipdens= interpolate.InterpolatedUnivariateSpline(apars,dens/dens_smooth) return (outll,ipdens(ipll(outll)))
with open(pepperfilename,'rb') as savefile: sdf_pepper= pickle.load(savefile) else: import simulate_streampepper timpacts= simulate_streampepper.parse_times('1sampling',9.) sdf_pepper= pal5_util.setup_pal5model(timpact=timpacts, hernquist=True) save_pickles(pepperfilename,sdf_pepper) # Convert track to xi, eta trackRADec=\ bovy_coords.lb_to_radec(sdf_smooth._interpolatedObsTrackLB[:,0], sdf_smooth._interpolatedObsTrackLB[:,1], degree=True) trackXiEta=\ pal5_util.radec_to_pal5xieta(trackRADec[:,0], trackRADec[:,1],degree=True) smooth_track= [] for coord in range(6): if coord < 2: smooth_track.append(\ interpolate.InterpolatedUnivariateSpline(sdf_smooth._interpolatedThetasTrack, trackXiEta[:,coord])) else: smooth_track.append(\ interpolate.InterpolatedUnivariateSpline(sdf_smooth._interpolatedThetasTrack, sdf_smooth._interpolatedObsTrackLB[:,coord])) smooth_ll= interpolate.InterpolatedUnivariateSpline(trackXiEta[:,0], sdf_smooth._interpolatedThetasTrack)