3D Vector Field interpolation (maybe with DIVAnd.jl)

Dear community,

I would like to interpolate my 3D Vector Field with DIVAnd.jl (GitHub - gher-uliege/DIVAnd.jl: DIVAnd performs an n-dimensional variational analysis of arbitrarily located observations) without any success. I have the following data: MPCDF DataShare

When I plot the data with PlotlyJS I get the following picture:
(Dots color and size the length of the vectors)

(Vectors size and color length of vectors)

I am now trying to use the example found here which is 2D: https://gher-ulg.github.io/DIVAnd.jl/latest/index.html#Examples

I get stuck when I am trying to use DIVAndrun. Here is my code:

using CSV
using DataFrames
using DIVAnd, PyPlot

data = DataFrame(CSV.File("211107_2025 LOGGER04.mod.csv",header=["X","Y","Z","U","V","W","Mod"]))

x = range(minimum(data[:,1]),stop=maximum(data[:,1]),length=393)
y = range(minimum(data[:,2]),stop=maximum(data[:,2]),length=398)
z = range(minimum(data[:,3]),stop=maximum(data[:,3]),length=300)

mask,(pm,pn,po),(xi,yi,zi) = DIVAnd_rectdom(x,y,z)

# normalized obs. error variance and correlation length
epsilon2 = 1 / 200
len = 0.2

# call DIVAnd
fi, s = DIVAndrun(mask,
            (pm,pn,po),
            (xi,yi,zi),
    (data[:,1],data[:,2],data[:,3]),
            data[:,7],
    len,epsilon2; 
    velocity = (data[:,4]data[:,5],data[:,6])
)

The error is:
MethodError: no method matching *(::Vector{Float64}, ::Vector{Float64})
Closest candidates are:
*(::Any, ::Any, ::Any, ::Any…) at operators.jl:560
*(::StridedMatrix{T}, ::StridedVector{S}) where {T<:Union{Float32, Float64, ComplexF32, ComplexF64}, S<:Real} at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/matmul.jl:44
*(::StridedVecOrMat{T} where T, ::LinearAlgebra.Adjoint{var"#s814", var"#s813"} where {var"#s814", var"#s813"<:LinearAlgebra.LQPackedQ}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/lq.jl:254

Stacktrace:
[1] top-level scope
@ In[13]:2
[2] eval
@ ./boot.jl:360 [inlined]
[3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1116

I know that the Problem lies with the structure of the location of my observation

(data[:,1],data[:,2],data[:,3])

and the velocities

velocity = (data[:,4]data[:,5],data[:,6])

I do not know how to transform them into tuples with n elements which says the documentation. Has anybody a clue?

If there is a smarter way to do this, please let me know.

Thanks

1 Like

Know nothing about that very interesting package but for the question quoted the following might help:

x = [1.0, 2, 3, 4]    # 4-element Vector{Float64}
xt = Tuple(x)         # NTuple{4, Float64}
1 Like

Presently DIVAnd works only on scalar fields. So one way is to interpolate/analyse each velocity component independently and then reassemble afterwards. Quick and easy (if your entry data contain the vector components)

That however completely ignores that it is a vector field on which you might want to add some more constraints (like non-divergence for incompressible flows). A way to do this is explained here for 2D surface currents:

https://github.com/gher-ulg/DIVAnd_HFRadar.jl

1 Like

Please also note that when referring to the advection constraint in DIVAnd, we mean that you provide a velocity field which is used to guide the interpolation of the scalar field you want to analyse/interpolate. So the parameter “velocity” is NOT meant to allow for an interpolation of a velocity field into a regular grid but is there so that the user can provide the velocity field on a regular grid and which can help during the interpolation of sparse data of a scalar onto a regular grid.
Hope it clarifies ?

1 Like

By the way, a simple and efficient way to make the analysis componentwise (assuming you have all three components at the same location) is explained here:

DIVAnd.jl documentation · DIVAnd?

1 Like