Skip to content

Commit

Permalink
Merge pull request #66 from albert-de-montserrat/adm/conflict
Browse files Browse the repository at this point in the history
Rework `InterpolateTopographyOnPlane` as a `InterpolateDataFields2D` method
  • Loading branch information
mthielma authored Feb 29, 2024
2 parents 853d36e + 78c7be0 commit 148f3ef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 148f3ef

Please sign in to comment.