Skip to content

Commit

Permalink
Add Pluto notebook to explore the output data
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
giordano committed May 25, 2021
1 parent 54fe391 commit 247c6a0
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 11 deletions.
33 changes: 22 additions & 11 deletions extra/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ version = "0.12.8"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "0a817fbe51c976de090aa8c997b7b719b786118d"
git-tree-sha1 = "e4e2b39db08f967cc1360951f01e8a75ec441cab"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.28.0"
version = "3.30.0"

[[CompilerSupportLibraries_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
Expand Down Expand Up @@ -206,9 +206,9 @@ version = "1.0.2"

[[HDF5]]
deps = ["Blosc", "Compat", "HDF5_jll", "Libdl", "Mmap", "Random", "Requires"]
git-tree-sha1 = "8a21f34a34491833bcda29a3ec2188b4ec6e558f"
git-tree-sha1 = "1d18a48a037b14052ca462ea9d05dee3ac607d23"
uuid = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
version = "0.15.4"
version = "0.15.5"

[[HDF5_jll]]
deps = ["Artifacts", "JLLWrappers", "LibCURL_jll", "Libdl", "OpenSSL_jll", "Pkg", "Zlib_jll"]
Expand All @@ -218,9 +218,9 @@ version = "1.12.0+1"

[[HTTP]]
deps = ["Base64", "Dates", "IniFile", "MbedTLS", "NetworkOptions", "Sockets", "URIs"]
git-tree-sha1 = "b855bf8247d6e946c75bb30f593bfe7fe591058d"
git-tree-sha1 = "1fd26bc48f96adcdd8823f7fc300053faf3d7ba1"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "0.9.8"
version = "0.9.9"

[[IniFile]]
deps = ["Test"]
Expand Down Expand Up @@ -474,9 +474,15 @@ version = "1.0.10"

[[Plots]]
deps = ["Base64", "Contour", "Dates", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "JSON", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"]
git-tree-sha1 = "2628e5859819173cef995470af83db42bf411ef8"
git-tree-sha1 = "f3a57a5acc16a69c03539b3684354cbbbb72c9ad"
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
version = "1.14.0"
version = "1.15.2"

[[PlutoUI]]
deps = ["Base64", "Dates", "InteractiveUtils", "JSON", "Logging", "Markdown", "Random", "Reexport", "Suppressor"]
git-tree-sha1 = "44e225d5837e2a2345e69a1d1e01ac2443ff9fcb"
uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
version = "0.7.9"

[[Preferences]]
deps = ["TOML"]
Expand Down Expand Up @@ -561,9 +567,9 @@ uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[StaticArrays]]
deps = ["LinearAlgebra", "Random", "Statistics"]
git-tree-sha1 = "fb46e45ef2cade8be20bb445b3ffeca3c6d6f7d3"
git-tree-sha1 = "a1f226ebe197578c25fcf948bfff3d0d12f2ff20"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.1.3"
version = "1.2.1"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
Expand All @@ -586,6 +592,11 @@ git-tree-sha1 = "44b3afd37b17422a62aea25f04c1f7e09ce6b07f"
uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
version = "0.5.1"

[[Suppressor]]
git-tree-sha1 = "a819d77f31f83e5792a76081eee1ea6342ab8787"
uuid = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
version = "0.2.0"

[[TOML]]
deps = ["Dates"]
git-tree-sha1 = "44aaac2d2aec4a850302f9aa69127c74f0c3787e"
Expand Down Expand Up @@ -651,7 +662,7 @@ uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a"
version = "2.9.10+3"

[[XSLT_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Pkg", "XML2_jll"]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "2b3eac39df218762d2d005702d601cd44c997497"
uuid = "aed1982a-8fda-507f-9586-7b0439959a61"
version = "1.1.33+4"
Expand Down
183 changes: 183 additions & 0 deletions extra/Plot_output_pluto.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
### A Pluto.jl notebook ###
# v0.14.5

using Markdown
using InteractiveUtils

# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
global $(esc(def)) = Core.applicable(Base.get, el) ? Base.get(el) : missing
el
end
end

# ╔═╡ c7383ff4-ba4c-11eb-1977-b31b330b20d0
begin
import Pkg
Pkg.activate(@__DIR__)
Pkg.instantiate()
using Plots
using HDF5
using Unitful
using UnitfulRecipes
using PlutoUI
end

# ╔═╡ 3e85f1c4-32ca-4e8e-ab9f-2fefaaabffb7
md"## Load HDF5 output file"

# ╔═╡ 72c703c9-3c32-45ab-b910-25a3c6652bdc
filename = "particle_da.h5"

# ╔═╡ 7cbbad5a-3767-422c-9d6b-f32524d4bf04
fh = h5open(filename, "r")

# ╔═╡ 7c316637-defe-4f60-a7e5-2e10511f7044
md"## Set these parameters to choose what to plot"

# ╔═╡ e1acfe11-0ead-4ada-946e-eff674e6d44e
begin
timestamps = keys(fh["data_syn"])
md"""
Select the timestamp
$(@bind timestamp_idx Slider(1:length(timestamps)))
"""
end

# ╔═╡ 775fbb1e-a760-4862-829d-455051942255
timestamp = timestamps[timestamp_idx]

# ╔═╡ d442ef52-1566-484d-af31-ba3565307502
md"""
Select the field
$(@bind field Select([f => f for f in keys(fh["data_syn"]["t0000"])]))
"""

# ╔═╡ 384116c1-ed19-4a8c-85a7-6c0dfd9c164f
md"## Contour plots of surface height"

# ╔═╡ 8f67e2b3-9a01-42a3-a56a-11b84776a5e1
md"## Scatter plot of particle weights"

# ╔═╡ a35f5895-5066-4e1d-b252-6172888aa92d
begin
weights = read(fh["weights"][timestamp])

p1 = scatter(weights, marker=:star)
p2 = scatter(weights, marker=:star, yscale=:log10)

for plt in (p1, p2)
plot!(plt; xlabel="Particle ID", ylabel="Weight")
end

plot(p1, p2, label="")
end

# ╔═╡ e5335e14-bdb6-432c-94ab-c666c304efc6
md"## Time series of Estimated Sample Size"

# ╔═╡ 343a1d50-38f8-4457-81dc-5d962a2acb4a
plot([1 / sum(read(w) .^ 2) for w in fh["weights"]];
label="", marker=:o, xlabel="Time step", ylabel="Estimated Sample Size (1 / sum(weight^2))")

# ╔═╡ a52a3f7e-1d8e-4153-b0c2-2cb47584c447
md"## Animation"

# ╔═╡ 8520dcbb-0bd8-4020-aea3-009e24df2099
md"## Collect data from the output file"

# ╔═╡ cff1a64f-03ba-4150-9501-fa4803901808
# All time-independent quantities
begin
field_unit = read(fh["data_syn"]["t0000"][field]["Unit"])
var_unit = read(fh["data_var"]["t0000"][field]["Unit"])

field_desc = read(fh["data_syn"]["t0000"][field]["Description"])

x_unit = read(fh["grid"]["x"]["Unit"])
y_unit = read(fh["grid"]["y"]["Unit"])
x_st_unit = read(fh["stations"]["x"]["Unit"])
y_st_unit = read(fh["stations"]["y"]["Unit"])

x = read(fh["grid"]["x"]) .* uparse(x_unit) .|> u"km"
y = read(fh["grid"]["y"]) .* uparse(y_unit) .|> u"km"

x_st = read(fh["stations"]["x"]) .* uparse(x_st_unit) .|> u"km"
y_st = read(fh["stations"]["y"]) .* uparse(y_st_unit) .|> u"km"
end

# ╔═╡ e17da3a7-39e4-4326-aa2e-08f70b574878
function plot_data(x, y, z_t, z_avg, z_std, field_desc)
n_contours = 100
zmax = max(maximum(z_t), maximum(z_avg))
zmin = min(minimum(z_t), minimum(z_avg))
levels = range(zmin, zmax; length=n_contours)

# Note that for heatmaps we need to permute the dimensions of the z matrix
p1 = heatmap(x, y, z_t'; title="True $(lowercase(field_desc))")
p2 = heatmap(x, y, z_avg'; title="Assimilated $(lowercase(field_desc))")
p3 = heatmap(x, y, z_std'; title="Std of assimilated $(lowercase(field_desc))")

for (i, plt) in enumerate((p1, p2, p3))
# Set labels
plot!(plt; xlabel="x", ylabel="y")
# Set range of color bar for first two plots
i (1, 2) && plot!(plt; clims=(ustrip(zmin), ustrip(zmax)))
# Add the positions of the stations
scatter!(plt, x_st, y_st, color=:red, marker=:star, label="")
end

plot(p1, p2, p3; titlefontsize=8, guidefontsize=8)
end

# ╔═╡ ba33b9a1-7d73-4247-b298-ccf30acc8859
function animate_data(fh, field, field_unit, var_unit, x, y)
animation = @animate for timestamp keys(fh["data_syn"])
z_t = read(fh["data_syn"][timestamp][field]) .* uparse(field_unit)
z_avg = read(fh["data_avg"][timestamp][field]) .* uparse(field_unit)
z_std = sqrt.(read(fh["data_var"][timestamp][field]) .* uparse(var_unit))

plot_data(x, y, z_t, z_avg, z_std, field_desc)
end

return mp4(animation, "animation_jl.mp4"; fps=5)
end

# ╔═╡ a9343779-de40-4d33-8487-27d53ec095c0
animate_data(fh, field, field_unit, var_unit, x, y)

# ╔═╡ da1315e0-71de-4df6-9d74-259979571e1e
# Quantities specific to the current timestamp
begin
z_t = read(fh["data_syn"][timestamp][field]) .* uparse(field_unit)
z_avg = read(fh["data_avg"][timestamp][field]) .* uparse(field_unit)
z_std = sqrt.(read(fh["data_var"][timestamp][field]) .* uparse(var_unit))
end

# ╔═╡ 1d230245-5f29-4895-b0cb-4e49f6c125ff
plot_data(x, y, z_t, z_avg, z_std, field_desc)

# ╔═╡ Cell order:
# ╠═c7383ff4-ba4c-11eb-1977-b31b330b20d0
# ╟─3e85f1c4-32ca-4e8e-ab9f-2fefaaabffb7
# ╠═72c703c9-3c32-45ab-b910-25a3c6652bdc
# ╟─7cbbad5a-3767-422c-9d6b-f32524d4bf04
# ╟─7c316637-defe-4f60-a7e5-2e10511f7044
# ╟─e1acfe11-0ead-4ada-946e-eff674e6d44e
# ╟─775fbb1e-a760-4862-829d-455051942255
# ╟─d442ef52-1566-484d-af31-ba3565307502
# ╟─384116c1-ed19-4a8c-85a7-6c0dfd9c164f
# ╟─e17da3a7-39e4-4326-aa2e-08f70b574878
# ╟─1d230245-5f29-4895-b0cb-4e49f6c125ff
# ╟─8f67e2b3-9a01-42a3-a56a-11b84776a5e1
# ╟─a35f5895-5066-4e1d-b252-6172888aa92d
# ╟─e5335e14-bdb6-432c-94ab-c666c304efc6
# ╟─343a1d50-38f8-4457-81dc-5d962a2acb4a
# ╟─a52a3f7e-1d8e-4153-b0c2-2cb47584c447
# ╟─ba33b9a1-7d73-4247-b298-ccf30acc8859
# ╟─a9343779-de40-4d33-8487-27d53ec095c0
# ╟─8520dcbb-0bd8-4020-aea3-009e24df2099
# ╟─cff1a64f-03ba-4150-9501-fa4803901808
# ╟─da1315e0-71de-4df6-9d74-259979571e1e
1 change: 1 addition & 0 deletions extra/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulRecipes = "42071c24-d89e-48dd-8a24-8a12d9b8861f"

Expand Down

0 comments on commit 247c6a0

Please sign in to comment.