diff --git a/src/utils.jl b/src/utils.jl index 4f8dc2cc..e45c4e71 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1173,6 +1173,23 @@ function InterpolateDataFields2D(Original::CartData, New::CartData; Rotate=0.0, return CartData(New.x.val,New.y.val,Znew, fields_new) end +""" + Surf_interp = InterpolateDataFields2D(V::GeoData, x::AbstractRange, y::AbstractRange; Lat::Number, Lon::Number) + +Interpolates a 3D data set `V` with a projection point `proj=(Lat, Lon)` on a plane defined by `x` and `y`, where `x` and `y` are uniformly spaced. +Returns the 2D array `Surf_interp`. +""" +function InterpolateDataFields2D(V::GeoData, x::AbstractRange, y::AbstractRange; Lat=49.9929, Lon=8.2473) + # Default: Lat=49.9929, Lon=8.2473 => Mainz (center of universe) + proj = ProjectionPoint(; Lat = Lat, Lon = Lon) + return InterpolateDataFields2D(V::GeoData, proj, x, y) +end + +function InterpolateDataFields2D(LonLat::GeoData, proj::ProjectionPoint, x::AbstractRange, y::AbstractRange) + cart_grid = CartData(XYZGrid(x, y, 0)) + tproj = ProjectCartData(cart_grid, LonLat, proj) + return tproj.z.val[:, :, 1] +end """ InterpolateDataFields2D_vecs(x_vec, y_vec, depth, fields_new, X, Y) @@ -1326,19 +1343,7 @@ function InterpolateDataOnSurface(V::GeoData, Surf::GeoData) return Surf_interp end - -""" - Surf_interp = InterpolateTopographyOnPlane(V::GeoData, proj::ProjectionPoint, x::AbstractRange, y::AbstractRange) - -Interpolates a 3D data set `V` with a projection point `proj` on a plane defined by `x` and `y`, where are uniformly spaced. -Returns the 2D array `Surf_interp`. -""" -function InterpolateTopographyOnPlane(V::GeoData, proj::ProjectionPoint, x::AbstractRange, y::AbstractRange) - cart_grid = CartData(XYZGrid(x, y, 0)) - tproj = ProjectCartData(cart_grid, V, proj) - return tproj.z.val[:, :, 1] -end - + # Extracts a sub-data set using indices function ExtractDataSets(V::AbstractGeneralGrid, iLon, iLat, iDepth) diff --git a/test/test_utils.jl b/test/test_utils.jl index 573fe49d..e2f28e83 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -10,6 +10,16 @@ Vx1,Vy1,Vz1 = Data1*3,Data1*4,Data1*5 Data_set2D = GeoData(Lon,Lat,Depth,(Depthdata=Data1,LonData1=Lon, Velocity=(Vx1,Vy1,Vz1))) @test_throws ErrorException CrossSection(Data_set2D, Depth_level=-10) +# Test interpolation of depth to a given cartesian XY-plane +x = 11:19 +y = 31:39 +plane1 = InterpolateDataFields2D(Data_set2D, x, y) +proj = ProjectionPoint() +plane2 = InterpolateDataFields2D(Data_set2D, proj, x, y) + +@test plane1 == plane2 +@test all(==(-50e0), plane1) + # Create 3D volume with some fake data Lon,Lat,Depth = LonLatDepthGrid(10:20,30:40,(-300:25:0)km); Data = Depth*2; # some data