Skip to content

Commit 4094505

Browse files
committed
add test
1 parent e4f1977 commit 4094505

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

test/test_utils.jl

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ using GeophysicalModelGenerator
77
Lon,Lat,Depth = lonlatdepth_grid(10:20,30:40,-50km);
88
Data1 = Depth*2; # some data
99
Vx1,Vy1,Vz1 = Data1*3,Data1*4,Data1*5
10-
Data_set2D = GeoData(Lon,Lat,Depth,(Depthdata=Data1,LonData1=Lon, Velocity=(Vx1,Vy1,Vz1)))
11-
Data_set2D0 = GeoData(Lon,Lat,Depth,(Depthdata=Data1,LonData1=Lon))
10+
Data_set2D = GeoData(Lon,Lat,Depth,(Depthdata=Data1,LonData1=Lon, Velocity=(Vx1,Vy1,Vz1)))
11+
Data_set2D0 = GeoData(Lon,Lat,Depth,(Depthdata=Data1,LonData1=Lon))
1212
@test_throws ErrorException cross_section(Data_set2D, Depth_level=-10)
1313

1414
# Test interpolation of depth to a given cartesian XY-plane
@@ -22,7 +22,7 @@ plane2 = interpolate_datafields_2D(Data_set2D, proj, x, y)
2222
Lon1,Lat1,Depth1 = lonlatdepth_grid(12:18,33:39,-50km);
2323
Data2 = Depth1*2; # some data
2424
Vx1,Vy1,Vz1 = Data2*3,Data2*4,Data2*5
25-
Data_set2D_1 = GeoData(Lon1,Lat1,Depth1,(Depthdata1=Data2,LonData2=Lon1))
25+
Data_set2D_1 = GeoData(Lon1,Lat1,Depth1,(Depthdata1=Data2,LonData2=Lon1))
2626

2727
plane3 = interpolate_datafields_2D(Data_set2D0, Data_set2D_1)
2828
@test sum(plane3.fields.Depthdata) -4900.0km
@@ -35,23 +35,23 @@ plane3 = interpolate_datafields_2D(Data_set2D0, Data_set2D_1)
3535
Lon,Lat,Depth = lonlatdepth_grid(10:20,30:40,(-300:25:0)km);
3636
Data = Depth*2; # some data
3737
Vx,Vy,Vz = ustrip(Data*3)*km/s,ustrip(Data*4)*km/s,ustrip(Data*5)*km/s;
38-
Data_set3D = GeoData(Lon,Lat,Depth,(Depthdata=Data,LonData=Lon, Velocity=(Vx,Vy,Vz)))
38+
Data_set3D = GeoData(Lon,Lat,Depth,(Depthdata=Data,LonData=Lon, Velocity=(Vx,Vy,Vz)))
3939

4040
# Test addfield
41-
Data_set3D = addfield(Data_set3D,"Lat", Lat)
41+
Data_set3D = addfield(Data_set3D,"Lat", Lat)
4242
@test keys(Data_set3D.fields) == (:Depthdata, :LonData, :Velocity, :Lat)
4343

44-
Data_set3D = addfield(Data_set3D,(;Lat, Lon))
44+
Data_set3D = addfield(Data_set3D,(;Lat, Lon))
4545
@test keys(Data_set3D.fields) == (:Depthdata, :LonData, :Velocity, :Lat, :Lon)
4646

4747
# Create 3D cartesian dataset
48-
Data_setCart3D = CartData(Lon,Lat,Depth,(Depthdata=Data,LonData=Lon, Velocity=(Vx,Vy,Vz)))
48+
Data_setCart3D = CartData(Lon,Lat,Depth,(Depthdata=Data,LonData=Lon, Velocity=(Vx,Vy,Vz)))
4949

5050
# Create 3D volume with some fake data
5151
Lon,Lat,Depth = lonlatdepth_grid(10:20,30:40,(0:-25:-300)km);
5252
Data = Depth*2; # some data
5353
Vx,Vy,Vz = ustrip(Data*3)*km/s,ustrip(Data*4)*km/s,ustrip(Data*5)*km/s;
54-
Data_set3D_reverse = GeoData(Lon,Lat,Depth,(Depthdata=Data,LonData=Lon, Velocity=(Vx,Vy,Vz)))
54+
Data_set3D_reverse = GeoData(Lon,Lat,Depth,(Depthdata=Data,LonData=Lon, Velocity=(Vx,Vy,Vz)))
5555

