Skip to content

Commit

Permalink
add interpolate_datafields_2D for GeoData; fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
boriskaus committed Jul 4, 2024
1 parent acf552b commit d475e77
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
19 changes: 14 additions & 5 deletions ext/GLMakie_Visualisation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ end
in-place heatmap for a 2D GeoData object (surface),
"""
function heatmap!(x::GeoData, args...; field=:Topography, kwargs...)
@assert size(x.z.val,3)==1
@assert size(x.depth.val,3)==1
@assert hasfield(typeof(x.fields), field)

heatmap(x.lon.val[:,1], x.lat.val[1,:], ustrip.(x.fields[field][:,:,1]), args...; kwargs...)
Expand All @@ -345,7 +345,7 @@ end
in-place heatmap for a 2D GeoData object (surface) with an array `a`.
"""
function heatmap!(x::GeoData, a::Array{_T,N}, args...; kwargs...) where{_T,N}
@assert size(x.z.val,3)==1
@assert size(x.depth.val,3)==1

if N==3
heatmap!(x.lon.val[:,1], x.lat.val[1,:], ustrip.(a[:,:,1]), args...; kwargs...)
Expand All @@ -356,14 +356,23 @@ function heatmap!(x::GeoData, a::Array{_T,N}, args...; kwargs...) where{_T,N}
end

"""
heatmap!(x::CartData, args...; field=:Topography, kwargs...)
heatmap!(x::CartData, args...; field=:Topography, colorbar=false, kwargs...)
in-place heatmap for a 2D CartData object (surface)
"""
function heatmap!(x::CartData, args...; field=:Topography, kwargs...)
function heatmap!(x::CartData, args...; field=:Topography, colorbar=false, kwargs...)
@assert size(x.z.val,3)==1
@assert hasfield(typeof(x.fields), field)

heatmap!(x.x.val[:,1], x.y.val[1,:], ustrip.(x.fields[field][:,:,1]), args...; kwargs...)
data = ustrip.(x.fields[field][:,:,1])

fig,ax,hm = heatmap!(x.x.val[:,1], x.y.val[1,:], data, args...; kwargs...)

cb = nothing
if colorbar
cb = Colorbar(fig[1,2], limits=extrema(filter(!isnan,x.fields[field])), label=field)
end

return fig_out
end

"""
Expand Down
28 changes: 28 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,34 @@ function interpolate_datafields_2D(Original::CartData, New::CartData; Rotate=0.0
return CartData(New.x.val,New.y.val,Znew, fields_new)
end

"""
interpolate_datafields_2D(Original::GeoData, New::GeoData; Rotate=0.0, Translate=(0,0,0), Scale=(1.0,1.0,1.0))
Interpolates a data field `Original` on a 2D GeoData grid `New`.
Typically used for horizontal surfaces.
Note: `Original` should have orthogonal coordinates. If it has not, e.g., because it was rotated, you'll have to specify the angle `Rotate` that it was rotated by
"""
function interpolate_datafields_2D(Original::GeoData, New::GeoData; Rotate=0.0, Translate=(0.0,0.0,0.0), Scale=(1.0,1.0,1.0))
if (Rotate!=0.0) || any(Translate .!= (0,0,0)) || any(Scale .!= (1.0,1.0,1.0))
Original_r = rotate_translate_scale(Original, Rotate = -1.0*Rotate, Translate = -1.0.*Translate, Scale=Scale);
New_r = rotate_translate_scale(New, Rotate = -1.0*Rotate, Translate = -1.0.*Translate, Scale=Scale);
else
Original_r = Original;
New_r = New;
end

Lon_vec = Original_r.lon.val[:,1,1];
Lat_vec = Original_r.lat.val[1,:,1];

Lon_new = New_r.lon.val
Lat_new = New_r.lat.val
Znew, fields_new = GeophysicalModelGenerator.InterpolateDataFields2D_vecs(Lon_vec, Lat_vec, Original_r.depth, Original_r.fields, Lon_new, Lat_new)

return GeoData(New.lon.val,New.lat.val,Znew, fields_new)
end

"""
Surf_interp = interpolate_datafields_2D(V::GeoData, x::AbstractRange, y::AbstractRange; Lat::Number, Lon::Number)
Expand Down

0 comments on commit d475e77

Please sign in to comment.