diff --git a/Project.toml b/Project.toml index 1a5994fb6..24b487826 100644 --- a/Project.toml +++ b/Project.toml @@ -25,10 +25,12 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" [weakdeps] CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" +Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" [extensions] DimensionalDataCategoricalArraysExt = "CategoricalArrays" +DimensionalDataInterpolations = "Interpolations" DimensionalDataMakie = "Makie" [compat] @@ -51,6 +53,7 @@ Extents = "0.1" ImageFiltering = "0.7" ImageTransformations = "0.10" Interfaces = "0.3" +Interpolations = "0.15" IntervalSets = "0.5, 0.6, 0.7" InvertedIndices = "1" IteratorInterfaceExtensions = "1" @@ -85,6 +88,7 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" ImageFiltering = "6a3955dd-da59-5b1f-98d4-e7296123deb5" ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795" +Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" @@ -95,4 +99,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [targets] -test = ["Aqua", "ArrayInterface", "BenchmarkTools", "CategoricalArrays", "ColorTypes", "Combinatorics", "CoordinateTransformations", "DataFrames", "Distributions", "Documenter", "ImageFiltering", "ImageTransformations", "CairoMakie", "OffsetArrays", "Plots", "Random", "SafeTestsets", "StatsPlots", "Test", "Unitful"] +test = ["Aqua", "ArrayInterface", "BenchmarkTools", "CategoricalArrays", "ColorTypes", "Combinatorics", "CoordinateTransformations", "DataFrames", "Distributions", "Documenter", "ImageFiltering", "ImageTransformations", "Interpolations", "CairoMakie", "OffsetArrays", "Plots", "Random", "SafeTestsets", "StatsPlots", "Test", "Unitful"] diff --git a/ext/DimensionalDataInterpolations.jl b/ext/DimensionalDataInterpolations.jl new file mode 100644 index 000000000..29f5997ae --- /dev/null +++ b/ext/DimensionalDataInterpolations.jl @@ -0,0 +1,13 @@ +module DimensionalDataInterpolations + +using DimensionalData, Interpolations + +function Interpolations.linear_interpolation(A::AbstractDimArray; kw...) + linear_interpolation(DimensionalData.index(dims(A)), A; kw...) +end + +function Interpolations.cubic_spline_interpolation(A::AbstractDimArray; kw...) + cubic_spline_interpolation(DimensionalData.index(dims(A)), A; kw...) +end + +end \ No newline at end of file diff --git a/test/interpolations.jl b/test/interpolations.jl new file mode 100644 index 000000000..d9c523da7 --- /dev/null +++ b/test/interpolations.jl @@ -0,0 +1,23 @@ +using DimensionalData +using Interpolations + +f((x1, x2)) = log(x1+x2) +a = f.(DimPoints((X(1:1:10), Y(1:1.5:20)))) +b = f.(DimPoints((X(1:1:10), Y([1.0,3,7.5,10,15])))) +to = rand(X(2:.3:7), Y(2:.3:17)) +# out = DimensionalData.interp(A; to) + +itp_a = linear_interpolation(a) +itp_b = linear_interpolation(b) +itp_ex = linear_interpolation(a, extrapolation_bc=(Flat(), Linear())) + +itp_a(7.5,7.5) +itp_b(7.5,7.5) +itp_ex(10,13) +itp_ex(11,13) +itp_ex(10,14) + +itp_ca = cubic_spline_interpolation(a) +# itp_cb = cubic_spline_interpolation(b) #fails, as expected + +itp_ca(10,10) \ No newline at end of file