Skip to content

Commit 229af98

Browse files
committed
Added a screenshot field to the ProfileData structure
To allow screenshots to be saved in ProfileData, I added this field. I also added the respective function create_profile_screenshot! and adapted extract_ProfileData. Tests were also modified.
1 parent 3c83dfe commit 229af98

File tree

2 files changed

+50
-16
lines changed

2 files changed

+50
-16
lines changed

src/ProfileProcessing.jl

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ mutable struct ProfileData
2929
VolData::Union{Nothing, GeophysicalModelGenerator.GeoData}
3030
SurfData::Union{Nothing, NamedTuple}
3131
PointData::Union{Nothing, NamedTuple}
32+
ScreenshotData::Union{Nothing, NamedTuple}
3233

3334
function ProfileData(; kwargs...) # this constructor allows to define only certain fields and leave the others blank
3435
K = new(true, nothing, nothing, nothing, nothing, nothing, nothing)
@@ -282,6 +283,31 @@ function create_profile_volume!(Profile::ProfileData, VolData::AbstractGeneralGr
282283
return nothing
283284
end
284285

286+
### 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
287+
function create_profile_screenshot!(Profile::ProfileData, DataSet::NamedTuple)
288+
num_datasets = length(DataSet)
289+
290+
tmp = NamedTuple() # initialize empty one
291+
DataSetName = keys(DataSet) # Names of the datasets
292+
293+
for idata in 1:num_datasets
294+
# 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
295+
data_tmp = DataSet[idata]
296+
if Profile.vertical
297+
x_profile = flatten_cross_section(data_tmp, Start = Profile.start_lonlat) # compute the distance along the profile
298+
data_tmp = addfield(data_tmp, "x_profile", x_profile)
299+
300+
# add the data set as a NamedTuple
301+
data_NT = NamedTuple{(DataSetName[idata],)}((data_tmp,))
302+
tmp = merge(tmp, data_NT)
303+
else
304+
# we do not have this implemented
305+
#error("horizontal profiles not yet implemented")
306+
end
307+
end
308+
Profile.SurfData = tmp # assign to profile data structure
309+
return
310+
end
285311

286312
### 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
287313
function create_profile_surface!(Profile::ProfileData, DataSet::NamedTuple; DimsSurfCross = (100,))
@@ -362,18 +388,20 @@ end
362388

363389

364390
"""
365-
extract_ProfileData!(Profile::ProfileData,VolData::GeoData, SurfData::NamedTuple, PointData::NamedTuple; DimsVolCross=(100,100),Depth_extent=nothing,DimsSurfCross=(100,),section_width=50)
391+
extract_ProfileData!(Profile::ProfileData,VolData::GeoData, SurfData::NamedTuple, PointData::NamedTuple, ScreenshotData::NamedTuple; DimsVolCross=(100,100),Depth_extent=nothing,DimsSurfCross=(100,),section_width=50)
366392
367393
Extracts data along a vertical or horizontal profile
368394
"""
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)
395+
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)
370396

371397
if !isnothing(VolData)
372398
create_profile_volume!(Profile, VolData; DimsVolCross = DimsVolCross, Depth_extent = Depth_extent)
373399
end
374400
create_profile_surface!(Profile, SurfData, DimsSurfCross = DimsSurfCross)
375401
create_profile_point!(Profile, PointData, section_width = section_width)
376-
402+
if !isempty(ScreenshotData)
403+
create_profile_screenshot!(Profile, ScreenshotData)
404+
end
377405
return nothing
378406
end
379407

test/test_ProfileProcessing.jl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ prof1 = ProfileData(start_lonlat = (5, 45), end_lonlat = (15, 49))
5959
prof2 = ProfileData(depth = -100)
6060
prof3 = ProfileData(start_lonlat = (5, 45), end_lonlat = (5, 49))
6161
prof4 = ProfileData(depth = -20)
62+
prof5 = ProfileData(start_lonlat = (12, 49), end_lonlat = (12, 45))
6263

6364
# test internal routines to intersect profile with volumetric data:
6465
GeophysicalModelGenerator.create_profile_volume!(prof1, VolData_combined1)
@@ -80,27 +81,32 @@ GeophysicalModelGenerator.create_profile_point!(prof4, Data.Point, section_width
8081
@test length(prof1.PointData[1].lon) == 13
8182
@test length(prof4.PointData[1].lon) == 445
8283

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

8489
# Test the main profile extraction routines:
85-
extract_ProfileData!(prof1, VolData_combined1, Data.Surface, Data.Point)
86-
extract_ProfileData!(prof2, VolData_combined1, Data.Surface, Data.Point)
87-
extract_ProfileData!(prof3, VolData_combined1, Data.Surface, Data.Point)
88-
extract_ProfileData!(prof4, VolData_combined1, Data.Surface, Data.Point)
90+
extract_ProfileData!(prof1, VolData_combined1, Data.Surface, Data.Point, NamedTuple())
91+
extract_ProfileData!(prof2, VolData_combined1, Data.Surface, Data.Point, NamedTuple())
92+
extract_ProfileData!(prof3, VolData_combined1, Data.Surface, Data.Point, NamedTuple())
93+
extract_ProfileData!(prof4, VolData_combined1, Data.Surface, Data.Point, NamedTuple())
8994

90-
extract_ProfileData!(prof1, VolData_combined2, Data.Surface, Data.Point)
91-
extract_ProfileData!(prof2, VolData_combined2, Data.Surface, Data.Point)
92-
extract_ProfileData!(prof3, VolData_combined2, Data.Surface, Data.Point)
93-
extract_ProfileData!(prof4, VolData_combined2, Data.Surface, Data.Point)
95+
extract_ProfileData!(prof1, VolData_combined2, Data.Surface, Data.Point, NamedTuple())
96+
extract_ProfileData!(prof2, VolData_combined2, Data.Surface, Data.Point, NamedTuple())
97+
extract_ProfileData!(prof3, VolData_combined2, Data.Surface, Data.Point, NamedTuple())
98+
extract_ProfileData!(prof4, VolData_combined2, Data.Surface, Data.Point, NamedTuple())
9499

95-
extract_ProfileData!(prof1, VolData_combined3, Data.Surface, Data.Point)
96-
extract_ProfileData!(prof2, VolData_combined3, Data.Surface, Data.Point)
97-
extract_ProfileData!(prof3, VolData_combined3, Data.Surface, Data.Point)
98-
extract_ProfileData!(prof4, VolData_combined3, Data.Surface, Data.Point)
100+
extract_ProfileData!(prof1, VolData_combined3, Data.Surface, Data.Point, NamedTuple())
101+
extract_ProfileData!(prof2, VolData_combined3, Data.Surface, Data.Point, NamedTuple())
102+
extract_ProfileData!(prof3, VolData_combined3, Data.Surface, Data.Point, NamedTuple())
103+
extract_ProfileData!(prof4, VolData_combined3, Data.Surface, Data.Point, NamedTuple())
104+
extract_ProfileData!(prof5, VolData_combined3, Data.Surface, Data.Point, Data.Screenshot)
99105

100106

101107
# Test that it works if only EQ's are provided:
102108
prof4 = ProfileData(depth = -20)
103-
extract_ProfileData!(prof4, nothing, NamedTuple(), Data.Point)
109+
extract_ProfileData!(prof4, nothing, NamedTuple(), Data.Point, NamedTuple())
104110
@test isnothing(prof4.VolData)
105111
@test isempty(prof4.SurfData)
106112
@test length(prof4.PointData[1].depth) == 3280

0 commit comments

Comments
 (0)