Skip to content

Commit d37cb6d

Browse files
committed
minor changes to a few things
1 parent 2e99bb9 commit d37cb6d

File tree

4 files changed

+74
-97
lines changed

4 files changed

+74
-97
lines changed

Sandbox/lastnight_LRGsuccess.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
zdir = '/global/cfs/cdirs/desi/spectro/redux/daily/tiles/cumulative/'
5858

5959
nzls = {x: [] for x in range(0,10)}
60+
nzla = []
6061
for tid in tidl:
6162
for pt in range(0,10):
6263

@@ -81,6 +82,7 @@
8182
gz[pt] += len(gzlrg)
8283
tz[pt] += len(zlrg)
8384
nzls[pt].append(zmtlf[wzwarn&wlrg]['Z'])
85+
nzla.append(zmtlf[wzwarn&wlrg]['Z'])
8486
else:
8587
print('no good lrg data')
8688
else:
@@ -95,9 +97,11 @@
9597

9698
if args.plotnz == 'y':
9799
from matplotlib import pyplot as plt
100+
nza = np.concatenate(nzla)
98101
for pt in range(0,10):
99102
nzp = np.concatenate(nzls[pt])
100-
plt.hist(nzp,range=(0.01,1.4),bins=28)
103+
a = plt.hist(nzp,range=(0.01,1.4),bins=28,density=True)
104+
plt.hist(nza,bins=a[1],density=True,histtype='step')
101105
plt.title('petal '+str(pt))
102106
plt.xlabel('Z')
103107
plt.show()

py/LSS/common_tools.py

+66-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
import fitsio
3-
from astropy.table import Table
3+
from astropy.table import Table,join
44

55
from LSS.tabulated_cosmo import TabulatedDESI
66
cosmo = TabulatedDESI()
@@ -10,6 +10,71 @@
1010

1111
#functions that shouldn't have any dependence on survey go here
1212

