-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNAVobservational.wl
296 lines (228 loc) · 9.68 KB
/
NAVobservational.wl
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
(* ::Package:: *)
(* ::Chapter:: *)
(*Observational NAV *)
(* ::Text:: *)
(*To generate the plots, uncomment the proper lines below.*)
(* ::Section:: *)
(*I.1. Plots for Kernel Density Estimation for the distribution*)
Print["Starting NAVobservational..."];
Clear[plotBlueZero, statusKDE];
exportPlotObservational[fileName_, plotToExport_] := If[Global`saveNAVobservationalPlots,
Block[{fileNameWithPath},
fileNameWithPath = FileNameJoin[{pathOutputDirectory, ToString @ fileName}];
Export[fileNameWithPath, plotToExport];
Echo[fileNameWithPath, "Exported"]
]
];
exportTableObservational[fileName_, plotToExport_] := If[Global`saveNAVobservationalTables,
Block[{fileNameWithPath},
fileNameWithPath = FileNameJoin[{pathOutputDirectory, ToString @ fileName}];
Export[fileNameWithPath, plotToExport];
Echo[fileNameWithPath, "Exported"]
]
];
plotBlueZero[dataForKDE_, opts:OptionsPattern[]] := nListPlot[
{dataForKDE},
PlotMarkers -> {
Graphics[{Darker[Blue],Opacity[0.05],Disk[]}, ImageSize -> 10],
Graphics[{Darker[Red],Opacity[0.3],Disk[]}, ImageSize -> 10]
},
opts,
PlotRange -> {{0,1}, All},
AspectRatio -> 1
];
statusKDE[dataForKDE_, {{xmin_, xmax_}, {ymin_, ymax_}}]:= Block[{},
Echo[silvermanBw[dataForKDE],
"Gaussian bandwidths from Silverman rule of thumb: "
];
Print@GraphicsRow[
{
plotBlueZero[dataForKDE],
ContourPlot[PDF[distributionSilverman[dataForKDE], {x, y}], {x, xmin, xmax}, {y, ymin, ymax}]
}
]
];
(* SPECIFIC DEFINITIONS *)
Clear[gdRList, gdRListFlat];
gdRList[gdFunction_] := gdRList[gdFunction] = gdFunction[{nRad, \[Delta]Vms}][[#]] & /@ Range[175];
gdRListFlat[gdFunction_] := Flatten[gdRList[gdFunction], 1];
EchoTiming[
list2RARRot = gdRListFlat @ gdR;
list2RARRotNoBulge = gdRListFlat @ gdRBulgeless; , "list2RARRot"
];
(*EXECUTION*)
EchoTiming[
distRARRot = distributionSilverman[list2RARRot];
distRARRotNoBulge = distributionSilverman[list2RARRotNoBulge]; , "distRAR"
];
(*Echo["All RAR galaxies case:"];
statusKDE[list2RARRot, {{0, 1}, {-0.5, 1.5}}];
Echo["Only the bulgeless RAR galaxies:"];
statusKDE[list2RARRotNoBulge, {{-0.01,1}, {-0.5, 1.5}}];*)
(* ::Section:: *)
(*I.2. plotBlue and the 1\[Sigma] and 2\[Sigma] Highest Density Regions*)
plotBlue[dataForBluePlot_, limitingPdfValeus_, {{xmin_, xmax_}, {ymin_, ymax_}}, options___] := Show[
plotBlueZero[dataForBluePlot, options],
plotSigmaContours[dataForBluePlot, limitingPdfValeus, {{xmin, xmax}, {ymin, ymax}}, PlotRange -> All]
];
(* SPECIFIC DEFINITIONS *)
ymin = -1.5;
ymax = 2.5;
xmin= 0;
xmax = 1;
xstep = 0.005;
ystep = 0.005;
oneAndTwoSigma = {oneSigmaProbability, twoSigmaProbability};
list1Limits = FindHDPDFValues[distRARRot, oneAndTwoSigma];
list1LimitsNoBulge = FindHDPDFValues[distRARRotNoBulge, oneAndTwoSigma];
plotBlueFunction = plotBlue[Sequence@@#, {{xmin, xmax - 0.001}, {-0.5, 1.5}}, PlotRange -> {{0, 1}, {-1, 2}}] & ;
(* EXECUTION *)
EchoTiming[
{plotBlueRAR, plotBlueRARNoBulge} = plotBlueFunction /@ {{list2RARRot, list1Limits}, {list2RARRotNoBulge, list1LimitsNoBulge}}; , "plotBlueRAR"
];
Clear[plotObsSigma];
plotObsSigma[n_] := plotObsSigma[n] = Block[{pdfValue},
pdfValue = FindHDPDFValues[distRARRotNoBulge, nSigmaProbability[n]];
ContourPlot[
PDF[distRARRotNoBulge, {x,y}] == pdfValue,
{x, 0, 1}, {y, -0.5, 2.5},
PerformanceGoal -> "Quality"
]
];
exportPlotObservational["plotBlueRAR.pdf", plotBlueRAR];
exportPlotObservational["plotBlueRARNoBulge.pdf", plotBlueRARNoBulge];
(* ::Text::GrayLevel[0]::Bold::Closed:: *)
(*Cell group comment: *)
(*Considers the removal of Vobs data points with uncertainty larger than 10%.*)
(*Conclusion: no relevant impact and adds complications*)
(* ::Text:: *)
(*Case with Bulge:*)
(* ::Input:: *)
(*Clear[gdRListVel, gdRListVelFlat]*)
(*gdRListVel[gdFunction_] := gdRListVel[gdFunction] = gdFunction[{nRad, \[Delta]Vms, Vobs, \[Delta]Vobs}][[#]] & /@ Range[175];*)
(*gdRListVelFlat[gdFunction_] := Flatten[gdRListVel[gdFunction], 1];*)
(**)
(*list2RARRotVelAux = Select[gdRListVelFlat[gdR], #[[4]]/#[[3]] < 0.1 &] ; (*Includes only the velocity points with uncertainty lower than 10% of Vobs*)*)
(*list2RARRotVel = Drop[list2RARRotVelAux\[Transpose], -2]\[Transpose]; (*Removes the columns on Vobs and \[Delta]Vobs*)*)
(**)
(*distRARRotVel = distributionSilverman[list2RARRotVel];*)
(**)
(*list1LimitsVel = FindHDPDFValues[distRARRotVel, oneAndTwoSigma];*)
(**)
(*plotBlueRARVel = plotBlueFunction[{list2RARRotVel, list1LimitsVel}] ; *)
(*Show[plotBlueRARVel, plotBlueRAR]*)
(* ::Text:: *)
(*Case without Bulge*)
(* ::Input:: *)
(**)
(*list2RARRotVelAuxNoBulge = Select[gdRListVelFlat[gdRBulgeless], #[[4]]/#[[3]] < 0.1 &] ; (*Includes only the velocity points with uncertainty lower than 10% of Vobs*)*)
(*list2RARRotVelNoBulge = Drop[list2RARRotVelAuxNoBulge\[Transpose], -2]\[Transpose]; (*Removes the columns on Vobs and \[Delta]Vobs*)*)
(**)
(*distRARRotVelNoBulge = distributionSilverman[list2RARRotVelNoBulge];*)
(**)
(*list1LimitsVelNoBulge = FindHDPDFValues[distRARRotVelNoBulge, oneAndTwoSigma];*)
(**)
(*plotBlueRARVelNoBulge = plotBlueFunction[{list2RARRotVelNoBulge, list1LimitsVelNoBulge}] ; *)
(*Show[plotBlueRARVelNoBulge, plotBlueRARNoBulge]*)
(* ::Text:: *)
(*The plot below shows that the excluded points most dense region is close to the galaxy center (as expectected, since there the observational velocity is typically close to zero, while the Vobs errors do not go to zero).*)
(* ::Input:: *)
(*ListPlot[{ list2RARRot, list2RARRotVel}, PlotStyle-> {Blue, Red}]*)
(* ::Text:: *)
(*The main differences appear in the lower bounds of the 1\[Sigma] and 2\[Sigma] regions, which get raised, in particular at Subscript[r, n]<0.2. The overall impact for our results is negligible. Since most of the excluded data points are close to the galactic center, in the bulgeless case the 1\[Sigma] upper and lower limits get connected, which adds a nonnecessary computational complication and such case is artificial, since it depends on the choice of the 10% rejection limit). *)
Clear[list1InterpSigmaCurves, plotSigmaRegions];
list1InterpSigmaCurves::usage = "list1InterpSigmaCurves[blueplot] provides a list of 4 interpolated curves in the following order:"<>
"{1\[Sigma]LowerLimit, 1\[Sigma]UpperLimit, 2\[Sigma]LowerLimit, 2\[Sigma]UpperLimit}. /n"<>
"The plot to be provided (blueplot) can be generated by the function plotBlue.";
list1InterpSigmaCurves[plotblue_] := Block[
{
sigmaContoursList,
curveSigma,
curveOrder,
curve2SigmaNeg,
curve1SigmaNeg,
curve1SigmaPlus,
curve2SigmaPlus
},
sigmaContoursList = Cases[
Normal @ FullForm @ First @ plotblue,
Line[pts_] :> pts,
Infinity
];
curveSigma[n_] := Interpolation[
Sort@sigmaContoursList[[n]],
Method -> "Spline",
InterpolationOrder-> 2
];
curveOrder = Ordering @ Table[curveSigma[n][0.5], {n, 1, 4}];
curve2SigmaNeg = curveSigma[curveOrder[[1]]];
curve1SigmaNeg = curveSigma[curveOrder[[2]]];
curve1SigmaPlus = curveSigma[curveOrder[[3]]];
curve2SigmaPlus = curveSigma[curveOrder[[4]]];
{
curve1SigmaNeg,
curve1SigmaPlus,
curve2SigmaNeg,
curve2SigmaPlus
}
];
plotSigmaRegions::usage =
"plotSigmaRegions[curvesSigma, xLimit1, xLimit2] yields a plot with the 1 and 2 sigma regions from xLimit1 to xLmit2. \n" <>
"The standard values of xLimit1 and xLimit2 are 0.2 and 0.9. \n" <>
"The input to be provided, curvesSigma, can be generated by list1InterpSigmaCurves.";
plotSigmaRegions[curvesSigma_, xLimit1_:0.01, xLimit2_:0.99] := Plot[
{
curvesSigma[[3]][r],
curvesSigma[[1]][r],
curvesSigma[[2]][r],
curvesSigma[[4]][r]
},
{r, xLimit1, xLimit2},
Filling -> {{1 -> {3}, GrayLevel[0.7]}, {2 -> {4}}},
PlotStyle -> {{Thickness[0.002], Gray}, {Thickness @ 0.002, Gray}},
FillingStyle -> {GrayLevel[0.7], Opacity @ 0.05}
];
(*EXECUTION*)
EchoTiming[
{plotSigmaRegionsRAR, plotSigmaRegionsRARNoBulge} = plotSigmaRegions[list1InterpSigmaCurves[#]] & /@ {plotBlueRAR, plotBlueRARNoBulge};, "plotSigmaRegions"
];
plotBackground[upperLimit_] := nPlot[
100,
{rn, 0, 1},
PlotRange -> {{0, 1}, {-0.25, upperLimit}},
AspectRatio -> (1 / 1.3),
GridLines -> None,
Prolog -> {
Dotted,
Line @ {{0, 0}, {1, 0}},
Gray,
Opacity[0.2],
Rectangle[{0.001, -0.5},{0.2, upperLimit}],
Rectangle[{0.9, -0.5},{0.999, upperLimit}]
}
];
(*GraphicsRow[
{plotSigmaRegionsRAR, plotSigmaRegionsRARNoBulge},
ImageSize \[Rule] 800
]*)
(* ::Subsection:: *)
(*I.2.1. Exporting the \[Sigma] regions into a almost-paper-ready table (uncomment to export the files)*)
Clear[exportSigmaList];
exportSigmaList::usage = "curvesSigmaList[listOfCurves, rnMin, rnMax, step] generates 1\[Sigma] and 2\[Sigma] limiting curves in a close-to-paper-ready formated table, /n"<>
"with rMin < r < rMax, in steps provided by step (optional, 0.02 being standard). The listOfCurves can be generated by list1InterpSigmaCurves./n"<>
"exportSigmaList does not exports any file, but prepares the list to be exported.";
exportSigmaList[list1IpSigmaCurves_, rnMin_, rnMax_, step_:0.025] := Block[
{header, tab, rn, nF, tabAux},
header = {"# rn", "1\[Sigma]Lower", "1\[Sigma]Upper", "2\[Sigma]Lower", "2\[Sigma]Upper"};
nF := NumberForm[#, {4, 3}] &;
tabAux = Table[list1IpSigmaCurves[[n]]@rn, {n, 4}];
tab = Table[
nF /@ Flatten[{rn, tabAux}],
{rn, rnMin, rnMax, step}
];
Join[{header}, tab]
];
list1InterpCurvesRAR = list1InterpSigmaCurves[plotBlueRAR];
list1InterpCurvesRARNoBulge = list1InterpSigmaCurves[plotBlueRARNoBulge];
exportTableObservational["sigmaRegionsRAR.csv", exportSigmaList[list1InterpCurvesRAR, 0.025, 1]];
exportTableObservational["sigmaRegionsRARNoBulge.csv", exportSigmaList[list1InterpCurvesRARNoBulge, 0.025, 1]];