Skip to content

Commit

Permalink
Toying around with spatial data interpolations
Browse files Browse the repository at this point in the history
  • Loading branch information
kapple19 committed Aug 24, 2024
1 parent e278c85 commit b3f5958
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
67 changes: 67 additions & 0 deletions prototyping/profiles.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
abstract type SpatialData end

abstract type SpatialData2D <: SpatialData end
abstract type SpatialData3D <: SpatialData end

struct SpatialDataCylindrical3D <: SpatialData3D
r::Vector{Float64}
z::Vector{Float64}
θ::Vector{Float64}
F::Array{Float64, 3}
itp::AbstractInterpolation
end

struct SpatialDataCylindrical2D <: SpatialData2D
r
z
end

function SpatialDataCylindrical3D()

end

struct SoundSpeedProfileData
r::Vector{Float64}
z::Vector{Float64}
θ::Vector{Float64}
c::Array{Float64, 3}
itp::AbstractInterpolation
end

sound_speed_profile_data = Dict{Symbol, SpatialData}

function sound_speed_profile(model, z; pars...)

end

struct SoundSpeedProfile <: Function
model::Model{M} where {M}
ranges::Vector{Float64}
depths::Vector{Float64}
azimuths::Vector{Float64}
sound_speeds::Array{Float64, 3}
itp::AbstractInterpolation

function SoundSpeedProfile(
model::Model{M},
ranges::Vector{Float64},
depths::Vector{Float64},
azimuths::Vector{Float64},
sound_speeds::Array{Float64, 3},
itp::AbstractInterpolation,
) where {M}
for r in ranges, z in depths, θ in azimuths
@assert itp(r, z, θ) isa Real
end
new(model, ranges, depths, azimuths, sound_speeds, itp)
end
end

function SoundSpeedProfile()

end

## Usage
sound_speed_profile(:Munk, z; ϵ)
c = SoundSpeedProfile(:Munk; ϵ)
c.itp
98 changes: 98 additions & 0 deletions prototyping/profiles2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
## Sound Speed Profile Data Storage Mechanism
using DataInterpolations

## Modelling
struct Model{M} end

## Interpolation
Interpolation(::Model{:Linear}, args...; extrapolate = true, kws...) = LinearInterpolation(args...; extrapolate = extrapolate, kws...)

## Data
abstract type SpatialData end

(data::SpatialData)(args::Real...) = data.fcn(args::Real...)

abstract type SpatialData1D <: SpatialData end
abstract type SpatialData2D <: SpatialData end
abstract type SpatialData3D <: SpatialData end

struct SpatialData1D_DepthProfile <: SpatialData1D
fcn::AbstractInterpolation
z::Vector{Float64}
F::Vector{Float64}

function SpatialData1D_DepthProfile(model::Model, z::AbstractVector{<:Real}, F::AbstractVector{<:Real})
@assert issorted(z)
@assert (F, z) .|> length |> isequal
fcn = Interpolation(model, F, z)
new(fcn, F, z)
end
end

struct SpatialData2D_DepthProfiles_Ranges <: SpatialData2D
fcn::Function
r::Vector{Float64}
zF::Vector{SpatialData1D_DepthProfile}

function SpatialData2D_DepthProfiles_Ranges{}(
model::Model,
r::AbstractVector{<:Real},
zF::AbstractVector{<:SpatialData1D_DepthProfile}
) where {N}
@assert issorted(r)
@assert (zF, r) .|> length |> isequal
Fz_data = [SpatialData1D_DepthProfile(depth_model, zF_...) for zF_ in zF]
append = r[end] |> isfinite
r_vals = copy(r)
if append
push!(r_vals, Inf)
end

function fcn(r_::Real, z_::Real)
@assert 0 r_
F_vals = [Fz_data_(z_) for Fz_data_ in Fz_data] # can optimize this to just the surrounding `r_` profiles.
if append
push!(F_vals, F_vals[end])
end
itp = Interpolation(range_model, F_vals, r_) # needs to construct a new interpolation object for each call?!
return itp(r_)
end
new(fcn, r, Fz_data)
end
end

function SpatialData2D_DepthProfiles_Ranges(
range_model::Model,
depth_model::Model,
r::AbstractVector{<:Real},
z::AbstractVector{<:Real},
F::AbstractMatrix{<:Real},
)
SpatialData2D_DepthProfiles_Ranges(
range_model, depth_model,
r,
(
(z, F[:, nr])
for nr in eachindex(r)
)
)
end

struct SpatialData3D_DepthProfiles_Ranges_Azimuths <: SpatialData3D
fcn::Function
θ::AbstractVector{<:Real}
rzF::Vector{SpatialData2D_RangeDepth}

function SpatialData3D_DepthProfiles_Ranges_Azimuths(
range_model::Model,
depth_model::Model,
azimuth_model::Model,
θ::AbstractVector{<:Real},
rzF::AbstractVector{<:Tuple}
)

end
end

## Usage

0 comments on commit b3f5958

Please sign in to comment.