5656
# Create cross-sections in various directions (no interpolation which is default)
5757
test_cross = cross_section(Data_set3D, Depth_level=-100km)
@@ -99,6 +99,20 @@ test_cross = cross_section(Data_set3D, Start=(10,30), End=(20,40), dims=(
9999
#@test size(test_cross_rev.fields[3][2])==(50,100,1)
100100
#@test write_paraview(test_cross_rev, "profile_test_rev")[1]=="profile_test_rev.vts"
101101

102+
# Cross section of a topography
103+
depth_values = [rand(0:0.1:3.5)]
104+
Lon, Lat, Depth =lonlatdepth_grid(10:20, 30:40, depth_values[:]);
105+
Data_Topo = GeoData(Lon, Lat, Depth, (Depthdata=Depth,))
106+
Data_Topo_geo= cross_section(Data_Topo, Start=(10,30), End=(20,40), dims=(50,100), Interpolate=true)
107+
@test Data_Topo_geo isa GeoData
108+
109+
Lon,Lat,Depth = lonlatdepth_grid(5:25,20:50,0);
110+
Depth = cos.(Lon/5).*sin.(Lat)*10;
111+
Data_surf = GeoData(Lon,Lat,Depth,(Z=Depth,));
112+
Data_surf_cart = convert2CartData(Data_surf, proj);
113+
Data_surf_cross = cross_section(Data_surf_cart, Start=(-1693,2500), End=(-1000,3650), dims=(50,100), Interpolate=true)
114+
@test Data_surf_cross isa CartData
115+
102116
# Cross-section with cartesian data
103117
test_cross = cross_section(Data_setCart3D, Lon_level=15, dims=(50,100), Interpolate=true)
104118
@test size(test_cross.fields[3][2])==(1,50,100)
@@ -173,16 +187,16 @@ Data_pert = subtract_horizontalmean(Data, Percentage=true) # 3D w
173187
@test Data_pert[1000] == 0.0
174188

175189
Data2D = Data[:,1,:];
176-
Data_pert = subtract_horizontalmean(Data2D, Percentage=true) # 2D version with units [dp the same along a vertical profile]
190+
Data_pert = subtract_horizontalmean(Data2D, Percentage=true) # 2D version with units [dp the same along a vertical profile]
177191

178-
Data_set2D = GeoData(Lon,Lat,Depth,(Depthdata=Data,LonData=Lon,Pertdata=Data_pert ,Velocity=(Vx,Vy,Vz)))
192+
Data_set2D = GeoData(Lon,Lat,Depth,(Depthdata=Data,LonData=Lon,Pertdata=Data_pert ,Velocity=(Vx,Vy,Vz)))
179193
@test Data_set2D.fields[3][10,8,1] == 0
180194

181195

182196
# Create surface ("Moho")
183197
Lon,Lat,Depth = lonlatdepth_grid(10:20,30:40,-40km);
184198
Depth = Depth + Lon*km; # some fake topography on Moho
185-
Data_Moho = GeoData(Lon,Lat,Depth,(MohoDepth=Depth,LonData=Lon,TestData=(Depth,Depth,Depth)))
199+
Data_Moho = GeoData(Lon,Lat,Depth,(MohoDepth=Depth,LonData=Lon,TestData=(Depth,Depth,Depth)))
186200

187201

188202
# Test intersecting a surface with 2D or 3D data sets
@@ -218,7 +232,7 @@ Data_VoteMap = votemap(Data_set3D_reverse, "Depthdata<-560",dims=(10,10,10))
218232
@test Data_VoteMap.fields[:votemap][101]==0
219233
@test Data_VoteMap.fields[:votemap][100]==1
220234

221-
# Combine 2 datasets
235+
# Combine 2 datasets
222236
Data_VoteMap = votemap([Data_set3D_reverse, Data_set3D], ["Depthdata<-560","LonData>19"],dims=(10,10,10))
223237
@test Data_VoteMap.fields[:votemap][10,9,1]==2
224238
@test Data_VoteMap.fields[:votemap][9 ,9,1]==1
@@ -253,9 +267,9 @@ cross_tmp = cross_section(Data_EQ,Lat_level=36.2,section_width=10km)
253267
@test cross_tmp.fields.lat_proj[10]==36.2 # check if the projected latitude level is the chosen one
254268

255269
cross_tmp = cross_section(Data_EQ,Lon_level=16.4,section_width=10km)
256-
@test cross_tmp.fields.lon_proj[10]==16.4 # check if the projected longitude level is the chosen one
270+
@test cross_tmp.fields.lon_proj[10]==16.4 # check if the projected longitude level is the chosen one
257271
cross_tmp = cross_section(Data_EQ,Start=(15.0,35.0),End=(17.0,37.0),section_width=10km)
258-
@test cross_tmp.fields.lon_proj[20] ==15.314329874961091
272+
@test cross_tmp.fields.lon_proj[20] ==15.314329874961091
259273
@test cross_tmp.fields.lat_proj[20] == 35.323420618580585
260274

261275
# test inPolygon

0 commit comments

Comments
 (0)