Skip to content

Commit e4f1977

Browse files
committed
fix GeoData export
1 parent 23d9d4a commit e4f1977

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/utils.jl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ addfield(V::GeoData,new_fields::NamedTuple) = GeoData(V.lon.val, V.lat.val, V.de
7070
7171
Add `new_fields` fields to a `Q1Data` dataset; set `cellfield` to `true` if the field is a cell field; otherwise it is a vertex field
7272
"""
73-
function addfield(V::Q1Data,new_fields::NamedTuple; cellfield=false)
73+
function addfield(V::Q1Data,new_fields::NamedTuple; cellfield=false)
7474
if cellfield
7575
return Q1Data(V.x.val, V.y.val, V.z.val, V.fields, merge(V.cellfields, new_fields))
7676
else
@@ -122,7 +122,7 @@ end
122122

123123

124124

125-
"""
125+
"""
126126
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 )
127127
128128
Creates a cross-section through a volumetric (3D) `GeoData` object.
@@ -259,7 +259,7 @@ cross_section_surface(Surface::GeoData; dims=(100,), Interpolate=false, Depth_le
259259
Creates a cross-section through a surface (2D) `GeoData` object.
260260
261261
- Cross-sections can be horizontal (map view at a given depth), if `Depth_level` is specified
262-
- They can also be vertical, either by specifying `Lon_level` or `Lat_level` (for a fixed lon/lat), or by defining both `Start=(lon,lat)` & `End=(lon,lat)` points.
262+
- They can also be vertical, either by specifying `Lon_level` or `Lat_level` (for a fixed lon/lat), or by defining both `Start=(lon,lat)` & `End=(lon,lat)` points. Start and End points will be in km!
263263
264264
- IMPORTANT: The surface to be extracted has to be given as a gridded GeoData object. It may also contain NaNs where it is not defined. Any points lying outside of the defined surface will be considered NaN.
265265
@@ -351,9 +351,14 @@ function cross_section_surface(S::AbstractGeneralGrid; dims=(100,), Interpolate=
351351

352352
end
353353

354-
# create GeoData structure with the interpolated points
355-
Data_profile = GeoData(Lon, Lat, depth_intp, (fields_new));
356-
354+
# create GeoData/CartData structure with the interpolated points
355+
if isa(S,GeoData)
356+
Data_profile = GeoData(Lon, Lat, depth_intp, fields_new);
357+
elseif isa(S,CartData)
358+
Data_profile = CartData(Lon, Lat, depth_intp, fields_new);
359+
else
360+
error("still to be implemented")
361+
end
357362
return Data_profile
358363
end
359364

@@ -545,9 +550,9 @@ Creates a cross-section through a `GeoData` object.
545550
julia> Lon,Lat,Depth = lonlatdepth_grid(10:20,30:40,(-300:25:0)km);
546551
julia> Data = Depth*2; # some data
547552
julia> Vx,Vy,Vz = ustrip(Data*3),ustrip(Data*4),ustrip(Data*5);
548-
julia> Data_set3D = GeoData(Lon,Lat,Depth,(Depthdata=Data,LonData=Lon, Velocity=(Vx,Vy,Vz)));
549-
julia> Data_cross = cross_section(Data_set3D, Depth_level=-100km)
550-
GeoData
553+
julia> Data_set3D = GeoData(Lon,Lat,Depth,(Depthdata=Data,LonData=Lon, Velocity=(Vx,Vy,Vz)));
554+
julia> Data_cross = cross_section(Data_set3D, Depth_level=-100km)
555+
GeoData
551556
size : (11, 11, 1)
552557
lon ϵ [ 10.0 : 20.0]
553558
lat ϵ [ 30.0 : 40.0]
@@ -601,7 +606,7 @@ CartData
601606
```
602607
"""
603608
function flatten_cross_section(V::CartData)
604-
609+
605610
x_new = sqrt.((V.x.val.-V.x.val[1,1,1]).^2 .+ (V.y.val.-V.y.val[1,1,1]).^2) # NOTE: the result is in km, as V.x and V.y are stored in km
606611

607612

@@ -1244,11 +1249,11 @@ function interpolate_datafields_2D(Original::GeoData, New::GeoData; Rotate=0.0,
12441249
return GeoData(New.lon.val,New.lat.val,Znew, fields_new)
12451250
end
12461251

1247-
"""
1252+
"""
12481253
Surf_interp = interpolate_datafields_2D(V::GeoData, x::AbstractRange, y::AbstractRange; Lat::Number, Lon::Number)
12491254
12501255
Interpolates a 3D data set `V` with a projection point `proj=(Lat, Lon)` on a plane defined by `x` and `y`, where `x` and `y` are uniformly spaced.
1251-
Returns the 2D array `Surf_interp`.
1256+
Returns the 2D array `Surf_interp`.
12521257
"""
12531258
function interpolate_datafields_2D(V::GeoData, x::AbstractRange, y::AbstractRange; Lat=49.9929, Lon=8.2473)
12541259
# Default: Lat=49.9929, Lon=8.2473 => Mainz (center of universe)
@@ -1340,7 +1345,7 @@ function InterpolateDataFields2D_vecs(EW_vec, NS_vec, depth, fields_new, EW, NS)
13401345

13411346
return depth_new, fields_new
13421347
end
1343-
1348+
13441349
# Extracts a sub-data set using indices
13451350
function ExtractDataSets(V::AbstractGeneralGrid, iLon, iLat, iDepth)
13461351

@@ -1815,4 +1820,4 @@ function inpoly_fast(PolyX::Vector{T}, PolyY::Vector{T}, x::T, y::T) where T <:
18151820
end
18161821
end
18171822
return inside
1818-
end
1823+
end

0 commit comments

Comments
 (0)