From f12f23f3c420febda583da37c9e04615e6a18e5c Mon Sep 17 00:00:00 2001 From: Aaron Kaw Date: Wed, 21 Aug 2024 01:15:47 +1000 Subject: [PATCH] Added sound speed profile visualisation --- .gitignore | 4 +- Manifest.toml | 2 +- Project.toml | 7 + docs/Manifest.toml | 297 ------------------ docs/Project.toml | 1 + .../01_ocean/01_sound_speed.md | 5 - .../01_ocean/01_sound_speed_profiles.md | 16 + docs/src/99_postamble/01_implementation.md | 29 ++ ext/OceanSonarMakieExt/00_preamble.jl | 14 + .../01_oceanography/sound_speed/01_recipe.jl | 8 + .../sound_speed/02_conversions.jl | 19 ++ .../01_oceanography/sound_speed/03_visual.jl | 45 +++ ext/OceanSonarMakieExt/OceanSonarMakieExt.jl | 62 ++++ src/00_preamble/01_general/02_textstyles.jl | 3 +- src/00_preamble/02_modelling/02_types.jl | 13 +- src/00_preamble/02_modelling/04_listing.jl | 22 +- .../02_modelling/05_visualisation.jl | 47 +++ .../01_ocean/sound_speed_profiles.jl | 16 + src/OceanSonar.jl | 4 + test/00_preamble/01_auxiliary/textstyles.jl | 22 ++ test/Manifest.toml | 256 --------------- test/Project.toml | 1 + 22 files changed, 318 insertions(+), 575 deletions(-) delete mode 100644 docs/Manifest.toml delete mode 100644 docs/src/01_oceanography/01_ocean/01_sound_speed.md create mode 100644 docs/src/01_oceanography/01_ocean/01_sound_speed_profiles.md create mode 100644 ext/OceanSonarMakieExt/00_preamble.jl create mode 100644 ext/OceanSonarMakieExt/01_oceanography/sound_speed/01_recipe.jl create mode 100644 ext/OceanSonarMakieExt/01_oceanography/sound_speed/02_conversions.jl create mode 100644 ext/OceanSonarMakieExt/01_oceanography/sound_speed/03_visual.jl create mode 100644 ext/OceanSonarMakieExt/OceanSonarMakieExt.jl create mode 100644 src/00_preamble/02_modelling/05_visualisation.jl delete mode 100644 test/Manifest.toml diff --git a/.gitignore b/.gitignore index 9e4469a..dda837c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -/docs/build/ \ No newline at end of file +/docs/build/ +/docs/Manifest.toml +/test/Manifest.toml diff --git a/Manifest.toml b/Manifest.toml index 66b4696..1447635 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.11.0-rc2" manifest_format = "2.0" -project_hash = "d0c62af25f1e334dc974e47fa84a9579455bd7a6" +project_hash = "79440dfbc25e977d413e6cab950bb824887b4e5d" [[deps.Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" diff --git a/Project.toml b/Project.toml index 5aba1c1..24e0fcc 100644 --- a/Project.toml +++ b/Project.toml @@ -6,6 +6,13 @@ version = "1.0.0-DEV" [deps] InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +[weakdeps] +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" + +[extensions] +OceanSonarMakieExt = "Makie" + [compat] InteractiveUtils = "1.11.0" +Makie = "0.21.7" julia = "1.10" diff --git a/docs/Manifest.toml b/docs/Manifest.toml deleted file mode 100644 index e81245a..0000000 --- a/docs/Manifest.toml +++ /dev/null @@ -1,297 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -julia_version = "1.11.0-rc2" -manifest_format = "2.0" -project_hash = "10d3a5827e09bc1b502085b2c5f6b4d8b06d7e99" - -[[deps.ANSIColoredPrinters]] -git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c" -uuid = "a4c015fc-c6ff-483c-b24f-f7ea428134e9" -version = "0.0.1" - -[[deps.AbstractTrees]] -git-tree-sha1 = "2d9c9a55f9c93e8887ad391fbae72f8ef55e1177" -uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" -version = "0.4.5" - -[[deps.ArgTools]] -uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" -version = "1.1.2" - -[[deps.Artifacts]] -uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" -version = "1.11.0" - -[[deps.Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" -version = "1.11.0" - -[[deps.CodecZlib]] -deps = ["TranscodingStreams", "Zlib_jll"] -git-tree-sha1 = "bce6804e5e6044c6daab27bb533d1295e4a2e759" -uuid = "944b1d66-785c-5afd-91f1-9de20f533193" -version = "0.7.6" - -[[deps.Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" -version = "1.11.0" - -[[deps.DocStringExtensions]] -deps = ["LibGit2"] -git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d" -uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.9.3" - -[[deps.Documenter]] -deps = ["ANSIColoredPrinters", "AbstractTrees", "Base64", "CodecZlib", "Dates", "DocStringExtensions", "Downloads", "Git", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "MarkdownAST", "Pkg", "PrecompileTools", "REPL", "RegistryInstances", "SHA", "TOML", "Test", "Unicode"] -git-tree-sha1 = "76deb8c15f37a3853f13ea2226b8f2577652de05" -uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -version = "1.5.0" - -[[deps.Downloads]] -deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] -uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" -version = "1.6.0" - -[[deps.Expat_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl"] -git-tree-sha1 = "1c6317308b9dc757616f0b5cb379db10494443a7" -uuid = "2e619515-83b5-522b-bb60-26c02a35a201" -version = "2.6.2+0" - -[[deps.FileWatching]] -uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" -version = "1.11.0" - -[[deps.Git]] -deps = ["Git_jll"] -git-tree-sha1 = "04eff47b1354d702c3a85e8ab23d539bb7d5957e" -uuid = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2" -version = "1.3.1" - -[[deps.Git_jll]] -deps = ["Artifacts", "Expat_jll", "JLLWrappers", "LibCURL_jll", "Libdl", "Libiconv_jll", "OpenSSL_jll", "PCRE2_jll", "Zlib_jll"] -git-tree-sha1 = "d18fb8a1f3609361ebda9bf029b60fd0f120c809" -uuid = "f8c6e375-362e-5223-8a59-34ff63f689eb" -version = "2.44.0+2" - -[[deps.IOCapture]] -deps = ["Logging", "Random"] -git-tree-sha1 = "b6d6bfdd7ce25b0f9b2f6b3dd56b2673a66c8770" -uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89" -version = "0.2.5" - -[[deps.InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" -version = "1.11.0" - -[[deps.JLLWrappers]] -deps = ["Artifacts", "Preferences"] -git-tree-sha1 = "7e5d6779a1e09a36db2a7b6cff50942a0a7d0fca" -uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" -version = "1.5.0" - -[[deps.JSON]] -deps = ["Dates", "Mmap", "Parsers", "Unicode"] -git-tree-sha1 = "31e996f0a15c7b280ba9f76636b3ff9e2ae58c9a" -uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -version = "0.21.4" - -[[deps.LazilyInitializedFields]] -git-tree-sha1 = "8f7f3cabab0fd1800699663533b6d5cb3fc0e612" -uuid = "0e77f7df-68c5-4e49-93ce-4cd80f5598bf" -version = "1.2.2" - -[[deps.LibCURL]] -deps = ["LibCURL_jll", "MozillaCACerts_jll"] -uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" -version = "0.6.4" - -[[deps.LibCURL_jll]] -deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] -uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" -version = "8.6.0+0" - -[[deps.LibGit2]] -deps = ["Base64", "LibGit2_jll", "NetworkOptions", "Printf", "SHA"] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" -version = "1.11.0" - -[[deps.LibGit2_jll]] -deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll"] -uuid = "e37daf67-58a4-590a-8e99-b0245dd2ffc5" -version = "1.7.2+0" - -[[deps.LibSSH2_jll]] -deps = ["Artifacts", "Libdl", "MbedTLS_jll"] -uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" -version = "1.11.0+1" - -[[deps.Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" -version = "1.11.0" - -[[deps.Libiconv_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl"] -git-tree-sha1 = "f9557a255370125b405568f9767d6d195822a175" -uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531" -version = "1.17.0+0" - -[[deps.Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" -version = "1.11.0" - -[[deps.Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" -version = "1.11.0" - -[[deps.MarkdownAST]] -deps = ["AbstractTrees", "Markdown"] -git-tree-sha1 = "465a70f0fc7d443a00dcdc3267a497397b8a3899" -uuid = "d0879d2d-cac2-40c8-9cee-1863dc0c7391" -version = "0.1.2" - -[[deps.MbedTLS_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" -version = "2.28.6+0" - -[[deps.Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" -version = "1.11.0" - -[[deps.MozillaCACerts_jll]] -uuid = "14a3606d-f60d-562e-9121-12d972cd8159" -version = "2023.12.12" - -[[deps.NetworkOptions]] -uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" -version = "1.2.0" - -[[deps.OceanSonar]] -deps = ["AbstractTrees", "InteractiveUtils"] -path = "C:\\Users\\Aaron\\.julia\\dev\\OceanSonar" -uuid = "03019ade-4524-4ecd-af79-46d4f04a1b56" -version = "1.0.0-DEV" - -[[deps.OpenSSL_jll]] -deps = ["Artifacts", "JLLWrappers", "Libdl"] -git-tree-sha1 = "a028ee3cb5641cccc4c24e90c36b0a4f7707bdf5" -uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95" -version = "3.0.14+0" - -[[deps.PCRE2_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "efcefdf7-47ab-520b-bdef-62a2eaa19f15" -version = "10.42.0+1" - -[[deps.Parsers]] -deps = ["Dates", "PrecompileTools", "UUIDs"] -git-tree-sha1 = "8489905bcdbcfac64d1daa51ca07c0d8f0283821" -uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "2.8.1" - -[[deps.Pkg]] -deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "Random", "SHA", "TOML", "Tar", "UUIDs", "p7zip_jll"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -version = "1.11.0" -weakdeps = ["REPL"] - - [deps.Pkg.extensions] - REPLExt = "REPL" - -[[deps.PrecompileTools]] -deps = ["Preferences"] -git-tree-sha1 = "5aa36f7049a63a1528fe8f7c3f2113413ffd4e1f" -uuid = "aea7be01-6a6a-4083-8856-8a6e6704d82a" -version = "1.2.1" - -[[deps.Preferences]] -deps = ["TOML"] -git-tree-sha1 = "9306f6085165d270f7e3db02af26a400d580f5c6" -uuid = "21216c6a-2e73-6563-6e65-726566657250" -version = "1.4.3" - -[[deps.Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" -version = "1.11.0" - -[[deps.REPL]] -deps = ["InteractiveUtils", "Markdown", "Sockets", "StyledStrings", "Unicode"] -uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" -version = "1.11.0" - -[[deps.Random]] -deps = ["SHA"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -version = "1.11.0" - -[[deps.RegistryInstances]] -deps = ["LazilyInitializedFields", "Pkg", "TOML", "Tar"] -git-tree-sha1 = "ffd19052caf598b8653b99404058fce14828be51" -uuid = "2792f1a3-b283-48e8-9a74-f99dce5104f3" -version = "0.1.0" - -[[deps.SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" -version = "0.7.0" - -[[deps.Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" -version = "1.11.0" - -[[deps.Sockets]] -uuid = "6462fe0b-24de-5631-8697-dd941f90decc" -version = "1.11.0" - -[[deps.StyledStrings]] -uuid = "f489334b-da3d-4c2e-b8f0-e476e12c162b" -version = "1.11.0" - -[[deps.TOML]] -deps = ["Dates"] -uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" -version = "1.0.3" - -[[deps.Tar]] -deps = ["ArgTools", "SHA"] -uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" -version = "1.10.0" - -[[deps.Test]] -deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -version = "1.11.0" - -[[deps.TranscodingStreams]] -git-tree-sha1 = "e84b3a11b9bece70d14cce63406bbc79ed3464d2" -uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" -version = "0.11.2" - -[[deps.UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" -version = "1.11.0" - -[[deps.Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" -version = "1.11.0" - -[[deps.Zlib_jll]] -deps = ["Libdl"] -uuid = "83775a58-1f1d-513f-b197-d71354ab007a" -version = "1.2.13+1" - -[[deps.nghttp2_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" -version = "1.59.0+0" - -[[deps.p7zip_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" -version = "17.4.0+2" diff --git a/docs/Project.toml b/docs/Project.toml index bb2d4af..b56948e 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,3 +1,4 @@ [deps] +CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" OceanSonar = "03019ade-4524-4ecd-af79-46d4f04a1b56" diff --git a/docs/src/01_oceanography/01_ocean/01_sound_speed.md b/docs/src/01_oceanography/01_ocean/01_sound_speed.md deleted file mode 100644 index 53d420d..0000000 --- a/docs/src/01_oceanography/01_ocean/01_sound_speed.md +++ /dev/null @@ -1,5 +0,0 @@ -# Ocean Sound Speed - -```@docs -sound_speed_profile -``` diff --git a/docs/src/01_oceanography/01_ocean/01_sound_speed_profiles.md b/docs/src/01_oceanography/01_ocean/01_sound_speed_profiles.md new file mode 100644 index 0000000..0c0fc5a --- /dev/null +++ b/docs/src/01_oceanography/01_ocean/01_sound_speed_profiles.md @@ -0,0 +1,16 @@ +# Ocean Sound Speed Profiles + +```@docs +sound_speed_profile +``` + +## Munk Sound Speed Profile + +```@docs +sound_speed_profile(::Model{:Munk}, z::Real; ϵ::Real = 7.37e-3) +``` + +```@example +using OceanSonar, CairoMakie +visual("Sound Speed 2D", 0, 5e3, Fix1(sound_speed_profile, "Munk")) +``` diff --git a/docs/src/99_postamble/01_implementation.md b/docs/src/99_postamble/01_implementation.md index acda72d..7f6f29e 100644 --- a/docs/src/99_postamble/01_implementation.md +++ b/docs/src/99_postamble/01_implementation.md @@ -72,3 +72,32 @@ with `listarguments`: ```@docs listarguments ``` + +## Visualisation + +The `visual` and `visual!` functions have methods described throughout the documentation, +flexibly catering to the variety of types of plots that ocean sonar modelling +benefits from. + +Internally `visual` and `visual!` dispatch on the first argument's `Model` specification +to specific `Makie` plotting recipes defined by the extension package `OceanSonarMakieExt`. +Due to the nature of extensions, +such plotting recipe functions are defined with no arguments in `OceanSonar` +then `imported` for overloading in the extension package. + +```@docs +visual +visual! +``` + +```@example +using OceanSonar, CairoMakie +listmodels(visual) +``` + +Supporting the creation of ocean metric visualisations +is the `OceanAxis2D` function: + +```@docs +OceanAxis2D +``` diff --git a/ext/OceanSonarMakieExt/00_preamble.jl b/ext/OceanSonarMakieExt/00_preamble.jl new file mode 100644 index 0000000..6c079b8 --- /dev/null +++ b/ext/OceanSonarMakieExt/00_preamble.jl @@ -0,0 +1,14 @@ +function OceanAxis2D(args...; + yreversed = true, + xgridvisible = true, + ygridvisible = true, + kws... +) + return Axis( + args...; + yreversed = yreversed, + xgridvisible = xgridvisible, + ygridvisible = ygridvisible, + kws... + ) +end diff --git a/ext/OceanSonarMakieExt/01_oceanography/sound_speed/01_recipe.jl b/ext/OceanSonarMakieExt/01_oceanography/sound_speed/01_recipe.jl new file mode 100644 index 0000000..aad5408 --- /dev/null +++ b/ext/OceanSonarMakieExt/01_oceanography/sound_speed/01_recipe.jl @@ -0,0 +1,8 @@ +@recipe(SoundSpeedLines2D, z, c) do scene + Theme() +end + +function plot!(plot::SoundSpeedLines2D) + lines!(plot, plot.c, plot.z) + return plot +end diff --git a/ext/OceanSonarMakieExt/01_oceanography/sound_speed/02_conversions.jl b/ext/OceanSonarMakieExt/01_oceanography/sound_speed/02_conversions.jl new file mode 100644 index 0000000..64843c1 --- /dev/null +++ b/ext/OceanSonarMakieExt/01_oceanography/sound_speed/02_conversions.jl @@ -0,0 +1,19 @@ +# I don't understand why this doesn't fucking work. +# function convert_arguments( +# PlotType::Type{<:SoundSpeedLines2D}, +# z::AbstractVector{<:Real}, +# c::Function +# ) +# @info 1 +# return (z, z .|> c) +# end + +# function convert_arguments( +# PlotType::Type{<:SoundSpeedLines2D}, +# z_min::Real, +# z_max::Real, +# c::Function +# ) +# @info 2 +# convert_arguments(PlotType, range(z_min, z_max, 351), c) +# end diff --git a/ext/OceanSonarMakieExt/01_oceanography/sound_speed/03_visual.jl b/ext/OceanSonarMakieExt/01_oceanography/sound_speed/03_visual.jl new file mode 100644 index 0000000..4f9dfd0 --- /dev/null +++ b/ext/OceanSonarMakieExt/01_oceanography/sound_speed/03_visual.jl @@ -0,0 +1,45 @@ +function visual!(::Model{:SoundSpeed2D}, + axis::AbstractAxis, + z::AbstractVector{<:Real}, + c::AbstractVector{<:Real}; + kws... +) + @info :e + soundspeedlines2d!(axis, z, c; kws...) +end + +function visual!(model::Model{:SoundSpeed2D}, + axis::AbstractAxis, + z::AbstractVector{<:Real}, + c::Function; + kws... +) + @info :d + visual!(model, axis, z, z .|> c; kws...) +end + +function visual!(model::Model{:SoundSpeed2D}, + axis::AbstractAxis, + z_min::Real, + z_max::Real, + c::Function; + kws... +) + @info :c + z = range(z_min, z_max, 351) + visual!(model, axis, z, z .|> c; kws...) +end + +function visual!(model::Model{:SoundSpeed2D}, args...; kws...) + @info :b + visual!(model, current_axis(), args...; kws...) +end + +function visual(model::Model{:SoundSpeed2D}, args...; kws...) + @info :a + fig = Figure() + axis = OceanAxis2D(fig[1, 1]) + plot = visual!(model, axis, args...; kws...) + + return FigureAxisPlot(fig, axis, plot) +end diff --git a/ext/OceanSonarMakieExt/OceanSonarMakieExt.jl b/ext/OceanSonarMakieExt/OceanSonarMakieExt.jl new file mode 100644 index 0000000..26f4236 --- /dev/null +++ b/ext/OceanSonarMakieExt/OceanSonarMakieExt.jl @@ -0,0 +1,62 @@ +module OceanSonarMakieExt + +## Imports +import Makie: + convert_arguments, + plot! + +using Makie: + AbstractAxis, + Axis, + current_axis, + Figure, + FigureAxisPlot, + lines!, + Theme, + @recipe + +import OceanSonar: + OceanAxis2D, + soundspeedlines2d, + soundspeedlines2d!, + visual, + visual! + +using OceanSonar: + Model + +## Implementation +""" +``` +OceanSonar.include_subroots(path::AbstractString) +``` + +Trade-off: If adding a file, need to restart REPL session. +""" +function include_subroots(current_path::AbstractString) + current_directory = if isfile(current_path) + dirname(current_path) + elseif isdir(current_path) + current_path + else + error("What is ", current_path, "?") + end + + for subpath in readdir(current_directory, join = true, sort = true) + if isdir(subpath) + include_subroots(subpath) + continue + elseif isfile(subpath) + endswith(subpath, "_.jl") && continue + subpath == current_path && continue + # @info "Including: $subpath" + subpath + else + error("What is ", subpath, "?") + end |> include + end +end + +include_subroots(@__FILE__) + +end \ No newline at end of file diff --git a/src/00_preamble/01_general/02_textstyles.jl b/src/00_preamble/01_general/02_textstyles.jl index 5c9d244..b2c96f5 100644 --- a/src/00_preamble/01_general/02_textstyles.jl +++ b/src/00_preamble/01_general/02_textstyles.jl @@ -31,7 +31,8 @@ to keep tokenised and keep their text styles const keeptokens = [ "a"; "to"; "the" "NSW"; - (["UL", "VL", "L", "M", "H", "VH", "UH"] .* "F") + (["UL", "VL", "L", "M", "H", "VH", "UH"] .* "F"); + string.(1:3, "D")... ] |> uniquesort! """ diff --git a/src/00_preamble/02_modelling/02_types.jl b/src/00_preamble/02_modelling/02_types.jl index 0ab1263..faba702 100644 --- a/src/00_preamble/02_modelling/02_types.jl +++ b/src/00_preamble/02_modelling/02_types.jl @@ -1,6 +1,13 @@ public MetricFunction public metric_functions +""" +`ModelFunction` + +Abstract supertype of all `OceanSonar`'s `Model`-dispatching functions. +""" +abstract type ModelFunction <: Function end + """ ``` OceanSonar.MetricFunction <: Function @@ -23,10 +30,10 @@ sound_speed("My Model", 1e3) See also: [`Model`](@ref). """ -abstract type MetricFunction <: Function end +abstract type MetricFunction <: ModelFunction end -function (fcn::MetricFunction)(model::Union{Symbol, <:AbstractString}, args...; kw...) - fcn(Model(model), args...; kw...) +function (fcn::ModelFunction)(model::Union{Symbol, <:AbstractString}, args...; kws...) + fcn(Model(model), args...; kws...) end function getdoc(MetricFunctionSubtype::Type{<:MetricFunction}) diff --git a/src/00_preamble/02_modelling/04_listing.jl b/src/00_preamble/02_modelling/04_listing.jl index 14ef78b..c2a3ef8 100644 --- a/src/00_preamble/02_modelling/04_listing.jl +++ b/src/00_preamble/02_modelling/04_listing.jl @@ -1,7 +1,7 @@ export listmodels export listarguments -function listmodels(::Type{Model}, fcn::MetricFunction) +function listmodels(::Type{Model}, fcn::ModelFunction) meths = methods(fcn) first_arg_types = [ meth.sig.types[2] @@ -15,27 +15,27 @@ function listmodels(::Type{Model}, fcn::MetricFunction) ] end -listmodels(::Type{Symbol}, fcn::MetricFunction) = listmodels(Model, fcn) .|> Symbol -listmodels(::Type{String}, fcn::MetricFunction) = listmodels(Model, fcn) .|> String +listmodels(::Type{Symbol}, fcn::ModelFunction) = listmodels(Model, fcn) .|> Symbol +listmodels(::Type{String}, fcn::ModelFunction) = listmodels(Model, fcn) .|> String """ ``` -listmodels(fcn::MetricFunction) +listmodels(fcn::ModelFunction) ``` Returns the names of `fcn` models as a `Vector` of `String`s formatted with `titletext`. Each element of the output can be used as the first positional argument to `fcn`. -See also: [`listarguments`](@ref), [`Model`](@ref), [`OceanSonar.MetricFunction`](@ref). +See also: [`listarguments`](@ref), [`Model`](@ref), [`OceanSonar.ModelFunction`](@ref). """ -listmodels(fcn::MetricFunction) = listmodels(Model, fcn) .|> titletext +listmodels(fcn::ModelFunction) = listmodels(Model, fcn) .|> titletext """ ``` -listarguments(fcn::MetricFunction, model::String) -listarguments(fcn::MetricFunction, model::Symbol) -listarguments(fcn::MetricFunction, model::Model) +listarguments(fcn::ModelFunction, model::String) +listarguments(fcn::ModelFunction, model::Symbol) +listarguments(fcn::ModelFunction, model::Model) ``` Lists the inputs (positional arguments) and parameters (keyword arguments) @@ -45,7 +45,7 @@ with fields `inputs` and `parameters`. While `InteractiveUtils.methodswith` gives similar information, `listarguments` provides the argument names in a useable form. """ -function listarguments(fcn::MetricFunction, model::Model) +function listarguments(fcn::ModelFunction, model::Model) @assert model in listmodels(Model, fcn) meths = methodswith(model |> typeof, fcn) inpss = @. method_argnames(meths) @@ -59,6 +59,6 @@ function listarguments(fcn::MetricFunction, model::Model) ] end -function listarguments(fcn::MetricFunction, model::Union{Symbol, <:AbstractString}) +function listarguments(fcn::ModelFunction, model::Union{Symbol, <:AbstractString}) listarguments(fcn, model |> Model) end diff --git a/src/00_preamble/02_modelling/05_visualisation.jl b/src/00_preamble/02_modelling/05_visualisation.jl new file mode 100644 index 0000000..9ecd2d0 --- /dev/null +++ b/src/00_preamble/02_modelling/05_visualisation.jl @@ -0,0 +1,47 @@ +export visual +export visual! +export OceanAxis2D + +"`InstantiatingVisualFunctionType` is the `typeof(visual)`." +struct InstantiatingVisualFunctionType <: ModelFunction end + +"`MutatingVisualFunctionType` is the `typeof(visual!)`." +struct MutatingVisualFunctionType <: ModelFunction end + +""" +``` +visual(model, args...; kws...) +visual!(model, args...; kws...) +visual!(axis::Axis, model, args...; kws...) +``` + +Dispatches the `args` and `kws` to the appropriate plotting function, +specified by `model`. + +Has no plotting methods until `Makie` is loaded, +which is normally done by loading one of its backends. +`Axis` is from `Makie`. + +The `model` can be a `String`, `Symbol`, or [`Model`](@ref) instance. + +This wrapper function acts as both a convenience and avoidance +for remembering the many plotting recipes defined in this package. + +As per other `OceanSonar` modelling functions, +a list of models is available via `listmodels(visual)` or `listmodels(visual!)` +""" +const visual = InstantiatingVisualFunctionType() + +@doc (@doc visual) +const visual! = MutatingVisualFunctionType() + +""" +``` +OceanAxis2D +``` + +Behaves as `Makie.Axis` except with the default of `yreversed = true`. + +Unusable until `Makie` is loaded. +""" +function OceanAxis2D end diff --git a/src/01_oceanography/01_ocean/sound_speed_profiles.jl b/src/01_oceanography/01_ocean/sound_speed_profiles.jl index e901c4b..aecc8b9 100644 --- a/src/01_oceanography/01_ocean/sound_speed_profiles.jl +++ b/src/01_oceanography/01_ocean/sound_speed_profiles.jl @@ -1,5 +1,6 @@ export sound_speed_profile +## Implementation @implement_metric_function sound_speed_profile @doc """ @@ -14,6 +15,21 @@ Subtypes [`OceanSonar.MetricFunction`](@ref). """ sound_speed_profile +## Visualisation +""" +``` +soundspeedlines2d +soundspeedlines2d! +``` + +Plotting functions. Methods to be populated by `Makie` extension. +""" +function soundspeedlines2d end + +@doc (@doc soundspeedlines2d) +function soundspeedlines2d! end + +## Models """ ``` sound_speed_profile(::Model{:Homogeneous}; c::Real = 1500.0) = c diff --git a/src/OceanSonar.jl b/src/OceanSonar.jl index e4530f0..e59741d 100644 --- a/src/OceanSonar.jl +++ b/src/OceanSonar.jl @@ -19,11 +19,15 @@ See the documentation website (in development) for more information. """ module OceanSonar +## Re-exports +export Fix1 + ## Imports import Base: show using Base: + Fix1, kwarg_decl, method_argnames diff --git a/test/00_preamble/01_auxiliary/textstyles.jl b/test/00_preamble/01_auxiliary/textstyles.jl index 83d538d..4dc5897 100644 --- a/test/00_preamble/01_auxiliary/textstyles.jl +++ b/test/00_preamble/01_auxiliary/textstyles.jl @@ -18,3 +18,25 @@ texts = ( @test context == newtext end end + +texts = ( + Space = "Say 32 Big Goodbyes to a Cruel NSW 1st World", + space = "say 32 big goodbyes to a cruel NSW 1st world", + Snake = "Say_32_Big_Goodbyes_to_a_Cruel_NSW_1st_World", + snake = "say_32_big_goodbyes_to_a_cruel_NSW_1st_world", + Kebab = "Say-32-Big-Goodbyes-to-a-Cruel-NSW-1st-World", + kebab = "say-32-big-goodbyes-to-a-cruel-NSW-1st-world", + pascal = "Say32BigGoodbyesToACruelNSW1stWorld", + camel = "say32BigGoodbyesToACruelNSW1stWorld", +) + +@testset "From $oldstyle" for (oldstyle, oldtext) in pairs(texts) + @testset "To $newstyle" for (newstyle, newtext) in pairs(texts) + context = textstyle(newstyle |> Symbol |> Val, oldtext) + if oldstyle in [:pascal, :camel] + @test_broken context == newtext + else + @test context == newtext + end + end +end diff --git a/test/Manifest.toml b/test/Manifest.toml deleted file mode 100644 index d1bee0b..0000000 --- a/test/Manifest.toml +++ /dev/null @@ -1,256 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -julia_version = "1.11.0-rc2" -manifest_format = "2.0" -project_hash = "a80f897e5c8e4eb28e38f55c302f762b0cbcaf09" - -[[deps.Aqua]] -deps = ["Compat", "Pkg", "Test"] -git-tree-sha1 = "12e575f31a6f233ba2485ed86b9325b85df37c61" -uuid = "4c88cf16-eb10-579e-8560-4a9242c79595" -version = "0.8.7" - -[[deps.ArgTools]] -uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" -version = "1.1.2" - -[[deps.Artifacts]] -uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" -version = "1.11.0" - -[[deps.Base64]] -uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" -version = "1.11.0" - -[[deps.CodeTracking]] -deps = ["InteractiveUtils", "UUIDs"] -git-tree-sha1 = "7eee164f122511d3e4e1ebadb7956939ea7e1c77" -uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" -version = "1.3.6" - -[[deps.Compat]] -deps = ["TOML", "UUIDs"] -git-tree-sha1 = "8ae8d32e09f0dcf42a36b90d4e17f5dd2e4c4215" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "4.16.0" - - [deps.Compat.extensions] - CompatLinearAlgebraExt = "LinearAlgebra" - - [deps.Compat.weakdeps] - Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" - LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - -[[deps.Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" -version = "1.11.0" - -[[deps.Downloads]] -deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] -uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" -version = "1.6.0" - -[[deps.FileWatching]] -uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" -version = "1.11.0" - -[[deps.HashArrayMappedTries]] -git-tree-sha1 = "2eaa69a7cab70a52b9687c8bf950a5a93ec895ae" -uuid = "076d061b-32b6-4027-95e0-9a2c6f6d7e74" -version = "0.2.0" - -[[deps.InteractiveUtils]] -deps = ["Markdown"] -uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" -version = "1.11.0" - -[[deps.JET]] -deps = ["CodeTracking", "InteractiveUtils", "JuliaInterpreter", "LoweredCodeUtils", "MacroTools", "Pkg", "PrecompileTools", "Preferences", "Test"] -git-tree-sha1 = "769c5277a61f21ee1faa9f75e360eb43252ac27e" -uuid = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" -version = "0.9.8" - - [deps.JET.extensions] - JETCthulhuExt = "Cthulhu" - ReviseExt = "Revise" - - [deps.JET.weakdeps] - Cthulhu = "f68482b8-f384-11e8-15f7-abe071a5a75f" - Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" - -[[deps.JuliaInterpreter]] -deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"] -git-tree-sha1 = "7ae67d8567853d367e3463719356b8989e236069" -uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a" -version = "0.9.34" - -[[deps.LibCURL]] -deps = ["LibCURL_jll", "MozillaCACerts_jll"] -uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" -version = "0.6.4" - -[[deps.LibCURL_jll]] -deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] -uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" -version = "8.6.0+0" - -[[deps.LibGit2]] -deps = ["Base64", "LibGit2_jll", "NetworkOptions", "Printf", "SHA"] -uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" -version = "1.11.0" - -[[deps.LibGit2_jll]] -deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll"] -uuid = "e37daf67-58a4-590a-8e99-b0245dd2ffc5" -version = "1.7.2+0" - -[[deps.LibSSH2_jll]] -deps = ["Artifacts", "Libdl", "MbedTLS_jll"] -uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" -version = "1.11.0+1" - -[[deps.Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" -version = "1.11.0" - -[[deps.Logging]] -uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" -version = "1.11.0" - -[[deps.LoweredCodeUtils]] -deps = ["JuliaInterpreter"] -git-tree-sha1 = "1ce1834f9644a8f7c011eb0592b7fd6c42c90653" -uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b" -version = "3.0.1" - -[[deps.MacroTools]] -deps = ["Markdown", "Random"] -git-tree-sha1 = "2fa9ee3e63fd3a4f7a9a4f4744a52f4856de82df" -uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -version = "0.5.13" - -[[deps.Markdown]] -deps = ["Base64"] -uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" -version = "1.11.0" - -[[deps.MbedTLS_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" -version = "2.28.6+0" - -[[deps.MozillaCACerts_jll]] -uuid = "14a3606d-f60d-562e-9121-12d972cd8159" -version = "2023.12.12" - -[[deps.NetworkOptions]] -uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" -version = "1.2.0" - -[[deps.Pkg]] -deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "Random", "SHA", "TOML", "Tar", "UUIDs", "p7zip_jll"] -uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -version = "1.11.0" - - [deps.Pkg.extensions] - REPLExt = "REPL" - - [deps.Pkg.weakdeps] - REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" - -[[deps.PrecompileTools]] -deps = ["Preferences"] -git-tree-sha1 = "5aa36f7049a63a1528fe8f7c3f2113413ffd4e1f" -uuid = "aea7be01-6a6a-4083-8856-8a6e6704d82a" -version = "1.2.1" - -[[deps.Preferences]] -deps = ["TOML"] -git-tree-sha1 = "9306f6085165d270f7e3db02af26a400d580f5c6" -uuid = "21216c6a-2e73-6563-6e65-726566657250" -version = "1.4.3" - -[[deps.Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" -version = "1.11.0" - -[[deps.Random]] -deps = ["SHA"] -uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -version = "1.11.0" - -[[deps.RequiredInterfaces]] -deps = ["InteractiveUtils", "Logging", "Test"] -git-tree-sha1 = "c3250333ea2894237ed015baf7d5fcb8a1ea3169" -uuid = "97f35ef4-7bc5-4ec1-a41a-dcc69c7308c6" -version = "0.1.6" - -[[deps.SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" -version = "0.7.0" - -[[deps.SafeTestsets]] -git-tree-sha1 = "81ec49d645af090901120a1542e67ecbbe044db3" -uuid = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" -version = "0.1.0" - -[[deps.ScopedValues]] -deps = ["HashArrayMappedTries", "Logging"] -git-tree-sha1 = "eef2fbac9538ee6cc60ee1489f028d2f8a1a5249" -uuid = "7e506255-f358-4e82-b7e4-beb19740aa63" -version = "1.2.1" - -[[deps.Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" -version = "1.11.0" - -[[deps.StyledStrings]] -uuid = "f489334b-da3d-4c2e-b8f0-e476e12c162b" -version = "1.11.0" - -[[deps.Supposition]] -deps = ["Logging", "Pkg", "PrecompileTools", "Printf", "Random", "RequiredInterfaces", "ScopedValues", "Serialization", "StyledStrings", "Test"] -git-tree-sha1 = "3a214d299ae8bfb8bee0eaf293690667d2ee80d8" -uuid = "5a0628fe-1738-4658-9b6d-0b7605a9755b" -version = "0.3.5" - -[[deps.TOML]] -deps = ["Dates"] -uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" -version = "1.0.3" - -[[deps.Tar]] -deps = ["ArgTools", "SHA"] -uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" -version = "1.10.0" - -[[deps.Test]] -deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] -uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -version = "1.11.0" - -[[deps.UUIDs]] -deps = ["Random", "SHA"] -uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" -version = "1.11.0" - -[[deps.Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" -version = "1.11.0" - -[[deps.Zlib_jll]] -deps = ["Libdl"] -uuid = "83775a58-1f1d-513f-b197-d71354ab007a" -version = "1.2.13+1" - -[[deps.nghttp2_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" -version = "1.59.0+0" - -[[deps.p7zip_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" -version = "17.4.0+2" diff --git a/test/Project.toml b/test/Project.toml index 17689e7..2e310c3 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -2,6 +2,7 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" +OceanSonar = "03019ade-4524-4ecd-af79-46d4f04a1b56" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" Supposition = "5a0628fe-1738-4658-9b6d-0b7605a9755b" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"