Skip to content

Commit 8305a3d

Browse files
committed
added options for different ext curves
1 parent 95e90ae commit 8305a3d

File tree

3 files changed

+195
-50
lines changed

3 files changed

+195
-50
lines changed

create_UVgrid.cosma.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
#SBATCH -A dp004
33
#SBATCH -p cosma6
44
#SBATCH --job-name=creategrid_UV
5-
#SBATCH -t 0-1:00
6-
#SBATCH --ntasks 12
5+
#SBATCH -t 0-1:30
6+
#SBATCH --ntasks 20
77
#SBATCH --cpus-per-task=1
88
#SBATCH --ntasks-per-node=2
99
#SBATCH -o logs/std_output.%J
1010
#SBATCH -e logs/std_error.%J
1111

1212

1313
module purge
14-
module load python/3.6.5 gnu_comp/7.3.0 openmpi/3.0.1 parallel_hdf5/1.10.3
14+
module load python/3.6.5 gnu_comp/7.3.0 openmpi/3.0.1 hdf5/1.10.3
1515

1616
source ./venv_fl/bin/activate
1717

18-
mpiexec -n 12 python3 creategrid_and_fit.py Gridgen
18+
### 3 inputs are (Gridgen or not), (kappa_BC) and (extinction curve: default, Calzetti, SMC, N18)
19+
20+
mpiexec -n 20 python3 creategrid_and_fit.py Gridgen 5 Calzetti
1921

2022
echo "Job done, info follows..."
2123
sacct -j $SLURM_JOBID --format=JobID,JobName,Partition,MaxRSS,Elapsed,ExitCode

creategrid_and_fit.py

+42-16
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_chisquare(Mobs, phiobs, phiobserr, uplims, xdata, ydata):
3535

3636
#Weights for observational datapoints that are upper/lower limits
3737
w = np.ones(len(uplims))
38-
w[np.where(uplims==1)] = 1e-3
38+
w[np.where(uplims==1)] = 1e-5
3939

4040
chi = chisquare(phiobs, yy, phiobserr)
4141

@@ -44,19 +44,39 @@ def get_chisquare(Mobs, phiobs, phiobserr, uplims, xdata, ydata):
4444

4545
return chi
4646

47-
def read_data_and_fit(z):
48-
49-
data = np.genfromtxt(f"./Obs_data/uv_lum_Bouw15_z{z}.txt", delimiter=',', skip_header=1)
50-
M, phi, phi_err, uplims = data[:,0], data[:,1], data[:,2], data[:,3]
51-
52-
ok = np.where(M < -17.5)[0]
47+
def read_data_and_fit(z, BC_fac):
48+
49+
if z in [5, 6, 7]:
50+
data = np.genfromtxt(f"./Obs_data/uv_lum_Bouw15_z{z}.txt", delimiter=',', skip_header=1)
51+
M, phi, phi_err, uplims = data[:,0], data[:,1], data[:,2], data[:,3]
52+
elif z == 8:
53+
data = np.genfromtxt(f"./Obs_data/uv_lum_Bouw15_z{z}.txt", delimiter=',', skip_header=1)
54+
M, phi, phi_err, uplims = data[:,0], data[:,1], data[:,2], data[:,3]
55+
data = np.genfromtxt(f"./Obs_data/uv_lum_Bowler19_z{z}.txt", delimiter=',', skip_header=1)
56+
M1, M_err, phi1, phi_err1, uplims1 = data[:,0], data[:,1], data[:,2]*1e-6, data[:,3]*1e-6, data[:,4]
57+
M = np.append(M, M1)
58+
phi = np.append(phi, phi1)
59+
phi_err = np.append(phi_err, phi_err1)
60+
uplims = np.append(uplims, uplims1)
61+
elif z == 9:
62+
data = np.genfromtxt(f"./Obs_data/uv_lum_Bouw16_z{z}.txt", delimiter=',', skip_header=1)
63+
M, phi, phi_up, phi_low, uplims = data[:,0], data[:,1]*1e-3, data[:,2]*1e-3, data[:,3]*1e-3, data[:,4]
64+
phi_err = (phi_up + phi_low)/2.
65+
data = np.genfromtxt(f"./Obs_data/uv_lum_Bowler19_z{z}.txt", delimiter=',', skip_header=1)
66+
M1, M_err, phi1, phi_err1, uplims1 = data[:,0], data[:,1], data[:,2]*1e-6, data[:,3]*1e-6, data[:,4]
67+
M = np.append(M, M1)
68+
phi = np.append(phi, phi1)
69+
phi_err = np.append(phi_err, phi_err1)
70+
uplims = np.append(uplims, uplims1)
71+
72+
ok = np.where((M < -18) & (uplims==0))[0]
5373
M = M[ok]
5474
phi = phi[ok]
5575
phi_err = phi_err[ok]
5676
uplims = uplims[ok]
5777

