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

[WIP] Add the Deltares World Flood dataset #58

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/RasterDataSources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export ACCESS1, BNUESM, CCSM4, CESM1BGC, CESM1CAM5, CMCCCMS, CMCCCM, CNRMCM5,
# Climate models from CMIP6 (used in WorldClim)
export BCCCSM2MR, CNRMCM61, CNRMESM21, CanESM5, GFDLESM4, IPSLCM6ALR, MIROCES2L, MIROC6, MRIESM2

# Deltares datasets
export Deltares, WorldFlood

export Values, Deciles

Expand Down Expand Up @@ -81,4 +83,6 @@ include("modis/products.jl")
include("modis/utilities.jl")
include("modis/examples.jl")

include("deltares/worldflood.jl")

end # module
56 changes: 56 additions & 0 deletions src/deltares/worldflood.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
struct Deltares{Description} <: RasterDataSource end

struct WorldFlood end

function _validate_deltares_worldflood_params(; year, res, dem_source, return_period)

Check warning on line 5 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L5

Added line #L5 was not covered by tests
# check the parameters
# resolution depends on dem_source
if dem_source == :NASADEM || dem_source == :MERITDEM
@assert res in ("90m", "1km") "Provided: $res, expected one of "
elseif dem_source == :LIDAR
@assert res == "5km" "Provided: $res, expected one of "

Check warning on line 11 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L8-L11

Added lines #L8 - L11 were not covered by tests
else
@assert dem_source in (:NASADEM, :MERITDEM, :LIDAR) "Provided: $dem_source, expected one of "

Check warning on line 13 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L13

Added line #L13 was not covered by tests
end

@assert return_period in (0, 2, 5, 10, 25, 50, 100, 250) "Provided: $return_period, expected one of "
@assert year in (2018, 2050) "Provided: $year, expected one of "
return true

Check warning on line 18 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L16-L18

Added lines #L16 - L18 were not covered by tests
end


getraster_keywords(::Type{<: Deltares{<: WorldFlood}}) = (:year, :res, :dem_source, :return_period)

Check warning on line 22 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L22

Added line #L22 was not covered by tests

function rastername(::Type{<: Deltares{<: WorldFlood}}, layer; year = 2050, res::String = "90m", dem_source::Symbol = :NASADEM, return_period::Int = 100)

Check warning on line 24 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L24

Added line #L24 was not covered by tests

# validate params
_validate_deltares_worldflood_params(; year, res, dem_source, return_period)
"GFM_global_$(dem_source)$(res)_$(year)slr_rp$(lpad(return_period, 4, '0'))_masked.nc"

Check warning on line 28 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L27-L28

Added lines #L27 - L28 were not covered by tests

end

function rasterpath(T::Type{<: Deltares{<: WorldFlood}}, layer; year = 2050, res::String = "90m", dem_source::Symbol = :NASADEM, return_period::Int = 100)

Check warning on line 32 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L32

Added line #L32 was not covered by tests

# validate params
_validate_deltares_worldflood_params(; year, res, dem_source, return_period)
return joinpath(rasterpath(), "Deltares", "WorldFlood", rastername(T, layer; year, res, dem_source, return_period))

Check warning on line 36 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L35-L36

Added lines #L35 - L36 were not covered by tests

end

function rasterurl(T::Type{<: Deltares{<: WorldFlood}}, layer; year = 2050, res::String = 90, dem_source::Symbol = :NASADEM, return_period::Int = 100)

Check warning on line 40 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L40

Added line #L40 was not covered by tests

# validate params
_validate_deltares_worldflood_params(; year, res, dem_source, return_period)

Check warning on line 43 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L43

Added line #L43 was not covered by tests

root_uri = URI(scheme = "https", host = "deltaresfloodssa.blob.core.windows.net", path = "/floods/v2021.06")

Check warning on line 45 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L45

Added line #L45 was not covered by tests

return URIs.URI(root_uri, path = "/floods/v2021.06/global/$(dem_source)/$(res)/" * rastername(T, layer; year, res, dem_source, return_period))

Check warning on line 47 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L47

Added line #L47 was not covered by tests

end

function getraster(T::Type{<: Deltares{<: WorldFlood}}, layer; year = 2050, res::String = "90m", dem_source::Symbol = :NASADEM, return_period::Int = 100)
raster_path = rasterpath(T, layer; year, res, dem_source, return_period)
mkpath(dirname(raster_path))
_maybe_download(rasterurl(T, layer; year, res, dem_source, return_period), raster_path)
raster_path

Check warning on line 55 in src/deltares/worldflood.jl

View check run for this annotation

Codecov / codecov/patch

src/deltares/worldflood.jl#L51-L55

Added lines #L51 - L55 were not covered by tests
end