13+
def find_znotposs(dz):
14+
15+
dz.sort('TARGETID')
16+
tidnoz = []
17+
tids = np.unique(dz['TARGETID'])
18+
ti = 0
19+
i = 0
20+
21+
print('finding targetids that were not observed')
22+
while i < len(dz):
23+
za = 0
24+
25+
while dz[i]['TARGETID'] == tids[ti]:
26+
if dz[i]['ZWARN'] != 999999:
27+
za = 1
28+
#break
29+
i += 1
30+
if i == len(dz):
31+
break
32+
if za == 0:
33+
tidnoz.append(tids[ti])
34+
35+
if ti%30000 == 0:
36+
print(ti)
37+
ti += 1
38+
39+
40+
selnoz = np.isin(dz['TARGETID'],tidnoz)
41+
tidsb = np.unique(dz[selnoz]['TILELOCID'])
42+
#dz = dz[selnoz]
43+
dz.sort('TILELOCID')
44+
tids = np.unique(dz['TILELOCID'])
45+
print('number of targetids with no obs '+str(len(tidnoz)))
46+
tlidnoz = []
47+
lznposs = []
48+
49+
ti = 0
50+
i = 0
51+
52+
while i < len(dz):
53+
za = 0
54+
55+
while dz[i]['TILELOCID'] == tids[ti]:
56+
if dz[i]['ZWARN'] != 999999:
57+
za = 1
58+
#break
59+
i += 1
60+
if i == len(dz):
61+
break
62+
if za == 0:
63+
tlidnoz.append(tids[ti])
64+
#if np.isin(tids[ti],tidsb):
65+
# lznposs.append(tids[ti])
66+
67+
if ti%30000 == 0:
68+
print(ti,len(tids))
69+
ti += 1
70+
#the ones to veto are now the join of the two
71+
wtbtlid = np.isin(tlidnoz,tidsb)
72+
tlidnoz = np.array(tlidnoz)
73+
lznposs = tlidnoz[wtbtlid]
74+
print('number of locations where assignment was not possible because of priorities '+str(len(lznposs)))
75+
return lznposs
76+
77+
1378
def mknz(fcd,fcr,fout,bs=0.01,zmin=0.01,zmax=1.6):
1479
'''
1580
fcd is the full path to the catalog file in fits format with the data; requires columns Z and WEIGHT

py/LSS/main/cattools.py

+1-95
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#from LSS.Cosmo import distance
1818
from LSS.imaging import densvar
19+
from LSS.common_tools import find_znotposs
1920

2021

2122

@@ -365,69 +366,6 @@ def gettarinfo_type(faf,tars,goodloc,pdict,tp='SV3_DESI_TARGET'):
365366

366367
return tt
367368

368-
def find_znotposs(dz):
369-
370-
dz.sort('TARGETID')
371-
tidnoz = []
372-
tids = np.unique(dz['TARGETID'])
373-
ti = 0
374-
i = 0
375-
376-
print('finding targetids that were not observed')
377-
while i < len(dz):
378-
za = 0
379-
380-
while dz[i]['TARGETID'] == tids[ti]:
381-
if dz[i]['ZWARN'] != 999999:
382-
za = 1
383-
#break
384-
i += 1
385-
if i == len(dz):
386-
break
387-
if za == 0:
388-
tidnoz.append(tids[ti])
389-
390-
if ti%30000 == 0:
391-
print(ti)
392-
ti += 1
393-
394-
395-
selnoz = np.isin(dz['TARGETID'],tidnoz)
396-
tidsb = np.unique(dz[selnoz]['TILELOCID'])
397-
#dz = dz[selnoz]
398-
dz.sort('TILELOCID')
399-
tids = np.unique(dz['TILELOCID'])
400-
print('number of targetids with no obs '+str(len(tidnoz)))
401-
tlidnoz = []
402-
lznposs = []
403-
404-
ti = 0
405-
i = 0
406-
407-
while i < len(dz):
408-
za = 0
409-
410-
while dz[i]['TILELOCID'] == tids[ti]:
411-
if dz[i]['ZWARN'] != 999999:
412-
za = 1
413-
#break
414-
i += 1
415-
if i == len(dz):
416-
break
417-
if za == 0:
418-
tlidnoz.append(tids[ti])
419-
#if np.isin(tids[ti],tidsb):
420-
# lznposs.append(tids[ti])
421-
422-
if ti%30000 == 0:
423-
print(ti,len(tids))
424-
ti += 1
425-
#the ones to veto are now the join of the two
426-
wtbtlid = np.isin(tlidnoz,tidsb)
427-
tlidnoz = np.array(tlidnoz)
428-
lznposs = tlidnoz[wtbtlid]
429-
print('number of locations where assignment was not possible because of priorities '+str(len(lznposs)))
430-
return lznposs
431369

432370
def get_specdat(indir,pd):
433371
#indir = '/global/cfs/cdirs/desi/survey/catalogs/main/LSS/'+specrel
@@ -1670,38 +1608,6 @@ def mkclusran(fl,rann,rcols=['Z','WEIGHT'],zmask=False,tsnrcut=80,tsnrcol='TSNR2
16701608
ffss.write(outfn,format='fits', overwrite=True)
16711609

16721610

1673-
def addnbar(fb,nran=18,bs=0.01,zmin=0.01,zmax=1.6):
1674-
nzd = np.loadtxt(fb+'_nz.dat').transpose()[3] #column with nbar values
1675-
fn = fb+'_clustering.dat.fits'
1676-
fd = fitsio.read(fn) #reading in data with fitsio because it is much faster to loop through than table
1677-
zl = fd['Z']
1678-
nl = np.zeros(len(zl))
1679-
for ii in range(0,len(zl)):
1680-
z = zl[ii]
1681-
zind = int((z-zmin)/bs)
1682-
if z > zmin and z < zmax:
1683-
nl[ii] = nzd[zind]
1684-
del fd
1685-
ft = Table.read(fn)
1686-
ft['NZ'] = nl
1687-
ft.write(fn,format='fits',overwrite=True)
1688-
print('done with data')
1689-
for rann in range(0,nran):
1690-
fn = fb+'_'+str(rann)+'_clustering.ran.fits'
1691-
fd = fitsio.read(fn) #reading in data with fitsio because it is much faster to loop through than table
1692-
zl = fd['Z']
1693-
nl = np.zeros(len(zl))
1694-
for ii in range(0,len(zl)):
1695-
z = zl[ii]
1696-
zind = int((z-zmin)/bs)
1697-
if z > zmin and z < zmax:
1698-
nl[ii] = nzd[zind]
1699-
del fd
1700-
ft = Table.read(fn)
1701-
ft['NZ'] = nl
1702-
ft.write(fn,format='fits',overwrite=True)
1703-
print('done with random number '+str(rann))
1704-
return True
17051611

17061612

17071613

scripts/main/donz_DA02.py

+2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535

3636
regl = ['_DN','_DS','','_N','_S']
3737

38+
3839
for reg in regl:
40+
print(type,reg)
3941
fb = dirout+type+wzm+reg
4042
fcr = fb+'_0_clustering.ran.fits'
4143
fcd = fb+'_clustering.dat.fits'

0 commit comments

Comments
 (0)