5878
try:
59-
data = np.load(F'FUVLF_z{z}.npz')
79+
data = np.load(F'FUVLF_{extinction}_z{z}_BC{BC_fac}.npz')
6080

6181
except Exception as e:
6282
print ("Create grid first!")
@@ -65,7 +85,7 @@ def read_data_and_fit(z):
6585
bincen = data['Mag']
6686
hists = data['LF']
6787
Kappas = data['Kappas']
68-
ok = np.where(bincen < -17.5)[0]
88+
ok = np.where(bincen < -18)[0]
6989
bincen = bincen[ok]
7090
hists = hists[:,ok]
7191
binwidth = bincen[1] - bincen[0]
@@ -82,7 +102,7 @@ def read_data_and_fit(z):
82102

83103
return rchi
84104

85-
run_type = sys.argv[1]
105+
run_type, BC_fac, ext_curve = sys.argv[1], np.float(sys.argv[2]), sys.argv[3]
86106

87107
h = 0.6777
88108
sims = np.arange(0,40)
@@ -96,18 +116,22 @@ def read_data_and_fit(z):
96116
z = 5
97117
tag = '010_z005p000'
98118
vol = (4/3)*np.pi*(14/h)**3
119+
log10t_BC = 7.
120+
extinction = ext_curve
99121

100122
bins = np.arange(-24, -16, 0.2)
101123
bincen = (bins[1:]+bins[:-1])/2.
102124
binwidth=bins[1:]-bins[:-1]
103125

104126
# Range of Kappa explored
105-
Kappas = np.arange(0.0, 0.2, 0.0025)
127+
Kappas = np.arange(0.01, 0.016, 0.00005)#np.arange(0.005, 0.03, 0.00025)
106128

107129
comm = MPI.COMM_WORLD
108130
rank = comm.Get_rank()
109131
size = comm.Get_size()
110132

133+
if rank == 0: print (F"MPI size = {size}")
134+
111135
if run_type == 'Gridgen':
112136

113137
hist = np.zeros((len(Kappas),len(bincen)))
@@ -129,30 +153,32 @@ def read_data_and_fit(z):
129153
else:
130154
thisok = np.arange(rank*part, len(Kappas), 1).astype(int)
131155

156+
print (F'Rank {rank} will be running {len(thisok)} task(s)')
157+
132158
for ii, jj in enumerate(thisok):
133159

134-
data, num, derr = get_lum_all(Kappas[jj], tag, bins = bins, LF = True, filters = ['FAKE.TH.FUV'])
160+
data, num, derr = get_lum_all(Kappas[jj], tag, BC_fac, bins = bins, LF = True, filters = ['FAKE.TH.FUV'], log10t_BC = log10t_BC, extinction = extinction)
135161
hist[jj] = data/(binwidth*vol)
136162
err[jj] = derr/(binwidth*vol)
137163

138164
comm.Reduce(hist, hists, op=MPI.SUM, root=0)
139165
comm.Reduce(err, errs, op=MPI.SUM, root=0)
140166

141167
if rank == 0:
142-
np.savez('FUVLF_z{}.npz'.format(z), LF = hists, err = errs, Mag = bincen, Kappas = Kappas)
168+
np.savez('FUVLF_{}_z{}_BC{}.npz'.format(extinction, z, BC_fac), LF = hists, err = errs, Mag = bincen, Kappas = Kappas)
143169

144170
if rank == 0:
145-
rchi = read_data_and_fit(z)
171+
rchi = read_data_and_fit(z, BC_fac)
146172
print ('Kappa = ', Kappas[np.where(rchi==np.min(rchi))[0]])
147173

148174
fig, axs = plt.subplots(nrows = 1, ncols = 1, figsize=(6, 6), sharex=True, sharey=True, facecolor='w', edgecolor='k')
149175

150176
axs.plot(Kappas, rchi)
151177
axs.scatter(Kappas[np.where(rchi==np.min(rchi))[0]], np.min(rchi), marker = 'x', color = 'red')
152-
axs.text(Kappas[3*int(len(Kappas)/4)], int(np.max(rchi/2)), rF"$\kappa$ = {Kappas[np.where(rchi==np.min(rchi))[0]]}", fontsize = 15)
178+
axs.text(Kappas[int(len(Kappas)/4)], np.median(rchi), rF"$\kappa$ = {Kappas[np.where(rchi==np.min(rchi))[0]]}", fontsize = 15)
153179
axs.set_xlabel(r"$\kappa$'s", fontsize = 15)
154180
axs.set_ylabel(r"reduced $\chi^2$")
155181
axs.grid(True)
156182
fig.tight_layout()
157-
plt.savefig('kappa_vs_rchi.png')
183+
plt.savefig(F'kappa_vs_rchi_{extinction}_BC{BC_fac}_z{z}.png')
158184
plt.close()

0 commit comments

Comments
 (0)