Help Interpolating Data (4D data cube)

Hi, I got a few question on how to interpolate some models of mine.

My goal is to interpolate the full data cube made from each of my diffraction grating models then, given some initial requirements, retrieve a simple line plot. I currently have three models, model 10, 20, and 30, each containing their own wavelength (Vector{Float64}), depth (Vector{Float64}), and efficiency (Matrix{Float64}) components.

I was able to interpolate my data in 3D space for a single model and pull out my line. Here is a simple version of that code:

function single_interp(mod, δ) #Single model
    #Model interpolation
    x = mod["wavelength"]
    y = mod["depth"]
    z = mod["efficiency"]

    itp = LinearInterpolation((x, y), z)
    # Find grid
    x2 = range(extrema(x)..., length=300)
    y2 = range(extrema(y)..., length=300)
    # Interpolate
    z2 = [itp(x,δ) for x in x2] # δ = desired etching depth we want to look at

    p = lines(x2,z2)
    return x2, y2, z2

Similarly to this, I want to interpolate between my 3 models and make a similar line plot. Each model covers the same depth and wavelength range, and the model number represents a physical attribute being changed in the models (10, 20, or 30% change to the period of the diffraction grating in this case), so I want to make a function looking similar to:

function multiple_interp(mod, δ, W)

where the W can be a single value (say 15) that represents the interpolated data between any two models. I’m getting stuck on how to bring in all my models into the interpolation function. Later I’ll be moving to adding other models too representing some other change in the grating, so I’ll need to similar function in a 5d and/or 6D data cube too, but figuring out how it works in 4D is my main goal here.

Any help is appreciated, especially since I’m fairly new at working with Julia and data cubes!

Is this the kind of transformation you are looking for?

julia> using Interpolations

julia> wavelength=200:10:700;

julia> depth=1:10;

julia> W=[10, 20, 30];

julia> efficiency_10=rand(length(wavelength), length(depth));

julia> efficiency_20=rand(length(wavelength), length(depth));

julia> efficiency_30=rand(length(wavelength), length(depth));

julia> efficiency = stack([efficiency_10, efficiency_20, efficiency_30]; dims=3);

julia> size(efficiency)
(51, 10, 3)

julia> itp = interpolate((wavelength, depth, W), efficiency, Gridded(Linear()));