# Help Interpolating Data (4D data cube)

**URL:** https://discourse.julialang.org/t/help-interpolating-data-4d-data-cube/98868
**Category:** New to Julia
**Tags:** question, dataframes, interpolations
**Created:** [May 15, 2023, 9:38am UTC](https://discourse.julialang.org/t/help-interpolating-data-4d-data-cube/98868 "2023-05-15T09:38:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![HNormanW](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hnormanw/32/49796_2.png) [@HNormanW](https://discourse.julialang.org/u/HNormanW)
#### Post date: [May 15, 2023, 9:38am UTC](https://discourse.julialang.org/t/help-interpolating-data-4d-data-cube/98868/1 "2023-05-15T09:38:07Z")

</div>

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)
    display(p)
    return x2, y2, z2
end

```

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!

---

<div class="post-metadata">

### Author: ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)
#### Post date: [May 15, 2023, 4:59pm UTC](https://discourse.julialang.org/t/help-interpolating-data-4d-data-cube/98868/2 "2023-05-15T16:59:21Z")

</div>

Is this the kind of transformation you are looking for?

```julia
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()));

```
