From cfa6104ceaeaf4de0ff3bbe601dbace7080594d5 Mon Sep 17 00:00:00 2001 From: Aaron Kaw Date: Wed, 24 Jul 2024 04:21:49 +1000 Subject: [PATCH] Migrated and improved from previous iteration Tests to come --- .github/workflows/CI.yml | 4 +- Project.toml | 8 + docs/make.jl | 34 ++- docs/src/01_new_users_introduction.md | 18 ++ .../src/04_ocean_acoustics/00_introduction.md | 1 + .../01_tracing/01_ray_tracing.md | 5 + .../01_tracing/02_beam_tracing.md | 1 + .../01_tracing/03_pressure_field.md | 1 + readme.md | 24 ++ .../01_general/01_auxiliary_functions.jl | 35 +++ .../01_general/02_flexible_math_functions.jl | 19 ++ .../01_general/02_string_cases.jl | 118 ++++++++++ .../02_modelling/01_model_naming.jl | 7 + .../02_modelling/02_model_types.jl | 32 +++ .../02_modelling/03_model_parsing.jl | 8 + src/02_oceanography/volume/celerity.jl | 43 ++++ .../01_profiles/attenuation/atmosphere.jl | 0 .../01_profiles/attenuation/ocean.jl | 0 .../attenuation/seabed/compressional.jl | 0 .../01_profiles/attenuation/seabed/shear.jl | 0 .../01_profiles/boundary/altimetry.jl | 0 .../01_profiles/boundary/bathymetry.jl | 0 .../01_profiles/celerity/atmosphere.jl | 0 .../01_profiles/celerity/ocean.jl | 16 ++ .../celerity/seabed/compressional.jl | 0 .../01_profiles/celerity/seabed/shear.jl | 0 .../01_profiles/density/atmosphere.jl | 0 src/03_acoustics/01_profiles/density/ocean.jl | 0 .../01_profiles/density/seabed.jl | 0 src/04_processing/01_sonar_types.jl | 24 ++ src/04_processing/01_windows.jl | 0 src/04_processing/02_sonar_terms.jl | 17 ++ src/06_postliminary/visualisation.jl | 0 src/OceanSonar.jl | 37 ++- test/00_quality/aqua.jl | 6 + test/00_quality/docstrings.jl | 6 + test/00_quality/linting.jl | 4 + test/Manifest.toml | 222 ------------------ test/Project.toml | 2 + test/runtests.jl | 18 +- 40 files changed, 472 insertions(+), 238 deletions(-) create mode 100644 docs/src/01_new_users_introduction.md create mode 100644 docs/src/04_ocean_acoustics/00_introduction.md create mode 100644 docs/src/04_ocean_acoustics/01_tracing/01_ray_tracing.md create mode 100644 docs/src/04_ocean_acoustics/01_tracing/02_beam_tracing.md create mode 100644 docs/src/04_ocean_acoustics/01_tracing/03_pressure_field.md create mode 100644 src/01_preliminary/01_general/01_auxiliary_functions.jl create mode 100644 src/01_preliminary/01_general/02_flexible_math_functions.jl create mode 100644 src/01_preliminary/01_general/02_string_cases.jl create mode 100644 src/01_preliminary/02_modelling/01_model_naming.jl create mode 100644 src/01_preliminary/02_modelling/02_model_types.jl create mode 100644 src/01_preliminary/02_modelling/03_model_parsing.jl create mode 100644 src/02_oceanography/volume/celerity.jl create mode 100644 src/03_acoustics/01_profiles/attenuation/atmosphere.jl create mode 100644 src/03_acoustics/01_profiles/attenuation/ocean.jl create mode 100644 src/03_acoustics/01_profiles/attenuation/seabed/compressional.jl create mode 100644 src/03_acoustics/01_profiles/attenuation/seabed/shear.jl create mode 100644 src/03_acoustics/01_profiles/boundary/altimetry.jl create mode 100644 src/03_acoustics/01_profiles/boundary/bathymetry.jl create mode 100644 src/03_acoustics/01_profiles/celerity/atmosphere.jl create mode 100644 src/03_acoustics/01_profiles/celerity/ocean.jl create mode 100644 src/03_acoustics/01_profiles/celerity/seabed/compressional.jl create mode 100644 src/03_acoustics/01_profiles/celerity/seabed/shear.jl create mode 100644 src/03_acoustics/01_profiles/density/atmosphere.jl create mode 100644 src/03_acoustics/01_profiles/density/ocean.jl create mode 100644 src/03_acoustics/01_profiles/density/seabed.jl create mode 100644 src/04_processing/01_sonar_types.jl create mode 100644 src/04_processing/01_windows.jl create mode 100644 src/04_processing/02_sonar_terms.jl create mode 100644 src/06_postliminary/visualisation.jl create mode 100644 test/00_quality/aqua.jl create mode 100644 test/00_quality/docstrings.jl create mode 100644 test/00_quality/linting.jl delete mode 100644 test/Manifest.toml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 75d471a..d55087a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -23,7 +23,7 @@ jobs: fail-fast: false matrix: version: - - '1.11' + - '1.11.0-rc1' os: - ubuntu-latest - windows-latest @@ -49,7 +49,7 @@ jobs: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 with: - version: '1.11' + version: '1.11.0-rc1' - uses: julia-actions/cache@v2 - name: Configure doc environment shell: julia --project=docs --color=yes {0} diff --git a/Project.toml b/Project.toml index 4dc63bb..032222d 100644 --- a/Project.toml +++ b/Project.toml @@ -3,5 +3,13 @@ uuid = "03019ade-4524-4ecd-af79-46d4f04a1b56" authors = ["Aaron Kaw and contributors"] version = "1.0.0-DEV" +[deps] +IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" +NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" + [compat] +IntervalArithmetic = "0.22.14" +NaNMath = "1.0.2" +Symbolics = "5.34.0" julia = "1.10" diff --git a/docs/make.jl b/docs/make.jl index 16cc233..e24cfa0 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,6 +1,35 @@ using OceanSonar using Documenter +sidebar_title(path::String) = if isdir(path) + basename(path)[4:end] +elseif isfile(path) + basename(path)[4:end-3] +else + error("What even is $path?") +end |> OceanSonar.titlecase + +src_dir = joinpath(@__DIR__, "src") + +function populate_pages(current_path) + if isfile(current_path) + current_path[length(src_dir)+2 : end] + elseif isdir(current_path) + [ + sidebar_title(subpath) => populate_pages(joinpath(current_path, subpath)) + for subpath in readdir(current_path, join = true, sort = true) + if !contains(subpath, "index.md") + ] + else + error("What even is $current_path?") + end +end + +pages=[ + "Home" => "index.md", + populate_pages(joinpath(@__DIR__, "src"))... +] + DocMeta.setdocmeta!(OceanSonar, :DocTestSetup, :(using OceanSonar); recursive=true) makedocs(; @@ -10,11 +39,10 @@ makedocs(; format=Documenter.HTML(; canonical="https://kapple19.github.io/OceanSonar.jl", edit_link="main", + collapselevel = 1, assets=String[], ), - pages=[ - "Home" => "index.md", - ], + pages=pages, ) deploydocs(; diff --git a/docs/src/01_new_users_introduction.md b/docs/src/01_new_users_introduction.md new file mode 100644 index 0000000..051309c --- /dev/null +++ b/docs/src/01_new_users_introduction.md @@ -0,0 +1,18 @@ +# New Users Introduction + +"New" could apply to users as some combination of: + +```@contents +Pages = ["01_new_users_introduction.md"] +Depth = 2:2 +``` + +of which this page addresses all three, linked in the above list. + +## New to the Field of Ocean Sonar + +## New to Julia Programming + +## New to Scientific Machine Learning + +## New to this Package diff --git a/docs/src/04_ocean_acoustics/00_introduction.md b/docs/src/04_ocean_acoustics/00_introduction.md new file mode 100644 index 0000000..3f14850 --- /dev/null +++ b/docs/src/04_ocean_acoustics/00_introduction.md @@ -0,0 +1 @@ +# Ocean Acoustics diff --git a/docs/src/04_ocean_acoustics/01_tracing/01_ray_tracing.md b/docs/src/04_ocean_acoustics/01_tracing/01_ray_tracing.md new file mode 100644 index 0000000..04c7907 --- /dev/null +++ b/docs/src/04_ocean_acoustics/01_tracing/01_ray_tracing.md @@ -0,0 +1,5 @@ +# Ray Tracing + +## Literature Fidelity + +## References diff --git a/docs/src/04_ocean_acoustics/01_tracing/02_beam_tracing.md b/docs/src/04_ocean_acoustics/01_tracing/02_beam_tracing.md new file mode 100644 index 0000000..0599e4a --- /dev/null +++ b/docs/src/04_ocean_acoustics/01_tracing/02_beam_tracing.md @@ -0,0 +1 @@ +# Beam Tracing diff --git a/docs/src/04_ocean_acoustics/01_tracing/03_pressure_field.md b/docs/src/04_ocean_acoustics/01_tracing/03_pressure_field.md new file mode 100644 index 0000000..b6b8aa9 --- /dev/null +++ b/docs/src/04_ocean_acoustics/01_tracing/03_pressure_field.md @@ -0,0 +1 @@ +# Pressure Field diff --git a/readme.md b/readme.md index 88096a9..110922e 100644 --- a/readme.md +++ b/readme.md @@ -8,3 +8,27 @@ ## Citing See [`citation.bib`](CITATION.bib) for the relevant reference(s). + +## Roadmap + +Usage Features: + +* Ocean sonar related environmental metrics (ocean sound speed, life noise, metric conversions, etc). +* Acoustic propagation models with modular components (beam types, coherence, etc). +* The sonar equation and calculation of its many terms. +* Detection performance metrics applied to the signal-to-noise ratio. +* Acausal modelling of the sonar equation and detection algorithms. +* Easy and interactive visualisations of all of the above. +* Graphical user interface/dashboards for streamlining usage and accessibility. + +Implementation Features: + +* Model name-based dispatch and handling avoids boilerplate and enables user extensibility. +* Modularisation of model components enables easy comparisons and the design of an algorithm for default best choices based on inputs ala `solve` from `DifferentialEquations.jl`. +* Interpolation methods built into the implementations to further enable user extensibility. +* Functor type system keeps external functions safe from this package's implementation design (e.g. `listmodels` will only work on `OceanSonar.AbstractModellingType` types and objects). +* Acausal modelling enabling the single implementation to flexibly apply for declaring different components of the sonar equation as the unknown to compute for. + +## References + +TODO. diff --git a/src/01_preliminary/01_general/01_auxiliary_functions.jl b/src/01_preliminary/01_general/01_auxiliary_functions.jl new file mode 100644 index 0000000..72d629d --- /dev/null +++ b/src/01_preliminary/01_general/01_auxiliary_functions.jl @@ -0,0 +1,35 @@ +export uniquesort! +export efficient_sampling +export output_extrema + +const uniquesort! = unique! ∘ sort! + +const cossin = reverse ∘ sincos +const nan_cossin = reverse ∘ nan_sincos +const cossind = reverse ∘ sincosd +const magang(z::Number) = (abs(z), angle(z)) + +function extract_all_underscored_alphanumeric_bodies(text::AbstractString) + idxs = findall(r"([a-z]|[A-Z]|[0-9]|_)+", text) + return getindex.(text, idxs) +end + +function extract_first_underscored_alphanumeric_bodies(text::AbstractString) + return extract_all_underscored_alphanumeric_bodies(text)[1] +end + +function extract_last_underscored_alphanumeric_bodies(text::AbstractString) + return extract_all_underscored_alphanumeric_bodies(text)[end] +end + +function efficient_sampling(f::Function, x1::Real, xN::Real, N::Integer) + # WIP, to be replaced + range(x1, xN, N) +end + +# function efficient_sampling(f::Function, x1::Real, xN::Real, θmin::Real) +# # WIP +# end + +output_extrema(f::Function, ntv::Interval) = (:lo, :hi) .|> bnd -> getproperty(f(ntv).bareinterval, bnd) +output_extrema(f::Function, x_lo::Real, x_hi::Real) = output_extrema(f, interval(x_lo, x_hi)) diff --git a/src/01_preliminary/01_general/02_flexible_math_functions.jl b/src/01_preliminary/01_general/02_flexible_math_functions.jl new file mode 100644 index 0000000..4d74c79 --- /dev/null +++ b/src/01_preliminary/01_general/02_flexible_math_functions.jl @@ -0,0 +1,19 @@ +export ocnson_sqrt + +num_fcn(fcn::Function, args::Num...) = Term(fcn, [args...]) |> wrap + +for op in (:sqrt, :cos, :sin, :cossin) + op_string = String(op) + ocnson_op = Symbol("ocnson_" * op_string) + nan_op = Symbol("nan_" * op_string) + eval( + quote + $ocnson_op(x::Real) = $nan_op(x) + $ocnson_op(x::Num) = $op(x) + $ocnson_op(x::Interval) = $op(x) + end + ) +end + +ocnson_hypot(args::Number...) = nan_hypot(args...) +ocnson_hypot(args::Union{<:Num, <:Interval}...) = hypot(args...) diff --git a/src/01_preliminary/01_general/02_string_cases.jl b/src/01_preliminary/01_general/02_string_cases.jl new file mode 100644 index 0000000..307defd --- /dev/null +++ b/src/01_preliminary/01_general/02_string_cases.jl @@ -0,0 +1,118 @@ +public stringcase +public titlecase +export snakecase +export kebabcase +export pascalcase + +""" +Storage of all words that need to keep their case as is stored here, +e.g. acronyms, articles, prepositions, coordinating conjunctions, etc. +""" +keepcases = [ + "NSW" + "the" + "a" + "to" +] |> uniquesort! + +delims = ( + snake = "_", + space = " ", + kebab = "-" +) + +_stringcasesep(::Val{C}) where C = delims[C] +_stringcasesep(::Val{:camel}) = "" +_stringcasesep(::Val{:Snake}) = _stringcasesep(:snake |> Val) +_stringcasesep(::Val{:Space}) = _stringcasesep(:space |> Val) +_stringcasesep(::Val{:Kebab}) = _stringcasesep(:kebab |> Val) +_stringcasesep(::Val{:Camel}) = _stringcasesep(:camel |> Val) +_stringcasesep(::Val{:pascal}) = _stringcasesep(:Camel |> Val) +_stringcasesep(::Val{:Pascal}) = _stringcasesep(:Camel |> Val) +_stringcasesep(::Val{:title}) = _stringcasesep(:Space |> Val) + +function _firstcap(::Val{C}, char::Char) where C + return if (C in (:pascal, :title)) || isuppercase(String(C)[1]) + uppercase(char) + else + lowercase(char) + end +end + +function _sepcap(::Val{C}, char::Char) where C + return if (C in (:pascal, :title, :camel)) || isuppercase(String(C)[1]) + uppercase(char) + else + lowercase(char) + end +end + +function _wordseparation(case::Val{C}, text::AbstractString) where C + text = text[1:end-1] * _sepcap(case, text[end]) +end + +function _caseconversions(::Val{C}, text::AbstractString; keepcases) where C + boolkeepcase = lowercase(text) .== lowercase.(keepcases) + iskeepcase = any(boolkeepcase) + keepcase = if iskeepcase + keepcases[boolkeepcase |> findall |> only] + else + "" + end + + iscamel = C in (:pascal, :Pascal, :camel, :Camel) + return if iskeepcase && (iscamel ? isuppercase(keepcase[1]) : true) + keepcase + elseif (C in (:pascal, :title, :camel)) || isuppercase(String(C)[1]) + uppercase(text[1]) * text[2:end] + else + text + end +end + +function stringcase(case::Val{C}, text::AbstractString; keepcases = keepcases) where C + tempsep = delims.snake + + # Convert camel word separations to snake separations + camel_regexes = [ + "[a-z][A-Z]" + "[0-9][A-Z]" + "[a-z][0-9]" + "[A-Z][0-9]" + ] .|> Regex + for camel_regex = camel_regexes + text = replace(text, + [ + text[idxs] => text[idxs[begin]] * tempsep * text[idxs[end]] + for idxs in findall(camel_regex, text, overlap = true) + ]... + ) + end + + text = lowercase(text) + + # Convert any delimiters to snake delimiter + text = replace(text, [sep => tempsep for sep in values(delims)]...) + + texts = split(text, tempsep) + + texts = [_caseconversions(case, text, keepcases = keepcases) for text in texts] + + text = join(texts, _stringcasesep(case)) + + text = _firstcap(case, text[1]) * text[2:end] + + return text +end + +stringcase(::Val{:Pascal}, text::AbstractString; keepcases = keepcases) = stringcase(:Camel |> Val, text; keepcases = keepcases) +stringcase(::Val{:pascal}, text::AbstractString; keepcases = keepcases) = stringcase(:Camel |> Val, text; keepcases = keepcases) +stringcase(::Val{:title}, text::AbstractString; keepcases = keepcases) = stringcase(:Space |> Val, text; keepcases = keepcases) + +stringcase(case::Symbol, text::AbstractString; keepcases = keepcases) = stringcase(case |> Val, text; keepcases = keepcases) +stringcase(case::AbstractString, text::AbstractString; keepcases = keepcases) = stringcase(case |> Symbol, text; keepcases = keepcases) + +titlecase(text::AbstractString; keepcases = keepcases) = stringcase(:Space |> Val, text; keepcases = keepcases) +snakecase(text::AbstractString; keepcases = keepcases) = stringcase(:snake |> Val, text; keepcases = keepcases) +kebabcase(text::AbstractString; keepcases = keepcases) = stringcase(:Kebab |> Val, text; keepcases = keepcases) +pascalcase(text::AbstractString; keepcases = keepcases) = stringcase(:Pascal |> Val, text; keepcases = keepcases) diff --git a/src/01_preliminary/02_modelling/01_model_naming.jl b/src/01_preliminary/02_modelling/01_model_naming.jl new file mode 100644 index 0000000..6d545d1 --- /dev/null +++ b/src/01_preliminary/02_modelling/01_model_naming.jl @@ -0,0 +1,7 @@ +export ModelName + +struct ModelName{m} end + +ModelName(m::Symbol) = ModelName(m |> String) + +ModelName(m::AbstractString) = ModelName{m |> snakecase |> Symbol}() diff --git a/src/01_preliminary/02_modelling/02_model_types.jl b/src/01_preliminary/02_modelling/02_model_types.jl new file mode 100644 index 0000000..6ee0d9b --- /dev/null +++ b/src/01_preliminary/02_modelling/02_model_types.jl @@ -0,0 +1,32 @@ +abstract type AbstractModellingType <: Function end +abstract type ModellingFunction <: AbstractModellingType end +abstract type ModellingFunctor <: AbstractModellingType end +abstract type ModellingFunctor2D <: ModellingFunctor end +abstract type ModellingFunctor3D <: ModellingFunctor end + +function (::Type{Fun})( + model::Union{Symbol, <:AbstractString}, args::Real...; kw... +) where {Fun <: ModellingFunction} + Fun(model |> ModelName, args...; kw...) +end + +function (::Type{Fct})(model::ModelName; pars...) where {Fct <: ModellingFunctor} + Fct(model, pars) +end + +macro implement_modelling_functor(super_type, name) + @eval begin + struct $name <: $super_type + model::ModelName + pars::Pairs + end + + function $name(model::Union{Symbol, <:AbstractString}, args...; pars...) + $name(model |> ModelName, args...; pars...) + end + + function (fct::$name)(args::Real...) + $name(fct.model, args...; fct.pars...) + end + end +end \ No newline at end of file diff --git a/src/01_preliminary/02_modelling/03_model_parsing.jl b/src/01_preliminary/02_modelling/03_model_parsing.jl new file mode 100644 index 0000000..4addb73 --- /dev/null +++ b/src/01_preliminary/02_modelling/03_model_parsing.jl @@ -0,0 +1,8 @@ +listmodels(modelling_function::AbstractModellingType) = [ + modelpretty(modelling_function, type()) + for type in [ + collect(m.sig.types)[2] for m in methods(modelling_function) + ] if type <: ModelName +] + +listmodels(fct::Fct) where {Fct<:ModellingFunctor} = String(Fct) \ No newline at end of file diff --git a/src/02_oceanography/volume/celerity.jl b/src/02_oceanography/volume/celerity.jl new file mode 100644 index 0000000..26dd6f7 --- /dev/null +++ b/src/02_oceanography/volume/celerity.jl @@ -0,0 +1,43 @@ +export ocean_celerity + +""" +``` +ocean_celerity(model, ...) +``` +""" +struct ocean_celerity <: ModellingFunction end + +""" +``` +ocean_celerity("Jensen", T::Real, S::Real, z::Real)::Real +``` +Equation 1.1 of Jensen, et al (2011). +""" +function ocean_celerity(::ModelName{:jensen}, T::Real, S::Real, z::Real) + c = 1449.2 + 4.6T - 0.055T^2 + 0.00029T^3 + (1.34 - 0.01T) * (S - 35) + 0.016z +end + +""" +``` +ocean_celerity("Del Grosso", T::Real, S::Real, P::Real) +``` +""" +function ocean_celerity(::ModelName{:del_grosso}, T::Real, S::Real, P::Real) + T² = T^2 + T³ = T^3 + P² = P^2 + P³ = P^3 + + V_T = 4.5721T − 4.4532e−2T² − 2.6045e−4T³ + 7.9851e−6T^4 + V_P = 1.60272e−1P + 1.0268e−5P² + 3.5216e−9P³ − 3.3603e−12P^4 + V_S = 1.39799(S − 35) + 1.69202e−3(S − 35)^2 + V_STP = (S − 35) * ( + −1.1244e−2T + 7.7711e−7T² + 7.7016e−5P − 1.2943e−7P² + 3.1580e−8P*T + 1.5790e−9P*T² + ) + P * ( + −1.8607e−4T + 7.4812e−6T² + 4.5283e−8T³ + ) + P² * ( + −2.5294e−7T + 1.8563e−9T² + ) + P³ * (−1.9646e−10T) + + V = 1449.14 + V_T + V_P + V_S + V_STP +end \ No newline at end of file diff --git a/src/03_acoustics/01_profiles/attenuation/atmosphere.jl b/src/03_acoustics/01_profiles/attenuation/atmosphere.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/03_acoustics/01_profiles/attenuation/ocean.jl b/src/03_acoustics/01_profiles/attenuation/ocean.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/03_acoustics/01_profiles/attenuation/seabed/compressional.jl b/src/03_acoustics/01_profiles/attenuation/seabed/compressional.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/03_acoustics/01_profiles/attenuation/seabed/shear.jl b/src/03_acoustics/01_profiles/attenuation/seabed/shear.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/03_acoustics/01_profiles/boundary/altimetry.jl b/src/03_acoustics/01_profiles/boundary/altimetry.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/03_acoustics/01_profiles/boundary/bathymetry.jl b/src/03_acoustics/01_profiles/boundary/bathymetry.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/03_acoustics/01_profiles/celerity/atmosphere.jl b/src/03_acoustics/01_profiles/celerity/atmosphere.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/03_acoustics/01_profiles/celerity/ocean.jl b/src/03_acoustics/01_profiles/celerity/ocean.jl new file mode 100644 index 0000000..61817e7 --- /dev/null +++ b/src/03_acoustics/01_profiles/celerity/ocean.jl @@ -0,0 +1,16 @@ +export OceanCelerity + +@implement_modelling_functor ModellingFunctor3D OceanCelerity + +function OceanCelerity(::ModelName{:munk}, x::Real, y::Real, z::Real; ϵ::Real = 7.37e-3) + z̃ = 2(z/1300 - 1) + return 1500( + 1 + ϵ * ( + z̃ - 1 + exp(-z̃) + ) + ) +end + +function OceanCelerity(::ModelName{:square_index}, x::Real, y::Real, z::Real; c₀ = 1550.0) + c₀ / ocnson_sqrt(1 + 2.4z / c₀) +end \ No newline at end of file diff --git a/src/03_acoustics/01_profiles/celerity/seabed/compressional.jl b/src/03_acoustics/01_profiles/celerity/seabed/compressional.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/03_acoustics/01_profiles/celerity/seabed/shear.jl b/src/03_acoustics/01_profiles/celerity/seabed/shear.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/03_acoustics/01_profiles/density/atmosphere.jl b/src/03_acoustics/01_profiles/density/atmosphere.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/03_acoustics/01_profiles/density/ocean.jl b/src/03_acoustics/01_profiles/density/ocean.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/03_acoustics/01_profiles/density/seabed.jl b/src/03_acoustics/01_profiles/density/seabed.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/04_processing/01_sonar_types.jl b/src/04_processing/01_sonar_types.jl new file mode 100644 index 0000000..b4bec59 --- /dev/null +++ b/src/04_processing/01_sonar_types.jl @@ -0,0 +1,24 @@ +export SonarType +export BandType +export BandType +export BandType +export Passive +export Exposure +export Intercept +export Active +export Monostatic +export Bistatic +export NB +export BB + +abstract type BandType end +abstract type NB <: BandType end +abstract type BB <: BandType end + +abstract type SonarType{BS <: BandType} end +abstract type Passive{BS <: BandType} <: SonarType{BS} end +abstract type Exposure{BS <: BandType} <: Passive{BS} end +abstract type Intercept{BS <: BandType} <: Passive{BS} end +abstract type Active{BS <: BandType} <: SonarType{BS} end +abstract type Monostatic{BS <: BandType} <: Active{BS} end +abstract type Bistatic{BS <: BandType} <: Active{BS} end diff --git a/src/04_processing/01_windows.jl b/src/04_processing/01_windows.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/04_processing/02_sonar_terms.jl b/src/04_processing/02_sonar_terms.jl new file mode 100644 index 0000000..e052fa3 --- /dev/null +++ b/src/04_processing/02_sonar_terms.jl @@ -0,0 +1,17 @@ +export signal_to_noise_ratio + +function signal_to_noise_ratio(::Type{<:Passive}, SL, PL, NL, AG) + SNR = SL - PL - NL + AG +end + +function signal_to_noise_ratio(::Type{<:Monostatic}, SL, PL, TS, NL, RL, AG) + SNR = SL - 2PL + TS - (NL ⊕ RL) + AG +end + +function signal_to_noise_ratio(::Type{<:Bistatic}, SL, PLa, PLb, TS, NL, RL, AG) + SNR = SL - PLa - PLb + TS - (NL ⊕ RL) + AG +end + +sonar_terms = ( + SL = signal_to_noise_ratio, +) diff --git a/src/06_postliminary/visualisation.jl b/src/06_postliminary/visualisation.jl new file mode 100644 index 0000000..e69de29 diff --git a/src/OceanSonar.jl b/src/OceanSonar.jl index d04454c..933d6f7 100644 --- a/src/OceanSonar.jl +++ b/src/OceanSonar.jl @@ -1,5 +1,40 @@ module OceanSonar -# Write your package code here. +import Base: extrema, Pairs, show, String, Symbol + +using IntervalArithmetic: Interval, interval +using NaNMath: + cos as nan_cos, + hypot as nan_hypot, + sin as nan_sin, + sincos as nan_sincos, + sqrt as nan_sqrt +using Symbolics: Num, Symbolics, Term, wrap, @register_symbolic + +function include_subroots(current_path) + 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 + @debug "Including: $subpath" + subpath + else + error("What is ", subpath, "?") + end |> include + end +end + +include_subroots(@__FILE__) end diff --git a/test/00_quality/aqua.jl b/test/00_quality/aqua.jl new file mode 100644 index 0000000..e2f9071 --- /dev/null +++ b/test/00_quality/aqua.jl @@ -0,0 +1,6 @@ +using OceanSonar +using Aqua + +Aqua.test_all(OceanSonar, + ambiguities = (broken = true,) +) \ No newline at end of file diff --git a/test/00_quality/docstrings.jl b/test/00_quality/docstrings.jl new file mode 100644 index 0000000..f3f754c --- /dev/null +++ b/test/00_quality/docstrings.jl @@ -0,0 +1,6 @@ +using OceanSonar +using Test +using Base.Docs + +undocs = undocumented_names(OceanSonar, private = true) +@test_broken undocs |> isempty \ No newline at end of file diff --git a/test/00_quality/linting.jl b/test/00_quality/linting.jl new file mode 100644 index 0000000..cb29e54 --- /dev/null +++ b/test/00_quality/linting.jl @@ -0,0 +1,4 @@ +using OceanSonar +using JET + +JET.test_package(OceanSonar; target_defined_modules = true) \ No newline at end of file diff --git a/test/Manifest.toml b/test/Manifest.toml deleted file mode 100644 index 3414228..0000000 --- a/test/Manifest.toml +++ /dev/null @@ -1,222 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -julia_version = "1.11.0-rc1" -manifest_format = "2.0" -project_hash = "1f45826613cafa0faebd6512f3b1b9e3efe7eaaf" - -[[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 = "c0216e792f518b39b22212127d4a84dc31e4e386" -uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" -version = "1.3.5" - -[[deps.Compat]] -deps = ["TOML", "UUIDs"] -git-tree-sha1 = "b1c55339b7c6c350ee89f2c1604299660525b248" -uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "4.15.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.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 = "1f209ff8dce4cebff6bfebd2da9cdc0e982874a6" -uuid = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" -version = "0.9.6" - - [deps.JET.extensions] - ReviseExt = "Revise" - - [deps.JET.weakdeps] - Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" - -[[deps.JuliaInterpreter]] -deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"] -git-tree-sha1 = "a6adc2dcfe4187c40dc7c2c9d2128e326360e90a" -uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a" -version = "0.9.32" - -[[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 = "eeaedcf337f33c039f9f3a209a8db992deefd7e9" -uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b" -version = "2.4.8" - -[[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.SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" -version = "0.7.0" - -[[deps.Serialization]] -uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" -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.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 737dfda..ad4ab4f 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,4 +1,6 @@ [deps] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" +OceanSonar = "03019ade-4524-4ecd-af79-46d4f04a1b56" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/runtests.jl b/test/runtests.jl index 0933df7..3fcff12 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,14 +1,12 @@ -using OceanSonar using Test -using Aqua -using JET +using SafeTestsets -@testset "OceanSonar.jl" begin - @testset "Code quality (Aqua.jl)" begin - Aqua.test_all(OceanSonar) +@testset verbose = true "OceanSonar.jl" begin + name = "Code Quality" + @time @testset "$name" begin + @info "Testing $name" + @safetestset "Aqua" include("00_quality/aqua.jl") + @safetestset "Linting" include("00_quality/linting.jl") + @safetestset "Docstrings" include("00_quality/docstrings.jl") end - @testset "Code linting (JET.jl)" begin - JET.test_package(OceanSonar; target_defined_modules = true) - end - # Write your tests here. end