Showing posts with label crl. Show all posts
Showing posts with label crl. Show all posts

Tuesday, May 10, 2011

xmpl_rv, ximat and sximat

Alexia I suggested to look at xmpl_rv (ximat) and sximat to make sure that the interpolation of the xi matrix is in the same location as the xi matrices from the data.

The results are surprising. First of all, the plot of ximat vs sximat is basically a flat line, when plotted log space (click on images to enlarge):

The above plot has sximat, ximat for 3 different binnings (39, 40, and 41) and the plots basically all fall on top of each other. This is from the best "working" reconstruction mock data, described here.

But they don't fall on top of the xi correlation functions from the data:


I thought maybe this was a conversion issue, but I checked and I think they are in the same units. In order to even get the cximat to fall on top of the xi correlation functions you need to divide by 10^4:

Alexia am I doing this right? Is this weird to you?

Different Reconstruction

Here is the reconstruction I ran last night with a different photometric distribution function, below shows the photometric and spectroscopic distributions:

I used the same number of bins and angles as yesterdays post. Here are the correlation functions:


And here are the reconstructions with several different binnings. None of them match as well as yesterdays post, but both 40 and 39 are close-ish:

I talked to Alexia this morning, she suggested that I do the binning sensitivity check and also look at how xmpl_rv (in getximat) compares to sximat. I'm doing that now. Most posts to come shortly.

Here's the code to make the following (also in logs/110509log.py):
import numpy as N
from pylab import *
from matplotlib import *
import crlold as crl
from correlationData import *
import galsphere as gals
import datetime as dt

workingDir = 'run201159_123'

runConstantsFile = './'+workingDir+'/runConstants.dat'

mockLRGfile,photofile,specfile,corr2dfile,corr3dfile,photo2dfile,photoCDfile,spec2dfile,spec3dfile,\
argumentFile,runConstantsFile,wpsMatrixFile,xiMatrixFile,oversample,corrBins,mincorr,maxcorr,boxside,\
xicorrmin,xicorrmax,nxicorr,rbinmin,rbinmax,nrbins,psubsize,ssubsize=readRunConstantsFileAll(runConstantsFile)

rbinspace = int((rbinmax-rbinmin)/(nrbins))
rbins = makeRbins(rbinmin,rbinmax,rbinspace)


#read in masks
minRaP,maxRaP,minDecP,maxDecP,minCDP,maxCDP,minRaS,maxRaS,minDecS,maxDecS,minCDS,maxCDS=readmasks(workingDir)


#Import the photometric redshift distribution
photoCD = readPhotoCDfile(photoCDfile)


#Create a matrix to input the correlation function data
# Write wps Matrix to file
#The number of redshift bins you want to skip for the
#reconstruction (this removes noisy bins from calculation)
skip = 0
makeWPSmatrix2(workingDir,rbins,corrBins, wpsMatrixFile, skip)

#Create a matrix to input the correlation function data
# Write Xi Matrix to file
makeXimatrix2(workingDir,rbins,nxicorr,xiMatrixFile, skip)

#Plot wps correlation functions
numtoplot = int(nrbins-skip) #number of correlation functions you want to display on plot
plotWPS(skip, numtoplot, workingDir, rbins)
numtoplot = 10
plotWPSScreen(skip, numtoplot, workingDir, rbins)

#Plot xi correlation functions
plotXi(skip, numtoplot, workingDir, rbins)
plotXiScreen(skip, numtoplot, workingDir, rbins)


#from commandsAlexia import *
xissfile = xiMatrixFile
wpsfile = wpsMatrixFile
nphibins = size(rbins)

# Read in the data
#spectroscopic autocorrelation function
X=N.loadtxt(xissfile,comments='#')
X=X.T
rs=X[0,:]/1000. #want box units (Gpc, not Mpc)
xispec=X[1:,:] #xi in nspecbins


