-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMake_schechter_param_tables.py
executable file
·117 lines (98 loc) · 4.22 KB
/
Make_schechter_param_tables.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
############################################################################################################
# A script for formatting the best-fit results from the previous step into a LaTeX-stle table.
############################################################################################################
#import modules/packages
import os, sys
import general as gen
import numpy as np
#######################################################
############### START OF SCRIPT #################
#######################################################
#padding to use between lines of data
padding = '0.5em'
#filename to give to table
tab_name = gen.PATH_TABLES + f'Schechter_params_{gen.n_gal}{gen.gal_type}.tex'
#see if PATH_TABLES already exists, and make it if it doesn't
if not os.path.exists(gen.PATH_TABLES):
os.system(f'mkdir -p {gen.PATH_TABLES}')
#set up the table preamble
tab_lines = [r'\begin{table}']
#decide the caption and label
caption = '''
Best-fit Schechter parameters for the differential and cumulative number counts, obtained from
MCMC fitting.
'''
label = 'tab:params'
#add more table pramble, but idnent for ease of interpretation
add_lines = [r'\centering', r'\caption{%s}'%caption, r'\label{%s}'%label]
add_lines = ['\t' + s for s in add_lines]
tab_lines.extend(add_lines)
#begin tabular environment
alignment = 'c'
align_all = ''.join([alignment]*7)
tab_lines.append('\t' + r'\begin{tabular}{%s}'%align_all)
#column titles
title_lines = [r'\hline']
titles = ['', r'Radius [$\arcmin$]', r'$N_{0}$', r'$S_{0}$', r'$\gamma$']
#join the titles together
title_lines.append(r' & '.join(titles) + r'\\')
title_lines.append(r'\hline')
title_lines.append(r'\hline')
title_lines.append(r'\vspace{0.5em}')
title_lines = ['\t\t' + s for s in title_lines]
#append these to the list of lines
tab_lines.extend(title_lines)
#set up a list for the lines of data in the table
data_lines = []
#data containing the best-fit parameters for the various radii
nc_data = [np.load(gen.PATH_CATS + 'Schechter_params/' + f'Differential_{r:.1f}am_{gen.n_gal}{gen.gal_type}.npz')['ALL'] for r in gen.r_search_all]
cc_data = [np.load(gen.PATH_CATS + 'Schechter_params/' + f'Cumulative_{r:.1f}am_{gen.n_gal}{gen.gal_type}.npz')['ALL'] for r in gen.r_search_all]
#get the number of different radii used
N_radii = len(gen.r_search_all)
#cycle through differential vs cumulative results
for counttype, data in zip(['Differential', 'Cumulative'], [nc_data, cc_data]):
for j in range(N_radii):
#get the radius used for the current datasets
r = gen.r_search_all[j]
#if the first radius used, include a multirow entry stating the type of number counts
if r == gen.r_search_all[0]:
params_all = ['\t\t' + r'\multirow{%i}{*}{%s}'%(N_radii,counttype), r'%g'%r]
#otherwise keep the first entry empty
else:
params_all = ['\t\t' + r' & %g'%r]
for i in range(len(data[j][0])):
#parameter and errors
pe = data[j][:,i]
pe = [gen.round_sigfigs(x, 2) for x in pe]
if pe[0] > 100:
params_all.append(r'$%g_{-%g}^{+%g}$'%tuple(pe))
else:
params_all.append(r'$%.1f_{-%.1f}^{+%.1f}$'%tuple(pe))
'''
if r == gen.r_search_all[-1]:
data_lines.append(' & '.join(params_all) + r'\\' + '\n\t\t' + r'\hline' + '\n\t\t' + r'\vspace{%s}'%padding)
else:
data_lines.append(' & '.join(params_all) + r'\\' + '\n\t\t' + r'\vspace{%s}'%padding)
'''
data_lines.append(' & '.join(params_all) + r'\\' + '\n\t\t' + r'\vspace{%s}'%padding)
#retrieve the best-fit parameters for the blank field
bf_data = np.load(gen.PATH_CATS + 'Schechter_params/' + f'{counttype}_bf.npz')['S2COSMOS']
#cycle through each parameter
params_all = ['\t\t' + 'S2COSMOS', '--']
for i in range(len(bf_data[0])):
#parameter and errors
pe = bf_data[:,i]
pe = [gen.round_sigfigs(x, 2) for x in pe]
if pe[0] > 100:
params_all.append(r'$%g_{-%g}^{+%g}$'%tuple(pe))
else:
params_all.append(r'$%.1f_{-%.1f}^{+%.1f}$'%tuple(pe))
data_lines.append(' & '.join(params_all) + r'\\' + '\n\t\t' + r'\hline' + '\n\t\t'+ r'\vspace{%s}'%padding)
tab_lines.extend(data_lines)
#tab_lines.append('\t\t' + r'\hline')
#end tabular environment
tab_lines.append('\t' + r'\end{tabular}')
tab_lines.append(r'\end{table}')
#write to a the file
with open(tab_name, 'w') as f:
f.write('\n'.join(tab_lines))