-
Notifications
You must be signed in to change notification settings - Fork 0
/
inclination_pdf.pro
278 lines (249 loc) · 9.77 KB
/
inclination_pdf.pro
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
pro inclination_pdf,q,q_err,folder,inc_bins,inc_pdf,NTRIALS=NTRIALS,$
NQGAUSSIAN=NQGAUSSIAN,NBINS_INC=NBINS_INC,RAN_Q=RAN_Q,RAN_INC=RAN_INC,$
GEDIST=GEDIST,UNITS=UNITS,GAM_EPS=GAM_EPS
;+
; NAME:
; INCLINATION_PDF
; PURPOSE:
; To create the probability distribution function (PDF) of inclination as described
; in Doore et al. (2021)
; EXPLANATION:
; Creates a distribution of inclination from the input axis ratio q and error,
; assuming the input q has a Gaussian distribution, using a Monte Carlo method.
; Can use the distributions of asymmetry and intrinsic thickness of spiral galaxies
; from Rodriguez & Padilla (2013).
;
; CALLING SEQUENCE:
; inclination_pdf, q, q_err, folder, inc_bins, inc_pdf, [NTRIALS=NTRIALS, $
; NQGAUSSIAN=NQGAUSSIAN, NBINS_INC=NBINS_INC, RAN_Q=RAN_Q, RAN_INC=RAN_INC,$
; GEDIST=GEDIST,UNITS=UNITS,GAM_EPS=GAM_EPS]
;
; INPUTS:
; q - a N element vector containing the values of axis ratio to be considered
; q_err - a N element vector containing the corresponding axis ratio error values
; folder - a string containing the directory location of the files of the gamma and epsilon
; distributions from Rodriguez & Padilla (2013)
;
; OPTIONAL INPUTS:
; NTRIALS - a single value containing the number of trials to run the Monte Carlo
; simulation (default = 1e7)
; NQGAUSSIAN - a single value containing the number of elements to use in the Gaussian
; distribution of q (default = 1e6)
; NBINS_INC - a single value containing the number of bins for which to determine
; the distribution of inclination (default = 180)
; GEDIST - a string containing the distribution to use for gamma and epsilon from
; Figure 11 of Rodriguez & Padilla (2013). Options are the color of the
; distributions: red (default), blue, or green
; UNITS - a string containing the desired units of the output inc_bins. Options
; are degrees (default), radians, cosi (cosine of the inclination)
; GAM_EPS - a 2 element vector containing the fixed values of gamma and epsilon,
; respectively. Values for both must be between 0 and 1. If set, then
; GEDIST input will be ignored.
;
; OUTPUTS:
; inc_bins - an NBINS_INC element vector containing the inclinations in the units given
; in the optional input UNITS corresponding to the PDF values. Points are
; at the center of each bin
; inc_pdf - an NBINS_INC x N element array containing the normalized PDF values for
; the inclination of each input galaxies axis ratio.
;
; OPTIONAL OUTPUTS:
; RAN_Q - a NTRIALS element vector containing the q values from the Monte Carlo simulation
; RAN_INC - a NTRIALS element vector containing the corresponding inclination values to
; q from the Monte Carlo simulation
;
; EXAMPLE USAGE:
; IDL> inclination_pdf,0.3,0.01,'~/YOUR_FOLDER/',inc_bins,inc_pdf
; IDL> help, inc_bins,inc_pdf
; IDL> plot(inc_bins,inc_pdf)
;
; REVISON HISTORY:
; Written by K. Doore, 9/01/2020
; Updated by K. Doore, 3/03/2021
; - Replaced the optional keyword RADIANS with optional input of UNITS to allow for
; specifying the units as DEGREES, RADIANS, or COSI. Changed INC_BINWIDTH to be
; NBINS_INC to be general for the variation in the possible units
; - Added the optional input of GAM_EPS to allow for the values of gamma and epsilon
; to be fixed to a specific value
; - Updated the descriptions of each input/output to be more detailed
;-
Compile_opt idl2
On_error,2
; Check for incorrect inputs
if size(q,/type) lt 2 or size(q,/type) gt 5 then begin
print,'q is incorrect data type'
return
endif
if size(q,/n_dim) gt 1 then begin
print,'q must be 1 dimensional'
return
endif
if min(q) lt 0 or max(q) gt 1 then begin
print,'q must be between 0 and 1'
return
endif
if size(q_err,/type) lt 2 or size(q_err,/type) gt 5 then begin
print,'q_err is incorrect data type'
return
endif
if size(q_err,/n_dim) gt 1 then begin
print,'q_err must be 1 dimensional'
return
endif
if n_elements(q_err) ne n_elements(q) then begin
print,'q and q_err need same number of elements'
return
endif
if min(q_err) le 0 then begin
print,'q_err must be greater than 0'
return
endif
if size(folder,/type) ne 7 then begin
print,'folder is not of type STRING'
return
endif
if n_elements(NTRIALS) gt 0 then begin
if size(NTRIALS,/type) lt 2 or size(NTRIALS,/type) gt 5 then begin
print,'NTRIALS is incorrect data type'
return
endif
if min(NTRIALS) lt 0 then begin
print,'NTRIALS must be greater than 0'
return
endif
endif else begin
NTRIALS = 1e7
endelse
if n_elements(NQGAUSSIAN) gt 0 then begin
if size(NQGAUSSIAN,/type) lt 2 or size(NQGAUSSIAN,/type) gt 5 then begin
print,'NQGAUSSIAN is incorrect data type'
return
endif
if min(NQGAUSSIAN) lt 0 then begin
print,'NQGAUSSIAN must be greater than 0'
return
endif
endif else begin
NQGAUSSIAN = 1e6
endelse
if n_elements(NTRIALS) lt n_elements(NQGAUSSIAN) then begin
print,'NTRIALS needs to be larger than NQGAUSSIAN'
return
endif
if n_elements(NBINS_INC) gt 0 then begin
if size(NBINS_INC,/type) lt 2 or size(NBINS_INC,/type) gt 5 then begin
print,'NBINS_INC is incorrect data type'
return
endif
if min(NBINS_INC) le 0 then begin
print,'NBINS_INC must be positive'
return
endif
endif else begin
NBINS_INC = 180
endelse
if n_elements(GEDIST) gt 0 then begin
if size(GEDIST,/type) ne 7 then begin
print,'GEDIST must be of type string'
return
endif
if ~STRCMP(GEDIST,'red',/fold_case) and ~STRCMP(GEDIST,'blue',/fold_case) and $
~STRCMP(GEDIST,'green',/fold_case) then begin
print,'GEDIST must be either red, blue, or green'
return
endif
endif else begin
if n_elements(GAM_EPS) eq 0 then GEDIST = 'red'
endelse
if n_elements(UNITS) gt 0 then begin
if size(UNITS,/type) ne 7 then begin
print,'UNITS must be of type string'
return
endif
if ~STRCMP(UNITS,'degrees',/fold_case) and ~STRCMP(UNITS,'radians',/fold_case) and $
~STRCMP(UNITS,'cosi',/fold_case) then begin
print,'UNITS must be either degrees, radians, or cosi'
return
endif
endif else begin
UNITS = 'degrees'
endelse
if n_elements(GAM_EPS) gt 0 then begin
if size(GAM_EPS,/type) lt 2 or size(GAM_EPS,/type) gt 5 then begin
print,'GAM_EPS is incorrect data type'
return
endif
if n_elements(GAM_EPS) ne 2 then begin
print,'GAM_EPS must be a two element vector'
return
endif
if GAM_EPS[0] lt 0 or GAM_EPS[0] gt 1 then begin
print,'The first element of GAM_EPS (gamma) must be between 0 and 1'
return
endif
if GAM_EPS[1] lt 0 or GAM_EPS[1] gt 1 then begin
print,'The second element of GAM_EPS (epsilon) must be between 0 and 1'
return
endif
endif
; compute the cumulative PDFs of gamma and epsilon
if n_elements(GEDIST) gt 0 then begin
if STRCMP(GEDIST,'red',/fold_case) then begin
readcol,folder+'gamma_spirals_red.txt',gam_val,gam_PDF,f='f,f',/silent
readcol,folder+'epsilon_spirals_red.txt',eps_val,eps_PDF,f='f,f',/silent
endif else if STRCMP(GEDIST,'blue',/fold_case) then begin
readcol,folder+'gamma_spiralsfracDeV_blue.txt',gam_val,gam_PDF,f='f,f',/silent
readcol,folder+'epsilon_spiralsfracDeV_blue.txt',eps_val,eps_PDF,f='f,f',/silent
endif else if STRCMP(GEDIST,'green',/fold_case) then begin
readcol,folder+'gamma_spiralsPS08_green.txt',gam_val,gam_PDF,f='f,f',/silent
readcol,folder+'epsilon_spiralsPS08_green.txt',eps_val,eps_PDF,f='f,f',/silent
endif
gam=[0:1:0.0001]
eps=[0:1:0.0001]
PDF_gam=interpol(gam_PDF,gam_val,gam)
PDF_eps=interpol(eps_PDF,eps_val,eps)
CUMPDF_gam=total(pdf_gam,/cum)/max(total(pdf_gam,/cum))
CUMPDF_eps=total(pdf_eps,/cum)/max(total(pdf_eps,/cum))
; run the Monte Carlo simulation
ran_gam=interpol(gam,cumpdf_gam,randomu(seed,NTRIALS))
ran_eps=interpol(eps,cumpdf_eps,randomu(seed,NTRIALS))
endif else begin
ran_gam=replicate(GAM_EPS[0],NTRIALS)
ran_eps=replicate(GAM_EPS[1],NTRIALS)
endelse
ran_phi=randomu(seed,NTRIALS)*2*!pi
ran_cosi=randomu(seed,NTRIALS)
ran_q=sqrt(ran_cosi^2*(1-ran_gam^2)+ran_gam^2)*(1-ran_eps*cos(2*ran_phi))
keep=where(ran_q le 1 and ran_q ge 0)
if STRCMP(UNITS,'degrees',/fold_case) then begin
ran_inc=acos(ran_cosi)/!dtor
binvals=[0:90:(90/double(NBINS_INC))]
inc_bins=binvals[1:*]-((90/double(NBINS_INC))/2.d)
endif else if STRCMP(UNITS,'radians',/fold_case) then begin
ran_inc=acos(ran_cosi)
binvals=[0:(!dpi/2.d):((!dpi/2.d)/double(NBINS_INC))]
inc_bins=binvals[1:*]-(((!dpi/2.d)/double(NBINS_INC))/2.d)
endif else if STRCMP(UNITS,'cosi',/fold_case) then begin
ran_inc=ran_cosi
binvals=[0:1:(1/double(NBINS_INC))]
inc_bins=binvals[1:*]-((1/double(NBINS_INC))/2.d)
endif
ran_inc=ran_inc[keep]
ran_q=ran_q[keep]
ran_inc=ran_inc[sort(ran_q)]
ran_q=ran_q[sort(ran_q)]
; compute the inclination PDF
nbins=n_elements(inc_bins)
inc_PDF=dblarr(nbins,n_elements(q))
for i=0,(n_elements(q)-1) do begin
q_dist=randomn(seed,NQGAUSSIAN)*q_err[i]+q[i]
q_dist=q_dist[where(q_dist ge 0 and q_dist le 1)]
values=ran_inc[value_locate(ran_q,q_dist,/l64)]
for j=0,(n_elements(binvals)-2) do begin
temp_num=where(values ge binvals[j] and values lt binvals[j+1],num)
inc_PDF[j,i]=num
endfor
inc_PDF[*,i]=inc_pdf[*,i]/INT_TABULATED(inc_bins,inc_pdf[*,i])
endfor
return
end