From 61ca54af133a5628eee4da097ae54e92c689a330 Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Wed, 19 Jun 2024 13:45:01 +0200 Subject: [PATCH 1/2] fix GMT import_topo --- ext/GMT_utils.jl | 65 ++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/ext/GMT_utils.jl b/ext/GMT_utils.jl index 5cbeaf3f..a502d82b 100644 --- a/ext/GMT_utils.jl +++ b/ext/GMT_utils.jl @@ -18,7 +18,7 @@ println("Loading GMT routines within GMG") """ - Topo = import_topo(limits; file::String="@earth_relief_01m.grd", maxattempts=5) + Topo = import_topo(limits; file::String="@earth_relief_01m", maxattempts=5) Uses `GMT` to download the topography of a certain region, specified with limits=[lon_min, lon_max, lat_min, lat_max]. Sometimes download fails because of the internet connection. We do `maxattempts` to download it. @@ -65,45 +65,44 @@ julia> write_paraview(Topo,"Topo_Alps") "Topo_Alps.vts" ``` """ -function import_topo(limits; file::String="@earth_relief_01m.grd", maxattempts=5) +function import_topo(limits; file::String="@earth_relief_01m", maxattempts=5) - # Correct if negative values are given (longitude coordinates that are west) - ind = findall(limits[1:2] .< 0); + # Correct if negative values are given (longitude coordinates that are west) + ind = limits[1:2] .< 0 - if (limits[1] < 0) && (limits[2] < 0) - limits[ind] .= 360 .+ limits[ind]; - limits[1:2] = sort(limits[1:2]) - end + if (limits[1] < 0) && (limits[2] < 0) + limits[ind] .= 360 .+ limits[ind] + limits[1:2] = sort(limits[1:2]) + end - # Download topo file - add a few attempts to do so - G = []; - attempt = 0 - while attempt Topo = import_topo(lat=[30,40], lon=[30, 50] ) ``` The values can also be defined as tuples: ```julia -julia> Topo = import_topo(lon=(-50, -40), lat=(-10,-5), file="@earth_relief_30s.grd") +julia> Topo = import_topo(lon=(-50, -40), lat=(-10,-5), file="@earth_relief_30s") ``` """ -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) +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) """ From 285d400b61d964f183edd2e624bf70739b81ccfd Mon Sep 17 00:00:00 2001 From: albert-de-montserrat Date: Wed, 19 Jun 2024 13:49:34 +0200 Subject: [PATCH 2/2] up docs --- docs/src/man/Tutorial_AlpineData.md | 2 +- docs/src/man/Tutorial_Jura.md | 2 +- docs/src/man/Tutorial_LaPalma.md | 2 +- docs/src/man/tutorial_GMT_Topography.md | 2 +- docs/src/man/tutorial_GMT_Topography_GeologicalMap.md | 4 ++-- docs/src/man/tutorial_GPS.md | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/src/man/Tutorial_AlpineData.md b/docs/src/man/Tutorial_AlpineData.md index c04978e3..a27aeb22 100644 --- a/docs/src/man/Tutorial_AlpineData.md +++ b/docs/src/man/Tutorial_AlpineData.md @@ -29,7 +29,7 @@ using GeophysicalModelGenerator, GMT 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. ```julia -Topo = import_topo([4,20,37,50], file="@earth_relief_01m.grd") +Topo = import_topo([4,20,37,50], file="@earth_relief_01m") ``` 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. diff --git a/docs/src/man/Tutorial_Jura.md b/docs/src/man/Tutorial_Jura.md index 1ae31b18..8e629457 100644 --- a/docs/src/man/Tutorial_Jura.md +++ b/docs/src/man/Tutorial_Jura.md @@ -18,7 +18,7 @@ using GeophysicalModelGenerator, GMT Download the topography with: ```julia -Topo = import_topo(lat=[45.5,47.7], lon=[5, 8.1], file="@earth_relief_03s.grd") +Topo = import_topo(lat=[45.5,47.7], lon=[5, 8.1], file="@earth_relief_03s") ``` Next, we drape the geological map on top of the geological map. diff --git a/docs/src/man/Tutorial_LaPalma.md b/docs/src/man/Tutorial_LaPalma.md index b5dee4ab..c8818099 100644 --- a/docs/src/man/Tutorial_LaPalma.md +++ b/docs/src/man/Tutorial_LaPalma.md @@ -23,7 +23,7 @@ using GeophysicalModelGenerator, GMT, DelimitedFiles We will use GMT to download the topography with: ```julia -Topo = import_topo(lon = [-18.2, -17.5], lat=[28.4, 29.0], file="@earth_relief_15s.grd") +Topo = import_topo(lon = [-18.2, -17.5], lat=[28.4, 29.0], file="@earth_relief_15s") ``` 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). diff --git a/docs/src/man/tutorial_GMT_Topography.md b/docs/src/man/tutorial_GMT_Topography.md index d1683876..fb67f3b3 100644 --- a/docs/src/man/tutorial_GMT_Topography.md +++ b/docs/src/man/tutorial_GMT_Topography.md @@ -15,7 +15,7 @@ The nice thing about GMT is that it automatically downloads data for you for a c ```julia julia> using GeophysicalModelGenerator, GMT -julia> Topo = import_topo([4,20,37,49], file="@earth_relief_01m.grd") +julia> Topo = import_topo([4,20,37,49], file="@earth_relief_01m") GeoData size : (960, 720, 1) lon ϵ [ 4.0 : 19.983333333333334] diff --git a/docs/src/man/tutorial_GMT_Topography_GeologicalMap.md b/docs/src/man/tutorial_GMT_Topography_GeologicalMap.md index ee92bd89..91fbb777 100644 --- a/docs/src/man/tutorial_GMT_Topography_GeologicalMap.md +++ b/docs/src/man/tutorial_GMT_Topography_GeologicalMap.md @@ -8,7 +8,7 @@ In many cases, we want to add topographic data as well a information about tecto #### 1. Download topographic data and tectonic maps of the Alpine region The ETOPO1 data file used in this example can be downloaded here: -[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`. +[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`. #### 2. Create a tectonic map with orthogonal projection 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 ``` First, define the filenames of the files you want to import: ```julia -julia> filename_topo = "./ETOPO1/ETOPO1_Ice_g_gmt4.grd" +julia> filename_topo = "./ETOPO1/ETOPO1_Ice_g_gmt4" julia> filename_geo = "./tectonicmap_SPP.png" ``` 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): diff --git a/docs/src/man/tutorial_GPS.md b/docs/src/man/tutorial_GPS.md index dcb5d182..c489a651 100644 --- a/docs/src/man/tutorial_GPS.md +++ b/docs/src/man/tutorial_GPS.md @@ -163,7 +163,7 @@ using GMT, Interpolations We use the `import_topo` function to read the topography from a file: ```julia -Elevation = import_topo([3,17,42,50], file="@earth_relief_01m.grd"); +Elevation = import_topo([3,17,42,50], file="@earth_relief_01m"); nothing #hide ```