Skip to content

Commit 3e83725

Browse files
authored
Merge pull request #176 from JuliaGeodynamics/mt_profiledata
Added a screenshot field to the ProfileData structure
2 parents f3444c8 + aba28cb commit 3e83725

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/ProfileProcessing.jl

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Structure that holds profile data (interpolated/projected on the profile)
1717
VolData :: GeophysicalModelGenerator.GeoData
1818
SurfData :: Union{Nothing, NamedTuple}
1919
PointData :: Union{Nothing, NamedTuple}
20+
ScreenshotData :: Union{Nothing, NamedTuple}
2021
end
2122
2223
Structure to store cross section data
@@ -29,6 +30,7 @@ mutable struct ProfileData
2930
VolData::Union{Nothing, GeophysicalModelGenerator.GeoData}
3031
SurfData::Union{Nothing, NamedTuple}
3132
PointData::Union{Nothing, NamedTuple}
33+
ScreenshotData::Union{Nothing, NamedTuple}
3234

3335
function ProfileData(; kwargs...) # this constructor allows to define only certain fields and leave the others blank
3436
K = new(true, nothing, nothing, nothing, nothing, nothing, nothing)
@@ -51,7 +53,6 @@ mutable struct ProfileData
5153
end
5254
end
5355

54-
5556
function show(io::IO, g::ProfileData)
5657
if g.vertical
5758
println(io, "Vertical ProfileData")
@@ -69,7 +70,9 @@ function show(io::IO, g::ProfileData)
6970
if !isnothing(g.PointData)
7071
println(io, " PointData: $(keys(g.PointData)) ")
7172
end
72-
73+
if !isnothing(g.ScreenshotData)
74+
println(io, " ScreenshotData: $(keys(g.ScreenshotData)) ")
75+
end
7376
return nothing
7477
end
7578

