Skip to content

Commit 4118b22

Browse files
committed
add tests for removefield; allow specifying an Tuple of fields to be removed
1 parent fa2496d commit 4118b22

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/utils.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ function removefield(V::AbstractGeneralGrid,field_name::Symbol)
120120
return V
121121
end
122122

123-
124123
"""
125124
V = removefield(V::AbstractGeneralGrid,field_name::String)
126125
@@ -131,6 +130,21 @@ function removefield(V::AbstractGeneralGrid,field_name::String)
131130
return removefield(V,Symbol(field_name))
132131
end
133132

133+
"""
134+
V = removefield(V::AbstractGeneralGrid,field_name::NTuple{N,Symbol})
135+
136+
Removes the fields in the tuple `field_name` from the GeoData or CartData dataset
137+
138+
"""
139+
function removefield(V::AbstractGeneralGrid,field_name::NTuple{N,Symbol}) where N
140+
141+
for ifield=1:N
142+
V = removefield(V,field_name[ifield])
143+
end
144+
145+
return V
146+
end
147+
134148

135149
"""
136150
cross_section_volume(Volume::AbstractGeneralGrid; dims=(100,100), Interpolate=false, Depth_level=nothing; Lat_level=nothing; Lon_level=nothing; Start=nothing, End=nothing, Depth_extent=nothing )
@@ -1831,3 +1845,6 @@ function inpoly_fast(PolyX::Vector{T}, PolyY::Vector{T}, x::T, y::T) where T <:
18311845
end
18321846
return inside
18331847
end
1848+
1849+
1850+

test/test_utils.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ Data_set3D = addfield(Data_set3D,"Lat", Lat)
4444
Data_set3D = addfield(Data_set3D,(;Lat, Lon))
4545
@test keys(Data_set3D.fields) == (:Depthdata, :LonData, :Velocity, :Lat, :Lon)
4646

47+
# test removefield
48+
Data_set3D_1 = removefield(Data_set3D,"Lon")
49+
@test keys(Data_set3D_1.fields) == (:Depthdata, :LonData, :Velocity, :Lat)
50+
51+
Data_set3D_2 = removefield(Data_set3D,:Lon)
52+
@test keys(Data_set3D_2.fields) == (:Depthdata, :LonData, :Velocity, :Lat)
53+
54+
Data_set3D_3 = removefield(Data_set3D,(:Lon,:Lat))
55+
@test keys(Data_set3D_3.fields) == (:Depthdata, :LonData, :Velocity)
56+
4757
# Create 3D cartesian dataset
4858
Data_setCart3D = CartData(Lon,Lat,Depth,(Depthdata=Data,LonData=Lon, Velocity=(Vx,Vy,Vz)))
4959

0 commit comments

Comments
 (0)