def findnearest(self,ra1,dec1,ra2,dec2,delta):#measure distances from ra1, dec1 to members in catalog ra2, dec2 ramatch=my.findmatch(ra1,ra2,delta) decmatch=my.findmatch(dec1,dec2,delta) match=ramatch&decmatch for i in range(len(ra1)): angdist=my.DA(c.z[j],h100)#kpc/arcsec dspec=N.sqrt((ra1[i]-ra2)**2+(dec1[i]-dec2)**2)#sorted array of distances in degrees dspecsort=N.take(dspec,N.argsort(dspec)) sig5[i]=5./(N.pi)/(dspecsort[5]*3600.*angdist/1000.)**2#convert from deg to arcsec, multiply by DA (kpc/arcsec), divide by 1000 to convert to Mpc, index 5 element b/c 0 is itself sig10[i]=10./(N.pi)/(dspecsort[10]*3600.*angdist/1000.)**2#convert from deg to arcsec, multiply by DA (kpc/arcsec), divide by 1000 to convert to Mpc, index 5 element b/c 0 is itself return sig5, sig10
def matchha(self):#match coordinates with ha data self.haflag=N.zeros(len(self.ra),'f')#flag for halpha self.hamatch=N.zeros(len(self.ra),'i') (x1sort,x1index)=my.sortwindex(gha.ra) (x2sort,x2index)=my.sortwindex(gha.dec) deltar=100.#matching tolerance in arcsec deltar=deltar/3600.#convert to degrees for i in range(len(self.ra)): temp=[] (temp,flag)=my.findmatch(self.ra[i],x1sort,deltar)#returns indices of sorted array if flag < 1: print i, "No match to Halpha data" continue templist1=temp for j in range(len(temp)): templist1[j]=x1index[temp[j]] temp=[] (temp,flag)=my.findmatch(self.dec[i],x2sort,deltar) if flag < 1: print i, "No match to Halpha data" continue templist2=temp for j in range(len(temp)): templist2[j]=x2index[temp[j]] a=sets.Set(templist1) b=sets.Set(templist2) members=a&b members=list(members)#contains all galaxies w/in a 4"x4" square min=100. for j in members: d=N.sqrt((self.ra[i]-gha.ra[j])**2+(self.dec[i]-gha.dec[j])**2) if d < min: min=d minindex=j if min < 2.: self.haflag[i]=1. self.hamatch[i]=minindex
def getmemberids(self): #get galaxy members self.membids = N.zeros(len(self.x1), 'd') self.membflag = N.ones(len(self.x1), 'f') #flag to indicate if no members are found self.membincut = N.zeros(len(self.x1), 'd') self.membids = list(self.membids) self.membdr = N.zeros(len(self.x1), 'd') self.membdr = list(self.membdr) nomemb = 0. for i in range(len(self.x1)): delta = nr #tolerance for matching temp = [] mdv = [] mdr = [] distance = N.sqrt((self.x1[i] - g.x1)**2 + (self.x2[i] - g.x2)**2 + (self.x3[i] - g.x3)**2) / self.r200[i] (dsort, dindex) = my.sortwindex(distance) (temp, matchflag) = my.findmatch(0., dsort, delta) #templist1=temp #for j in range(len(temp)): # templist1[j]=dindex[temp[j]] #membid=copy.copy(temp) membid = [] dr = [] #print 'cdtheta = ',cdtheta #print "temp=",temp try: for j in range(len(temp)): membid.append(dindex[temp[j]]) #print j,temp[j],dindex[temp[j]],'temp=',temp dr.append(distance[membid[j]]) self.membids[i] = membid self.membincut[i] = len(membid) self.membdr[i] = dr except TypeError: #if (self.membids[i]+999) < 1.: nomemb = nomemb + 1. #print "no members in cluster ",i,self.membids[i] self.membincut[i] = 0 self.membflag[i] = 0. continue print nomemb, " clusters with no members", nomemb / len(self.x1)
def getobsmemberids(self): #get galaxies within nr*dr and nv*dv #print "within getobsmemberids(), nv,nr,len(x1) = ",nv,nr,len(g.x1) #print "within measurecontam(), nv,nr,len(x1) = ",nv,nr,len(g.x1),len(self.mass) #print self.mass self.obsmembids = N.zeros(len(self.x1), 'd') self.obsmembflag = N.ones(len(self.x1), 'd') self.obsmembids = list(self.obsmembids) self.obsdr = N.zeros(len(self.x1), 'd') self.obsdr = list(self.obsdr) self.obsdv = N.zeros(len(self.x1), 'd') self.obsdv = list(self.obsdv) self.obsmembincut = N.zeros(len(self.x1), 'd') nomemb = 0. vbox = my.vofz( zbox) #redshift of box center given epoch of observation #i.e. recession velocity corresponding to z=0.2, 0.4, 0.6, etc of GIF observations for i in range(len(self.x1)): #self.obsmembids[i]=[] vcl = H0 * self.x3[i] deltar = nr * self.r200[i] #tolerance for matching deltav = nv * self.sigma[i] #tolerance for matching #print i,"cluster id, mass, r200, sigma = ",self.id[i],self.mass[i],self.r200[i],self.sigma[i],Mclmin temp = [] #put cluster in middle of box x1 = g.x1 - self.x1[i] + 0.5 * simL #flip coordinates so galaxy x1 ranges from 0 to simL for j in range(len(x1)): if x1[j] > simL: x1[j] = x1[j] - simL if x1[j] < 0: x1[j] = x1[j] + simL x2 = g.x2 - self.x2[i] + 0.5 * simL for j in range(len(x2)): if x2[j] > simL: x2[j] = x2[j] - simL if x2[j] < 0: x2[j] = x2[j] + simL x3 = g.x3 - self.x3[i] + 0.5 * simL for j in range(len(x3)): if x3[j] > simL: x3[j] = x3[j] - simL if x3[j] < 0: x3[j] = x3[j] + simL gvobs = x3 * H0 + g.v3 gvobs = my.relsumv(vbox, gvobs) gz = my.zofv(gvobs) (x1sort, x1index) = my.sortwindex(x1) (x2sort, x2index) = my.sortwindex(x2) (temp, matchflag1) = my.findmatch(0.5 * simL, x1sort, deltar) if (matchflag1 > 0): templist1 = [] for j in range(len(temp)): templist1.append(x1index[temp[j]]) temp = [] (temp, matchflag2) = my.findmatch(0.5 * simL, x2sort, deltar) if (matchflag2 > 0): templist2 = [] for j in range(len(temp)): templist2.append(x2index[temp[j]]) if (matchflag1 + matchflag2) < 2.: nomemb = nomemb + 1. self.obsmembflag[i] = 0. print "no observed members in cluster ", i continue a = sets.Set(templist1) b = sets.Set(templist2) members = a & b members = list(members) #templist1=N.argsort(templist1) #templist2=N.argsort(templist2) subset = [] odv = [] odr = [] ccvobs = my.relsumv(vbox, 0.5 * simL * H0) ccz = my.zofv(ccvobs) cdtheta = self.r200[i] / my.DA(ccz, h) ccx1 = 0.5 * simL ccx2 = 0.5 * simL for k in members: dr = (N.sqrt((x1[k] - ccx1)**2 + (x2[k] - ccx2)**2)) / self.r200[i] if dr < nr: dv = (gvobs[k] - ccvobs) / (1 - gvobs[k] * ccvobs / (9.e10)) / self.sigma[i] if abs(dv) <= nv: #deltav: gdtheta = dr * self.r200[i] / my.DA(gz[k], h) if gdtheta <= cdtheta: #make sure galaxy is in cone field-of-view subset.append(k) odv.append(dv) odr.append(dr) self.obsmembids[i] = subset self.obsdr[i] = odr self.obsdv[i] = odv self.obsmembincut[i] = len(subset) if self.obsmembincut[i] < 1.: nomemb = nomemb + 1. self.obsmembflag[i] = 0. print nomemb, " clusters with no observed members", nomemb / len( self.x1)
caterrewha = N.array(caterrewha, 'f') index = N.zeros(len(ra), 'i') print "number of cluster galaxies = ", len(ra) ntime = 0 print "sorting catalog ra array" (catrasort, catraindex) = my.sortwindex(catra) deltara = .01 #matching tolerance in ra in arcsec deltara = deltara / 3600. * 15. #convert to degrees print "matching cluster galaxies against dr2 catalog" endloop = len(ra) for i in range(len(ra)): if 1. * i / 500. > ntime: print i, "galaxies", mx.DateTime.localtime(), "nomatch = ", nomatch ntime += 1 match = my.findmatch( ra[i], catrasort, deltara) #returns indices of catrasort that lie w/in deltara #print "matched",i try: #if more than one match, find closest in terms of ra,dec,z if len(match) > 1: diffmin = 1000000. for j in range(len(match)): catindex = catraindex[ match[j]] #catindex is for unsorted cat arrays diff = N.sqrt((catra[catindex] - ra[i])**2 + (catdec[catindex] - dec[i])**2 + (catz[catindex] - z[i])**2) if diff < diffmin: diffmin = diff catmatchindex = catindex index[i] = catmatchindex