-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeightFunctions.jl
245 lines (226 loc) · 11.2 KB
/
WeightFunctions.jl
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
"""
ComputeWeightFunction(z::Float64, i::Int64, ConvolvedDensity::AbstractConvolvedDensity,
AnalitycalDensity::AnalitycalDensity, InstrumentResponse::InstrumentResponse,
w0waCDMCosmology::w0waCDMCosmology, GCWeightFunction::GCWeightFunction)
This function returns the Galaxy Clustering Weight function for a given redshift
``z`` and tomographic bin ``i``.
"""
function ComputeWeightFunction(z::T, i::I,
ConvolvedDensity::AbstractConvolvedDensity, AnalitycalDensity::AnalitycalDensity,
InstrumentResponse::InstrumentResponse, Cosmology::AbstractCosmology,
GCWeightFunction::GCWeightFunction) where {T, I}
c_0 = 2.99792458e5 #TODO: find a package containing the exact value of
#physical constants involved in calculations
return ComputeConvolvedDensity(z, i, ConvolvedDensity,
AnalitycalDensity, InstrumentResponse) *
ComputeBias(z, GCWeightFunction.BiasKind, ConvolvedDensity) *
ComputeHubbleFactor(z, Cosmology) / c_0
end
"""
ComputeWeightFunctionGrid!(GCWeightFunction::GCWeightFunction,
ConvolvedDensity::AbstractConvolvedDensity, CosmologicalGrid::CosmologicalGrid,
BackgroundQuantities::BackgroundQuantities, Cosmology::AbstractCosmology)
This function evaluates the Galaxy Clustering Weight Function over the ``z``
grid and for all tomographic bins ``i``.
"""
function ComputeWeightFunctionGrid!(GCWeightFunction::GCWeightFunction,
ConvolvedDensity::AbstractConvolvedDensity, CosmologicalGrid::CosmologicalGrid,
BackgroundQuantities::BackgroundQuantities, Cosmology::AbstractCosmology)
c_0 = 2.99792458e5 #TODO: find a package containing the exact value of
#physical constants involved in calculations
#TODO use avx here to accelerate
for idx_ZBinArray in 1:length(ConvolvedDensity.ZBinArray)-1
for idx_ZArray in 1:length(CosmologicalGrid.ZArray)
GCWeightFunction.WeightFunctionArray[idx_ZBinArray, idx_ZArray] =
GCWeightFunction.BiasArray[idx_ZBinArray, idx_ZArray]*
ConvolvedDensity.DensityGridArray[idx_ZBinArray,
idx_ZArray] *
BackgroundQuantities.HZArray[idx_ZArray] / c_0
end
end
end
"""
ComputeLensingEfficiency(z::Float64, i::Int64,
ConvolvedDensity::AbstractConvolvedDensity, AnalitycalDensity::AnalitycalDensity,
InstrumentResponse::InstrumentResponse, w0waCDMCosmology::w0waCDMCosmology,
CosmologicalGrid::CosmologicalGrid, ::WLWeightFunction)
This function returns the Lensing efficiency, for a given redshift
``z`` and tomographic bin ``i``.
"""
function ComputeLensingEfficiency(z::T, i::I,
ConvolvedDensity::AbstractConvolvedDensity,
AnalitycalDensity::AnalitycalDensity,
InstrumentResponse::InstrumentResponse,
Cosmology::AbstractCosmology,
CosmologicalGrid::CosmologicalGrid,
::WLWeightFunction) where {T,I}
int, err = quadgk(x -> CosmoCentral.ComputeConvolvedDensity(
x, i, ConvolvedDensity, AnalitycalDensity, InstrumentResponse)*
((Computeχ(x, Cosmology) -
Computeχ(z, Cosmology))/
(Computeχ(x, Cosmology) *
Computeχ(z, Cosmology) ) ), z,
last(CosmologicalGrid.ZArray) , rtol=1e-12)
return int
end
function ComputeLensingEfficiency(z::T, i::I, ConvolvedDensity::AbstractConvolvedDensity,
AnalitycalDensity::AnalitycalDensity, InstrumentResponse::InstrumentResponse,
Cosmology::AbstractCosmology, CosmologicalGrid::CosmologicalGrid,
LensingSourceFunction::LensingSourceFunction) where {T,I}
int, err = quadgk(x -> CosmoCentral.ComputeConvolvedDensity(
x, i, ConvolvedDensity, AnalitycalDensity, InstrumentResponse)*
((Computeχ(x, Cosmology) -
Computeχ(z, Cosmology))/
(Computeχ(x, Cosmology) *
Computeχ(z, Cosmology) ) ), z,
last(CosmologicalGrid.ZArray) , rtol=1e-12)
return int
end
"""
ComputeLensingEfficiencyGrid!(LensingFunction::WLWeightFunction,
AnalitycalDensity::AnalitycalDensity, InstrumentResponse::InstrumentResponse,
ConvolvedDensity::AbstractConvolvedDensity, CosmologicalGrid::CosmologicalGrid,
BackgroundQuantities::BackgroundQuantities, Cosmology::AbstractCosmology,
::StandardLensingEfficiency)
This function evaluates the Lensing Efficiency over the ``z``
grid and for all tomographic bins ``i``.
"""
function ComputeLensingEfficiencyGrid!(LensingFunction::WLWeightFunction,
AnalitycalDensity::AnalitycalDensity, InstrumentResponse::InstrumentResponse,
ConvolvedDensity::AbstractConvolvedDensity, CosmologicalGrid::CosmologicalGrid,
BackgroundQuantities::BackgroundQuantities, Cosmology::AbstractCosmology,
::StandardLensingEfficiency)
for idx_ZBinArray in 1:length(ConvolvedDensity.ZBinArray)-1
for idx_ZArray in 1:length(CosmologicalGrid.ZArray)
LensingFunction.LensingEfficiencyArray[idx_ZBinArray, idx_ZArray] =
ComputeLensingEfficiency(CosmologicalGrid.ZArray[idx_ZArray],
idx_ZBinArray, ConvolvedDensity, AnalitycalDensity,
InstrumentResponse, Cosmology, CosmologicalGrid,
LensingFunction)
end
end
end
function ComputeLensingEfficiencyGrid!(
LensingSourceFunction::LensingSourceFunction,
AnalitycalDensity::AnalitycalDensity,
InstrumentResponse::InstrumentResponse,
ConvolvedDensity::AbstractConvolvedDensity,
CosmologicalGrid::CosmologicalGrid,
BackgroundQuantities::BackgroundQuantities,
Cosmology::AbstractCosmology,
::StandardLensingEfficiency)
for idx_ZBinArray in 1:length(ConvolvedDensity.ZBinArray)-1
for idx_ZArray in 1:length(CosmologicalGrid.ZArray)
LensingSourceFunction.LensingEfficiencyArray[idx_ZBinArray, idx_ZArray] =
ComputeLensingEfficiency(CosmologicalGrid.ZArray[idx_ZArray],
idx_ZBinArray, ConvolvedDensity, AnalitycalDensity,
InstrumentResponse, Cosmology, CosmologicalGrid,
LensingSourceFunction)
end
end
end
"""
ComputeLensingEfficiencyGrid!(
LensingFunction::WLWeightFunction, ConvolvedDensity::AbstractConvolvedDensity,
CosmologicalGrid::CosmologicalGrid, BackgroundQuantities::BackgroundQuantities,
w0waCDMCosmology::w0waCDMCosmology, ::CustomLensingEfficiency)
This function evaluates the Lensing Efficiency over the ``z`` grid and for all tomographic
bins ``i``.
"""
function ComputeLensingEfficiencyGrid!(
LensingFunction::WLWeightFunction,
ConvolvedDensity::AbstractConvolvedDensity,
CosmologicalGrid::CosmologicalGrid,
BackgroundQuantities::BackgroundQuantities,
Cosmology::AbstractCosmology,
::CustomLensingEfficiency)
LensingFunction.LensingEfficiencyArray .*= 0
Weight_Matrix = SimpsonWeightMatrix(length(CosmologicalGrid.ZArray))
@avx for idx_ZBinArray in 1:length(ConvolvedDensity.ZBinArray)-1
for idx_ZArray in 1:length(CosmologicalGrid.ZArray)
for idx_ZArrayInt in 1:length(CosmologicalGrid.ZArray)
LensingFunction.LensingEfficiencyArray[idx_ZBinArray,
idx_ZArray] += ConvolvedDensity.DensityGridArray[idx_ZBinArray,
idx_ZArrayInt] * (BackgroundQuantities.χZArray[idx_ZArrayInt] -
BackgroundQuantities.χZArray[idx_ZArray]) /
BackgroundQuantities.χZArray[idx_ZArrayInt] /
BackgroundQuantities.χZArray[idx_ZArray] *
Weight_Matrix[idx_ZArray, idx_ZArrayInt]
end
end
end
LensingFunction.LensingEfficiencyArray .*=
(last(CosmologicalGrid.ZArray)-first(CosmologicalGrid.ZArray))/
(length(CosmologicalGrid.ZArray)-1)
end
"""
ComputeWeightFunction(z::Float64, i::Int64,ConvolvedDensity::AbstractConvolvedDensity,
AnalitycalDensity::AnalitycalDensity, InstrumentResponse::InstrumentResponse,
Cosmology::AbstractCosmology, CosmologicalGrid::CosmologicalGrid,
LensingFunction::WLWeightFunction)
This function returns the Weak Lensing Weight Function, for a given redshift
``z`` and tomographic bin ``i``.
"""
function ComputeWeightFunction(z::T, i::I,
ConvolvedDensity::AbstractConvolvedDensity, AnalitycalDensity::AnalitycalDensity,
InstrumentResponse::InstrumentResponse, Cosmology::AbstractCosmology,
CosmologicalGrid::CosmologicalGrid, LensingFunction::WLWeightFunction) where {T,I}
c_0 = 2.99792458e5 #TODO: find a package containing the exact value of
#physical constants involved in calculations
return 1.5 * ComputeLensingEfficiency(z, i, ConvolvedDensity,
AnalitycalDensity,InstrumentResponse, Cosmology, CosmologicalGrid,
LensingFunction) * (Cosmology.H0/c_0)^2 * Cosmology.ΩM *
(1. + z) * Computeχ(z, Cosmology)^2
end
"""
ComputeWeightFunctionGrid!(LensingFunction::WLWeightFunction,
ConvolvedDensity::AbstractConvolvedDensity, CosmologicalGrid::CosmologicalGrid,
BackgroundQuantities::BackgroundQuantities, Cosmology::AbstractCosmology)
This function evaluates the Weak Lensing Weight Function over the ``z``
grid and for all tomographic bins ``i``.
"""
function ComputeWeightFunctionGrid!(
LensingFunction::WLWeightFunction,
ConvolvedDensity::AbstractConvolvedDensity,
CosmologicalGrid::CosmologicalGrid,
BackgroundQuantities::BackgroundQuantities,
Cosmology::AbstractCosmology)
c_0 = 2.99792458e5 #TODO: find a package containing the exact value of
#physical constants involved in calculations
for idx_ZBinArray in 1:length(ConvolvedDensity.ZBinArray)-1
for idx_ZArray in 1:length(CosmologicalGrid.ZArray)
LensingFunction.WeightFunctionArray[idx_ZBinArray, idx_ZArray] =
1.5 * (Cosmology.H0/c_0)^2 * Cosmology.ΩM *
(1. + CosmologicalGrid.ZArray[idx_ZArray]) *
BackgroundQuantities.χZArray[idx_ZArray]^2 *
LensingFunction.LensingEfficiencyArray[idx_ZBinArray, idx_ZArray] +
LensingFunction.IntrinsicAlignmentArray[idx_ZBinArray, idx_ZArray]
end
end
end
function CreateAndEvaluateWeightFunction(probe::WLProbe, cosmogrid::CosmologicalGrid,
background::BackgroundQuantities, cosmo::AbstractCosmology)
weightfunction = WLWeightFunction()
weightfunction.LensingEfficiencyArray = zeros(
length(probe.Density.DensityGridArray[:,1]), length(cosmogrid.ZArray))
weightfunction.IntrinsicAlignmentArray = zeros(size(weightfunction.LensingEfficiencyArray))
weightfunction.WeightFunctionArray = zeros(size(weightfunction.LensingEfficiencyArray))
weightfunction.IntrinsicAlignmentModel = probe.IAModel
ComputeLensingEfficiencyGrid!(weightfunction, probe.Density, cosmogrid, background,
cosmo, CustomLensingEfficiency())
ComputeIntrinsicAlignmentGrid!(cosmogrid, weightfunction, probe.Density, background,
cosmo)
ComputeWeightFunctionGrid!(weightfunction, probe.Density, cosmogrid, background, cosmo)
return weightfunction
end
function CreateAndEvaluateWeightFunction(probe::GCProbe, cosmogrid::CosmologicalGrid,
background::BackgroundQuantities, cosmo::AbstractCosmology)
weightfunction = GCWeightFunction()
weightfunction.WeightFunctionArray = zeros(
length(probe.Density.DensityGridArray[:,1]), length(cosmogrid.ZArray))
weightfunction.BiasArray = zeros(size(weightfunction.WeightFunctionArray))
weightfunction.BiasKind = probe.BiasModel
ComputeBiasGrid!(cosmogrid, weightfunction, probe.Density)
ComputeWeightFunctionGrid!(weightfunction, probe.Density, cosmogrid, background, cosmo)
return weightfunction
end