Skip to content

Commit 432ac9c

Browse files
Merge pull request #122 from albert-de-montserrat/adm/CI
Fix the download of topographyic data with GMT
2 parents 4b3886a + 285d400 commit 432ac9c

File tree

7 files changed

+39
-40
lines changed

7 files changed

+39
-40
lines changed

docs/src/man/Tutorial_AlpineData.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using GeophysicalModelGenerator, GMT
2929
When loading both packages, several `GMT` routines within `GMG` will be loaded. One of these routines is the function `import_topo`, where one simply has to provide the region for which to download the topographic data and the data source.
3030

3131
```julia
32-
Topo = import_topo([4,20,37,50], file="@earth_relief_01m.grd")
32+
Topo = import_topo([4,20,37,50], file="@earth_relief_01m")
3333
```
3434

3535
The data is available in different resolutions; see [here](http://gmt.soest.hawaii.edu/doc/latest/grdimage.html) for an overview. Generally, it is advisable to not use the largest resolution if you have a large area, as the files become very large.

docs/src/man/Tutorial_Jura.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using GeophysicalModelGenerator, GMT
1818
Download the topography with:
1919

2020
```julia
21-
Topo = import_topo(lat=[45.5,47.7], lon=[5, 8.1], file="@earth_relief_03s.grd")
21+
Topo = import_topo(lat=[45.5,47.7], lon=[5, 8.1], file="@earth_relief_03s")
2222
```
2323

2424
Next, we drape the geological map on top of the geological map.

docs/src/man/Tutorial_LaPalma.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using GeophysicalModelGenerator, GMT, DelimitedFiles
2323
We will use GMT to download the topography with:
2424

2525
```julia
26-
Topo = import_topo(lon = [-18.2, -17.5], lat=[28.4, 29.0], file="@earth_relief_15s.grd")
26+
Topo = import_topo(lon = [-18.2, -17.5], lat=[28.4, 29.0], file="@earth_relief_15s")
2727
```
2828

2929
Next, lets load the seismicity. The earthquake data is available on [https://www.ign.es/web/ign/portal/vlc-catalogo](https://www.ign.es/web/ign/portal/vlc-catalogo).

docs/src/man/tutorial_GMT_Topography.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The nice thing about GMT is that it automatically downloads data for you for a c
1515

1616
```julia
1717
julia> using GeophysicalModelGenerator, GMT
18-
julia> Topo = import_topo([4,20,37,49], file="@earth_relief_01m.grd")
18+
julia> Topo = import_topo([4,20,37,49], file="@earth_relief_01m")
1919
GeoData
2020
size : (960, 720, 1)
2121
lon ϵ [ 4.0 : 19.983333333333334]

docs/src/man/tutorial_GMT_Topography_GeologicalMap.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In many cases, we want to add topographic data as well a information about tecto
88

99
#### 1. Download topographic data and tectonic maps of the Alpine region
1010
The ETOPO1 data file used in this example can be downloaded here:
11-
[https://ngdc.noaa.gov/mgg/global/global.html](https://ngdc.noaa.gov/mgg/global/global.html). For this example, we downloaded `ETOPO1_Ice_g_gmt4.grd` and stored it directly in the folder where we will be working. For the geological map, we download the data from the [SPP 4DMB repository](http://www.spp-mountainbuilding.de/data/Maps.zip) and extract the zip file (to the current folder). In this data set, a `gmt` file with the data for different tectonic units is given in `./tectonic_maps_4dmb_2020_09_17/GMT_example/alcapadi_polygons.gmt`.
11+
[https://ngdc.noaa.gov/mgg/global/global.html](https://ngdc.noaa.gov/mgg/global/global.html). For this example, we downloaded `ETOPO1_Ice_g_gmt4` and stored it directly in the folder where we will be working. For the geological map, we download the data from the [SPP 4DMB repository](http://www.spp-mountainbuilding.de/data/Maps.zip) and extract the zip file (to the current folder). In this data set, a `gmt` file with the data for different tectonic units is given in `./tectonic_maps_4dmb_2020_09_17/GMT_example/alcapadi_polygons.gmt`.
1212

1313
#### 2. Create a tectonic map with orthogonal projection
1414
To create a png with an orthogonal map projection (which we need for the png import), we do the following in julia:
@@ -28,7 +28,7 @@ julia> using GMT, NearestNeighbors, GeoParams, GeophysicalModelGenerator
2828
```
2929
First, define the filenames of the files you want to import:
3030
```julia
31-
julia> filename_topo = "./ETOPO1/ETOPO1_Ice_g_gmt4.grd"
31+
julia> filename_topo = "./ETOPO1/ETOPO1_Ice_g_gmt4"
3232
julia> filename_geo = "./tectonicmap_SPP.png"
3333
```
3434
Next, define the region that you want to visualize (note that we use the same coordinates here as we used previously for the generation of the geological map):

docs/src/man/tutorial_GPS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ using GMT, Interpolations
163163
We use the `import_topo` function to read the topography from a file:
164164

165165
```julia
166-
Elevation = import_topo([3,17,42,50], file="@earth_relief_01m.grd");
166+
Elevation = import_topo([3,17,42,50], file="@earth_relief_01m");
167167
nothing #hide
168168
```
169169

ext/GMT_utils.jl

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ println("Loading GMT routines within GMG")
1818

1919

2020
"""
21-
Topo = import_topo(limits; file::String="@earth_relief_01m.grd", maxattempts=5)
21+
Topo = import_topo(limits; file::String="@earth_relief_01m", maxattempts=5)
2222
2323
Uses `GMT` to download the topography of a certain region, specified with limits=[lon_min, lon_max, lat_min, lat_max].
2424
Sometimes download fails because of the internet connection. We do `maxattempts` to download it.
@@ -65,45 +65,44 @@ julia> write_paraview(Topo,"Topo_Alps")
6565
"Topo_Alps.vts"
6666
```
6767
"""
68-
function import_topo(limits; file::String="@earth_relief_01m.grd", maxattempts=5)
68+
function import_topo(limits; file::String="@earth_relief_01m", maxattempts=5)
6969

70-
# Correct if negative values are given (longitude coordinates that are west)
71-
ind = findall(limits[1:2] .< 0);
70+
# Correct if negative values are given (longitude coordinates that are west)
71+
ind = limits[1:2] .< 0
7272

73-
if (limits[1] < 0) && (limits[2] < 0)
74-
limits[ind] .= 360 .+ limits[ind];
75-
limits[1:2] = sort(limits[1:2])
76-
end
73+
if (limits[1] < 0) && (limits[2] < 0)
74+
limits[ind] .= 360 .+ limits[ind]
75+
limits[1:2] = sort(limits[1:2])
76+
end
7777

78-
# Download topo file - add a few attempts to do so
79-
G = [];
80-
attempt = 0
81-
while attempt<maxattempts
82-
try
83-
G = gmtread(file, limits=limits, grid=true);
84-
break
85-
catch
86-
@warn "Failed downloading GMT topography on attempt $attempt/$maxattempts"
87-
sleep(5) # wait a few sec
88-
end
89-
attempt += 1
90-
end
91-
if isempty(G)
92-
error("Could not download GMT topography data")
78+
# Download topo file - add a few attempts to do so
79+
local G
80+
attempt = 0
81+
while attempt < maxattempts
82+
try
83+
G = gmtread(file, limits=limits, grid=true);
84+
break
85+
catch
86+
@warn "Failed downloading GMT topography on attempt $attempt/$maxattempts"
87+
sleep(5) # wait a few sec
9388
end
89+
attempt += 1
90+
end
91+
if isempty(G)
92+
error("Could not download GMT topography data")
93+
end
9494

95-
# Transfer to GeoData
96-
nx,ny = size(G.z,2), size(G.z,1)
97-
Lon,Lat,Depth = lonlatdepth_grid(G.x[1:nx],G.y[1:ny],0);
98-
Depth[:,:,1] = 1e-3*G.z';
99-
Topo = GeoData(Lon, Lat, Depth, (Topography=Depth*km,))
95+
# Transfer to GeoData
96+
nx, ny = size(G.z,2), size(G.z,1)
97+
Lon,Lat,Depth = lonlatdepth_grid(G.x[1:nx],G.y[1:ny],0);
98+
@views Depth[:,:,1] = 1e-3*G.z';
99+
Topo = GeoData(Lon, Lat, Depth, (Topography=Depth*km,))
100100

101-
return Topo
102-
101+
return Topo
103102
end
104103

105104
"""
106-
import_topo(; lat::Vector{2}, lon::Vector{2}, file::String="@earth_relief_01m.grd", maxattempts=5)
105+
import_topo(; lat::Vector{2}, lon::Vector{2}, file::String="@earth_relief_01m", maxattempts=5)
107106
108107
Imports topography (using GMT), by specifying keywords for latitude and longitude ranges
109108
@@ -114,11 +113,11 @@ julia> Topo = import_topo(lat=[30,40], lon=[30, 50] )
114113
```
115114
The values can also be defined as tuples:
116115
```julia
117-
julia> Topo = import_topo(lon=(-50, -40), lat=(-10,-5), file="@earth_relief_30s.grd")
116+
julia> Topo = import_topo(lon=(-50, -40), lat=(-10,-5), file="@earth_relief_30s")
118117
```
119118
120119
"""
121-
import_topo(; lat=[37,49], lon=[4,20], file::String="@earth_relief_01m.grd", maxattempts=5) = import_topo([lon[1],lon[2], lat[1], lat[2]], file=file, maxattempts=maxattempts)
120+
import_topo(; lat=[37,49], lon=[4,20], file::String="@earth_relief_01m", maxattempts=5) = import_topo([lon[1],lon[2], lat[1], lat[2]], file=file, maxattempts=maxattempts)
122121

123122

124123
"""

0 commit comments

Comments
 (0)