#2D cross correlation between spec and photo samples
th,rlos,wps=N.loadtxt(wpsfile,comments='#',unpack=True)
th=N.unique(th)
rlos=N.unique(rlos)
#rlos=getcomovingD(rlos) #adjusts from redshift to Mpc/h
rlos=rlos/1000 #want box units (Gpc, not Mpc)

#covariance matrix of wps measurements, wps vector arranged
covar = N.identity(wps.shape[0],float)
xierr = N.identity(xispec.shape[1],float)

# compute the xi matrix using the spec sample,
npbins=39#the number of bins you want reconstructed
reconstructmax = 0.5 #in Gpc
reconstructionmin = 0.0 #in Gpc
phibsize = (reconstructmax - reconstructionmin)/npbins

phibins = linspace(start=reconstructionmin,stop=reconstructmax,num=npbins,endpoint=True)

#phibins =(linspace(2,npbins,num=npbins,endpoint=False)+0.5)*(1./npbins)
sximat=crl.getximat(th,rlos,phibins,rs,xispec,xierr)

# invert to recover phi
phircvd=crl.getCoeff(wps,covar,sximat)
for i in range(len(phircvd.x)):
if (phircvd.x[i] < 0):
phircvd.x[i]=0

print 'the recovered selection function is not normalized.'

outphi4 = phircvd.x
phibins4 = phibins

start = 1
end = npbins - 1

#junkbins = linspace(start=0,stop=0.5,num=100,endpoint=True)
junkbins = phibins
junk = histogram(photoCD/1000., bins=junkbins)
junkdata = junk[0]
plot(junkbins[start:end], junkdata[start:end], 'r.-', label = 'photometric data')
plot((phibins4[start:end]+1.0*phibsize), outphi4[start:end]*sum(junkdata[start:end])/sum(outphi4[start:end]), 'g-', label='reconstruction %i'%npbins)

xlabel('comoving distance (Gpc/h)')
ylabel('number of objects per bin')
title('Redshift Distribution')
from pylab import *
legend(loc=2)


Tuesday, March 9, 2010

Likelihood Wins = More Work For Me

At the BOSS Collaboration Meeting today we decided to make the core sample be composed of the top 20/deg^2 likelihood targets. The rest of the fibers are going to be targeted using a combined method. We're number one! Awesome.

However, this puts the pressure on the likelihood target selection group (me, Joe, David) to get this thing optimized, trained, etc.

First thing on the agenda, fix the luminosity function:
Above shows two different QSO luminosity selection functions as a function of redshift. The green is the Jiang et al. (2008) and the red is the Hopkins, Richards and Hernquist (2007).

I'm going to try running both of them down to 0.5 and see how they compare to what we've been doing. Joe says I shouldn't spend more than a couple days on this.

Adam Myers also suggested another paper to look at: R.J. Assef et al. The Mid-IR and X-ray Selected QSO Luminosity Function

In the mean time I am also re-running the reconstruction on the photo-z SDSS data with the fixed 2-d correlation function. Should have results from that soon. Waiting on Alexia to give me a new crl to see if this fixes the binning issues I was having.

Lots to do lots to do! Feeling excited about life.

Thursday, January 21, 2010

Success!

I finally got Alexia's new crl working. As far as I can tell the only difference is that getximat expects the errors in xi as an input. For now I am just inputting an identity matrix, as I will need to get the errors by bootstrapping and haven't done that yet.

The function getximat wants a matrix that is the same size as the length of the xiss matrix:
xierr = N.identity(xispec.shape[1],float)

I am reconstructing from 0 to 0.5 Gpc/h using 20 bins. I am renormalizing the reconstructed redshift distribution by the following:
sum(photometric data)/sum(reconstructed data)
This gives the same "number" of objects in both sets.

This is the first reasonable reconstruction I have ever generated. This makes me very very happy. I'm going to play with different binning and selection functions next, but I would like to have at least one blog entry which has a happy ending.