Skip to content

Commit

Permalink
Merge pull request #60 from JuliaGeodynamics/bk-load-remote-data
Browse files Browse the repository at this point in the history
Download remote data
  • Loading branch information
boriskaus authored Feb 28, 2024
2 parents 27dc5f1 + b2b331b commit 9e3e225
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/IO.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This provides functions to load and save GeoData structs & friends to file
using JLD2, Downloads

export save_GMG, load_GMG
export save_GMG, load_GMG, download_data

"""
save_GMG(filename::String, data::Union{GeoData, CartDat, UTMData}; dir=pwd())
Expand Down Expand Up @@ -71,3 +71,32 @@ function load_GMG(filename::String, dir=pwd())

return data
end




"""
download_data(url::String, local_filename="temp.dat"; dir=pwd() )
Downloads a remote dataset with name `url` from a remote location and saves it to the current directory
Example
====
```julia
julia> url = "https://seafile.rlp.net/f/10f867e410bb4d95b3fe/?dl=1";
julia> download_data(url)
"/Users/kausb/.julia/dev/GeophysicalModelGenerator/temp.dat"
```
"""
function download_data(url::String, local_filename="temp.dat"; dir=pwd() )

if !contains(url,"http")
@warn "the url does not contain http; please double check that it worked"
end

# download remote file to a local temporary directory
file_ext = Downloads.download(url, joinpath(dir,local_filename))

return file_ext
end
7 changes: 7 additions & 0 deletions test/test_IO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ data_local = load_GMG(joinpath(pkg_dir,"test"))
url = "https://seafile.rlp.net/f/10f867e410bb4d95b3fe/?dl=1"
data_remote = load_GMG(url)
@test data_remote.fields.MohoDepth[20] -17.99km


# loading remote data
url = "https://seafile.rlp.net/f/10f867e410bb4d95b3fe/?dl=1"
data_remote = download_data(url, "temp1.dat")
@test data_remote[end-8:end] == "temp1.dat"

0 comments on commit 9e3e225

Please sign in to comment.