@@ -282,6 +285,31 @@ function create_profile_volume!(Profile::ProfileData, VolData::AbstractGeneralGr
282285
return nothing
283286
end
284287

288+
### internal function to process screenshot data - contrary to the volume data, we here have to save lon/lat/depth pairs for every screenshot data set, so we create a NamedTuple of GeoData data sets
289+
function create_profile_screenshot!(Profile::ProfileData, DataSet::NamedTuple)
290+
num_datasets = length(DataSet)
291+
292+
tmp = NamedTuple() # initialize empty one
293+
DataSetName = keys(DataSet) # Names of the datasets
294+
295+
for idata in 1:num_datasets
296+
# load data set --> each data set is a single GeoData structure, so we'll only have to get the respective key to load the correct type
297+
data_tmp = DataSet[idata]
298+
if Profile.vertical
299+
x_profile = flatten_cross_section(data_tmp, Start = Profile.start_lonlat) # compute the distance along the profile
300+
data_tmp = addfield(data_tmp, "x_profile", x_profile)
301+
302+
# add the data set as a NamedTuple
303+
data_NT = NamedTuple{(DataSetName[idata],)}((data_tmp,))
304+
tmp = merge(tmp, data_NT)
305+
else
306+
# we do not have this implemented
307+
#error("horizontal profiles not yet implemented")
308+
end
309+
end
310+
Profile.SurfData = tmp # assign to profile data structure
311+
return
312+
end
285313

286314
### internal function to process surface data - contrary to the volume data, we here have to save lon/lat/depth pairs for every surface data set, so we create a NamedTuple of GeoData data sets
287315
function create_profile_surface!(Profile::ProfileData, DataSet::NamedTuple; DimsSurfCross = (100,))
@@ -362,21 +390,38 @@ end
362390

363391

364392
"""
365-
extract_ProfileData!(Profile::ProfileData,VolData::GeoData, SurfData::NamedTuple, PointData::NamedTuple; DimsVolCross=(100,100),Depth_extent=nothing,DimsSurfCross=(100,),section_width=50)
393+
extract_ProfileData!(Profile::ProfileData,VolData::GeoData, SurfData::NamedTuple, PointData::NamedTuple, ScreenshotData::NamedTuple; DimsVolCross=(100,100),Depth_extent=nothing,DimsSurfCross=(100,),section_width=50)
366394
367395
Extracts data along a vertical or horizontal profile
368396
"""
369-
function extract_ProfileData!(Profile::ProfileData, VolData::Union{Nothing, GeoData} = nothing, SurfData::NamedTuple = NamedTuple(), PointData::NamedTuple = NamedTuple(); DimsVolCross = (100, 100), Depth_extent = nothing, DimsSurfCross = (100,), section_width = 50km)
397+
function extract_ProfileData!(Profile::ProfileData, VolData::Union{Nothing, GeoData} = nothing, SurfData::NamedTuple = NamedTuple(), PointData::NamedTuple = NamedTuple(),ScreenshotData::NamedTuple = NamedTuple(); DimsVolCross = (100, 100), Depth_extent = nothing, DimsSurfCross = (100,), section_width = 50km)
370398

371399
if !isnothing(VolData)
372400
create_profile_volume!(Profile, VolData; DimsVolCross = DimsVolCross, Depth_extent = Depth_extent)
373401
end
374402
create_profile_surface!(Profile, SurfData, DimsSurfCross = DimsSurfCross)
375403
create_profile_point!(Profile, PointData, section_width = section_width)
404+
if !isempty(ScreenshotData)
405+
create_profile_screenshot!(Profile, ScreenshotData)
406+
end
407+
return nothing
408+
end
376409

410+
"""
411+
extract_ProfileData!(Profile::ProfileData,VolData::GeoData, SurfData::NamedTuple, PointData::NamedTuple; DimsVolCross=(100,100),Depth_extent=nothing,DimsSurfCross=(100,),section_width=50)
412+
413+
Extracts data along a vertical or horizontal profile.
414+
"""
415+
function extract_ProfileData!(Profile::ProfileData, VolData::Union{Nothing, GeoData} = nothing, SurfData::NamedTuple = NamedTuple(), PointData::NamedTuple = NamedTuple(); DimsVolCross = (100, 100), Depth_extent = nothing, DimsSurfCross = (100,), section_width = 50km)
416+
417+
# call the actual function to extract the profile data
418+
extract_ProfileData!(Profile, VolData, SurfData, PointData,NamedTuple(); DimsVolCross = DimsVolCross, Depth_extent = Depth_extent, DimsSurfCross = DimsSurfCross, section_width = section_width)
377419
return nothing
378420
end
379421

422+
423+
424+
380425
"""
381426
This reads the picked profiles from disk and returns a vector of ProfileData
382427
"""

test/test_ProfileProcessing.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ data_Vol2 = GMG_Dataset("Plomerova2022", "Volume", "https://seafile.rlp.net/f/ab
2222
#data_Vol2 = GMG_Dataset("Zhao2016","Volume","https://seafile.rlp.net/f/e81a6d075f6746609973/?dl=1", true)
2323

2424
# Now load these datasets into NamedTuples
25-
2625
SurfData = load_GMG(data_Surf)
2726
PointData = load_GMG(data_EQ)
2827
ScreenshotData = load_GMG(data_SS)
@@ -59,6 +58,7 @@ prof1 = ProfileData(start_lonlat = (5, 45), end_lonlat = (15, 49))
5958
prof2 = ProfileData(depth = -100)
6059
prof3 = ProfileData(start_lonlat = (5, 45), end_lonlat = (5, 49))
6160
prof4 = ProfileData(depth = -20)
61+
prof5 = ProfileData(start_lonlat = (12, 49), end_lonlat = (12, 45))
6262

6363
# test internal routines to intersect profile with volumetric data:
6464
GeophysicalModelGenerator.create_profile_volume!(prof1, VolData_combined1)
@@ -80,6 +80,10 @@ GeophysicalModelGenerator.create_profile_point!(prof4, Data.Point, section_width
8080
@test length(prof1.PointData[1].lon) == 13
8181
@test length(prof4.PointData[1].lon) == 445
8282

83+
# test screenshot data
84+
GeophysicalModelGenerator.create_profile_screenshot!(prof5, Data.Screenshot)
85+
@test prof5.SurfData[1].fields.x_profile[1,1,1] == 0
86+
8387

8488
# Test the main profile extraction routines:
8589
extract_ProfileData!(prof1, VolData_combined1, Data.Surface, Data.Point)
@@ -96,6 +100,7 @@ extract_ProfileData!(prof1, VolData_combined3, Data.Surface, Data.Point)
96100
extract_ProfileData!(prof2, VolData_combined3, Data.Surface, Data.Point)
97101
extract_ProfileData!(prof3, VolData_combined3, Data.Surface, Data.Point)
98102
extract_ProfileData!(prof4, VolData_combined3, Data.Surface, Data.Point)
103+
extract_ProfileData!(prof5, VolData_combined3, Data.Surface, Data.Point, Data.Screenshot)
99104

100105

101106
# Test that it works if only EQ's are provided:

0 commit comments

Comments
 (0)