-
Notifications
You must be signed in to change notification settings - Fork 1
/
print_summary.py
61 lines (43 loc) · 2.05 KB
/
print_summary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Print the number of matched objects in truth catalogs
# Example: DR9.0 truth catalogs:
# python print_summary.py 9.0
from __future__ import division, print_function
import sys, os, time, argparse, glob
import numpy as np
import fitsio
from astropy.io import fits
from catalog_info import catalog_info
parser = argparse.ArgumentParser()
parser.add_argument('ls_dr')
args = parser.parse_args()
ls_dr = args.ls_dr
top_dir = '/global/cfs/cdirs/desi/target/analysis/truth'
# top_dir = '/global/cfs/cdirs/desi/users/rongpu/truth'
parent_dir = os.path.join(top_dir, 'parent/')
end_string = '-match.fits'
# catalogs = ["hsc-dr3"]
catalogs = sorted(glob.glob('truth_catalogs/*.yaml'))
catalogs = [string[15:-5] for string in catalogs]
for field in ['north', 'south']:
print('\n------------------------------------------------------')
print('------------------------------------------------------\n')
print('DR'+ls_dr+' '+field)
print('-----------\n')
output_dir_matched = os.path.join(top_dir, 'dr'+ls_dr, field, 'matched')
for index in range(len(catalogs)):
print(catalogs[index])
cat_info = catalog_info(catalogs[index], ls_dr, field=field)
ra_col, dec_col, search_radius, cat2_fns, cat1_output_fns, plot_path, ext = cat_info
for cat2_index in range(len(cat2_fns)):
cat1_output_path_trim = os.path.join(output_dir_matched, cat1_output_fns[cat2_index][:-5]+end_string)
cat1_output_path_trim = os.path.join(output_dir_matched, cat1_output_fns[cat2_index][:-5]+end_string)
cat2_fn = cat2_fns[cat2_index]
cat2_path = os.path.join(parent_dir, cat2_fn)
if os.path.isfile(cat1_output_path_trim):
cat2 = fitsio.read(cat2_path, ext=ext, columns=[ra_col])
t = fits.getdata(cat1_output_path_trim)
print('{} {} {:.2f}%'.format(cat2_fn, len(t), 100*len(t)/len(cat2)))
else:
print(cat2_fn, ' No match')
continue
print('\n------------------------------------------------------\n')