Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download remote data #60

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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"

Check warning on line 95 in src/IO.jl

View check run for this annotation

Codecov / codecov/patch

src/IO.jl#L95

Added line #L95 was not covered by tests
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"

Loading