Skip to content

Commit

Permalink
Merge pull request #111 from gaelforget/v0p2p41b
Browse files Browse the repository at this point in the history
V0p2p41b
  • Loading branch information
gaelforget authored Aug 30, 2023
2 parents 90b8b2d + 53bb0d1 commit 6885e81
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 218 deletions.
3 changes: 1 addition & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MeshArrays"
uuid = "cb8c808f-1acf-59a3-9d2b-6e38d009f683"
authors = ["gaelforget <gforget@mit.edu>"]
version = "0.2.40"
version = "0.2.41"

[deps]
CatViews = "81a5f4ea-a946-549a-aa7e-2a7f63a27d31"
Expand Down Expand Up @@ -31,7 +31,6 @@ MeshArraysMakieExt = ["Makie"]
MeshArraysProjExt = ["Proj"]
MeshArraysShapefileExt = ["Shapefile"]
MeshArraysZipFileExt = ["ZipFile"]
demo_sections = ["JLD2"]

[compat]
CatViews = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MeshArrays.GRID_LLC90_download()
MeshArrays.GRID_CS32_download()

using Downloads, ZipFile
fil=MeshArrays.download_polygons("ne_110m_admin_0_countries.shp")
fil=demo.download_polygons("ne_110m_admin_0_countries.shp")

makedocs(
sitename = "MeshArrays",
Expand Down
44 changes: 2 additions & 42 deletions ext/MeshArraysDownloadsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,9 @@ module MeshArraysDownloadsExt

using Downloads

import MeshArrays: download_polygons, interpolation_setup, unzip

"""
download_polygons(ID::String)
Download data and unzip (if needed) to `tempdir()`. Only works for predefined `ID`:
- `ne_110m_admin_0_countries.shp`
- `countries.geojson`
"""
function download_polygons(ID::String)
pth=tempdir()
unzipfil="" #if provided then need to unzip + return this file name
if ID=="ne_110m_admin_0_countries.shp"
url="https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip"
fil=joinpath(pth,"ne_110m_admin_0_countries.zip")
unzipfil=joinpath(pth,"ne_110m_admin_0_countries.shp")
elseif ID=="countries.geojson"
fil=joinpath(pth,"countries.geojson")
url = "https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/countries.geojson"
else
println("unknown file")
fil="unknown"
url="unknown"
end
!isfile(fil) ? Downloads.download(url,fil) : nothing
if !isempty(unzipfil)
unzip(fil)
fil=unzipfil
end
fil
end
import MeshArrays: download_file

##

function interpolation_setup(;path=tempdir())
fil=joinpath(tempdir(),"interp_coeffs_halfdeg.jld2")
if !isfile(fil)
url="https://zenodo.org/record/5784905/files/interp_coeffs_halfdeg.jld2"
Downloads.download(url, fil)
end
fil
end
download_file(url,file) = Downloads.download(url,file)

end

Expand Down
11 changes: 11 additions & 0 deletions ext/MeshArraysJLD2Ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ module MeshArraysJLD2Ext
using MeshArrays, JLD2
import MeshArrays: read_JLD2, write_JLD2

"""
write_JLD2(file;kwargs...)
Call `JLD2.jldsave(file;kwargs...)`
"""
write_JLD2(fil;kwargs...) = jldsave(fil;kwargs...)

"""
read_JLD2(file)
Call `FileIO.load(file)`. Works `.jld2`, `.jpg`, etc files.
"""
read_JLD2(a) = load(a)

end
Loading

0 comments on commit 6885e81

Please sign in to comment.