-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjointPDF_Nd.jl
More file actions
155 lines (125 loc) · 5.41 KB
/
jointPDF_Nd.jl
File metadata and controls
155 lines (125 loc) · 5.41 KB
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
#================================================
Joint PDF
================================================#
include("../plots_setup_Nd.jl")
# Create the figure
fig = Figure(resolution=(1200, 700))
use_GLMakie && display(fig)
Nd_bounds = (0.0, 40.0)
εNd_bounds = (-20.0, 5.0)
tracer_names = ("[Nd]", "εNd")
labels = ("(a)", "(b)")
cmap = cgrad(:oslo, 10, categorical=true, rev=true)
cmap2 = cgrad(cmap[2:end], categorical=true) # to skip the white color to leave the grid behind (prettier)
function myjointpdf!(fig)
axs = Array{Any}(undef, 2)
cos = []
for (itracer, (xmodel, xobs, ux, boundary, tracer_name, label)) in enumerate(zip((DNdmodel, εNdmodel), (DNdobs, εNdobs), (uDNd, uεNd), (Nd_bounds, εNd_bounds), tracer_names, labels))
xmodelatobs, xdepthatobs, iobswet, xwetobs = _locations(xmodel, xobs, ux)
#@show size.([xwetobs, xmodelatobs])
x, y = ustrip.(xwetobs), ustrip.(xmodelatobs)
bw = (boundary[2]-boundary[1])/150
D = kde((x, y); boundary=(boundary, boundary), bandwidth=(bw,bw))
# calculate cumulative density from density
δx = step(D.x)
δy = step(D.y)
Q = vec(D.density) * δx * δy
idx = sortperm(Q)
Q_sorted = Q[idx]
Dcum = similar(D.density)
Dcum[idx] .= 100cumsum(Q_sorted)
ax = fig[1, itracer] = Axis(fig, aspect = AxisAspect(1))
co = Makie.contourf!(ax, D.x, D.y, Dcum, levels=10:10:100, colormap=cmap2)
lines!(ax, collect(boundary), collect(boundary), linestyle=:dash, color=:black)
#scatter!(ax, x, y, markersize=1)
Makie.xlims!(ax, boundary)
Makie.ylims!(ax, boundary)
ax.xlabel = "Observed " * tracer_name * " ($ux)"
ax.ylabel = "Modelled " * tracer_name * " ($ux)"
# Add label
Label(fig, bbox = ax.scene.px_area, label, fontsize=20, halign=:left, valign=:top, padding=(10,10,5,5), font=labelfont, color=:black)
# Root mean square error
RMSE = sqrt(mean((x - y).^2))
Label(fig, bbox = ax.scene.px_area, sprintf1("RMSE = %.2f $ux", RMSE), fontsize=15, halign=:right, valign=:bottom, padding=(10,10,10,10), font=labelfont, color=:black)
push!(axs, ax)
push!(cos, co)
end
axs
# colorbar
cbar = fig[2, 1:2] = Colorbar(fig, #cos[1],
colormap=cmap, ticks = 0:10:100, limits=(0,100),
label="Percentile", vertical=false, flipaxis=false, ticklabelalign = (:center, :top))
cbar.width = Relative(2/4)
cbar.height = 30
cbar.tellheight = true
# make top plots square
sublayout = GridLayout()
fig[1, 1:2] = sublayout
rowsize!(sublayout, 1, Aspect(1,1))
fig
end
# Create the plot
myjointpdf!(fig)
if use_GLMakie
fig # show the output wiht GLMakie
else
save(joinpath(archive_path, "jointPDF_$(lastcommit)_run$(run_num).pdf"), fig)
nothing # just so that no output is spat out
end
function myjointpdf2!(fig)
axs = Array{Any}(undef, 2)
cos = []
for (itracer, (xmodel, xobs, ux, boundary, tracer_name, label)) in enumerate(zip((DNdmodel, εNdmodel), (DNdobs, εNdobs), (uDNd, uεNd), (Nd_bounds, εNd_bounds), tracer_names, labels))
xmodelatobs, xdepthatobs, iobswet, xwetobs = _locations(xmodel, xobs, ux)
#@show size.([xwetobs, xmodelatobs])
x, y = ustrip.(xwetobs), ustrip.(xmodelatobs)
bw = (boundary[2]-boundary[1])/150
D = kde((x, y); boundary=(boundary, boundary), bandwidth=(bw,bw))
# calculate cumulative density from density
δx = step(D.x)
δy = step(D.y)
Q = vec(D.density) * δx * δy
idx = sortperm(Q)
Q_sorted = Q[idx]
Dcum = similar(D.density)
Dcum[idx] .= 100cumsum(Q_sorted)
ax = fig[itracer, 1] = Axis(fig, aspect = AxisAspect(1))
co = Makie.contourf!(ax, D.x, D.y, Dcum, levels=10:10:100, colormap=cmap2)
lines!(ax, collect(boundary), collect(boundary), linestyle=:dash, color=:black)
#scatter!(ax, x, y, markersize=1)
Makie.xlims!(ax, boundary)
Makie.ylims!(ax, boundary)
ax.xlabel = "Observed " * tracer_name * " ($ux)"
ax.ylabel = "Modelled " * tracer_name * " ($ux)"
# Add label
Label(fig, bbox = ax.scene.px_area, label, fontsize=20, halign=:left, valign=:top, padding=(10,10,5,5), font=labelfont, color=:black)
# Root mean square error
RMSE = sqrt(mean((x - y).^2))
Label(fig, bbox = ax.scene.px_area, sprintf1("RMSE = %.2f $ux", RMSE), fontsize=15, halign=:right, valign=:bottom, padding=(10,10,10,10), font=labelfont, color=:black)
push!(axs, ax)
push!(cos, co)
end
axs
# colorbar
cbar = fig[3, 1] = Colorbar(fig, #cos[1],
colormap=cmap, ticks = 0:10:100, limits=(0,100),
label="Percentile", vertical=false, flipaxis=false, ticklabelalign = (:center, :top))
cbar.width = Relative(3/4)
cbar.height = 30
cbar.tellheight = true
# make top plots square
sublayout = GridLayout()
fig[1:2, 1] = sublayout
colsize!(sublayout, 1, Aspect(1,1))
fig
end
# Create the plot
fig = Figure(resolution=(450, 1000))
use_GLMakie && display(fig)
myjointpdf2!(fig)
if use_GLMakie
display(fig) # show the output wiht GLMakie
else
save(joinpath(archive_path, "jointPDF_vertical_$(lastcommit)_run$(run_num).pdf"), fig)
nothing # just so that no output is spat out
end