Skip to content

Commit

Permalink
Merge pull request #72 from PoisotLab/feature/human-names
Browse files Browse the repository at this point in the history
Add additional metadata to the providers
  • Loading branch information
tpoisot authored Nov 17, 2022
2 parents ca936e3 + 1bc1ccc commit f243c40
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 42 deletions.
1 change: 1 addition & 0 deletions SimpleSDMDatasets/src/SimpleSDMDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export RasterData, Projection

# Common interface
include("interface.jl")
export layers, layerdescriptions

# Providers
include("providers/CHELSA/chelsa_v1.jl")
Expand Down
10 changes: 6 additions & 4 deletions SimpleSDMDatasets/src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ layers(data::R, ::F) where {R <: RasterData, F <: Projection} = layers(data)
"""
layerdescriptions(data::R) where {R <: RasterData}
Human-readable names the layers. This will by default print the value of
`layers`, but can be overloaded if these names are not informative.
Human-readable names the layers. This *must* be a dictionary mapping the layer names (as returned by `layers`) to a string explaining the contents of the layers.
"""
layerdescriptions(data::R) where {R <: RasterData} = layers(data)
layerdescriptions(data::R) where {R <: RasterData} = Dict(zip(layers(data), layers(data)))
layerdescriptions(data::R, ::F) where {R <: RasterData, F <: Projection} =
layerdescriptions(data)

Expand Down Expand Up @@ -223,4 +222,7 @@ bandnumber(::R; kwargs...) where {R <: RasterData} = 1
bandnumber(::R, ::F; kwargs...) where {R <: RasterData, F <: Projection} = 1

crs(::R) where {R <: RasterData} = _wgs84
crs(data::R, future::F) where {R <: RasterData, F <: Projection} = crs(data)
crs(data::R, ::F) where {R <: RasterData, F <: Projection} = crs(data)

url(::R) where {R <: RasterData} = ""
url(data::R, ::F) where {R <: RasterData, F <: Projection} = url(data)
25 changes: 24 additions & 1 deletion SimpleSDMDatasets/src/providers/CHELSA/chelsa_v1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,31 @@ CHELSA1Dataset = Union{
# Update provisioning
provides(::Type{CHELSA1}, ::Type{T}) where {T <: CHELSA1Dataset} = true

url(::RasterData{CHELSA1, D}) where {D <: CHELSA1Dataset} = "https://chelsa-climate.org/"

# Update the layers
layers(::RasterData{CHELSA1, BioClim}) = "BIO" .* string.(1:19)
layerdescriptions(::RasterData{CHELSA1, BioClim}) = Dict([
"BIO1" => "Annual Mean Temperature",
"BIO2" => "Mean Diurnal Range (Mean of monthly (max temp - min temp))",
"BIO3" => "Isothermality (BIO2/BIO7) (×100)",
"BIO4" => "Temperature Seasonality (standard deviation ×100)",
"BIO5" => "Max Temperature of Warmest Month",
"BIO6" => "Min Temperature of Coldest Month",
"BIO7" => "Temperature Annual Range (BIO5-BIO6)",
"BIO8" => "Mean Temperature of Wettest Quarter",
"BIO9" => "Mean Temperature of Driest Quarter",
"BIO10" => "Mean Temperature of Warmest Quarter",
"BIO11" => "Mean Temperature of Coldest Quarter",
"BIO12" => "Annual Precipitation",
"BIO13" => "Precipitation of Wettest Month",
"BIO14" => "Precipitation of Driest Month",
"BIO15" => "Precipitation Seasonality (Coefficient of Variation)",
"BIO16" => "Precipitation of Wettest Quarter",
"BIO17" => "Precipitation of Driest Quarter",
"BIO18" => "Precipitation of Warmest Quarter",
"BIO19" => "Precipitation of Coldest Quarter",
])

# Months for climate variables
months(::RasterData{CHELSA1, T}) where {T <: CHELSA1Dataset} = Month.(1:12)
Expand Down Expand Up @@ -56,4 +79,4 @@ function source(data::RasterData{CHELSA1, BioClim}; layer = "BIO1")
filename = lowercase(stem),
outdir = destination(data),
)
end
end
25 changes: 24 additions & 1 deletion SimpleSDMDatasets/src/providers/CHELSA/chelsa_v2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,31 @@ CHELSA2Dataset = Union{
# Update provisioning
provides(::Type{CHELSA2}, ::Type{T}) where {T <: CHELSA2Dataset} = true

url(::RasterData{CHELSA2, D}) where {D <: CHELSA2Dataset} = "https://chelsa-climate.org/"

# Update the layers
layers(::RasterData{CHELSA2, BioClim}) = "BIO" .* string.(1:19)
layerdescriptions(::RasterData{CHELSA2, BioClim}) = Dict([
"BIO1" => "Annual Mean Temperature",
"BIO2" => "Mean Diurnal Range (Mean of monthly (max temp - min temp))",
"BIO3" => "Isothermality (BIO2/BIO7) (×100)",
"BIO4" => "Temperature Seasonality (standard deviation ×100)",
"BIO5" => "Max Temperature of Warmest Month",
"BIO6" => "Min Temperature of Coldest Month",
"BIO7" => "Temperature Annual Range (BIO5-BIO6)",
"BIO8" => "Mean Temperature of Wettest Quarter",
"BIO9" => "Mean Temperature of Driest Quarter",
"BIO10" => "Mean Temperature of Warmest Quarter",
"BIO11" => "Mean Temperature of Coldest Quarter",
"BIO12" => "Annual Precipitation",
"BIO13" => "Precipitation of Wettest Month",
"BIO14" => "Precipitation of Driest Month",
"BIO15" => "Precipitation Seasonality (Coefficient of Variation)",
"BIO16" => "Precipitation of Wettest Quarter",
"BIO17" => "Precipitation of Driest Quarter",
"BIO18" => "Precipitation of Warmest Quarter",
"BIO19" => "Precipitation of Coldest Quarter",
])

# Months
months(::RasterData{CHELSA2, T}) where {T <: CHELSA2Dataset} = Month.(1:12)
Expand Down Expand Up @@ -45,4 +68,4 @@ function source(data::RasterData{CHELSA2, T}; month = Month(1)) where {T <: CHEL
filename = lowercase(stem),
outdir = destination(data),
)
end
end
7 changes: 5 additions & 2 deletions SimpleSDMDatasets/src/providers/EarthEnv/earthenv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ EarthEnvDataset = Union{LandCover, HabitatHeterogeneity}
provides(::Type{EarthEnv}, ::Type{T}) where {T <: EarthEnvDataset} = true

# Additional keys for search
extrakeys(::RasterData{EarthEnv, LandCover}) = Dict([:full=>(true,false)])
extrakeys(::RasterData{EarthEnv, LandCover}) = Dict([:full => (true, false)])

url(::RasterData{EarthEnv, LandCover}) = "https://www.earthenv.org/landcover"
url(::RasterData{EarthEnv, HabitatHeterogeneity}) = "https://www.earthenv.org/texture"

# Update the layers
layers(::RasterData{EarthEnv, LandCover}) = [
Expand Down Expand Up @@ -110,4 +113,4 @@ function source(
filename = lowercase(stem),
outdir = destination(data),
)
end
end
26 changes: 25 additions & 1 deletion SimpleSDMDatasets/src/providers/WorldClim/worldclim_v2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ wcdat = [
]
WorldClim2Dataset = Union{wcdat...}

url(::RasterData{WorldClim2, D}) where {D <: WorldClim2Dataset} =
"https://www.worldclim.org/data/index.html"

# Update provisioning
provides(::Type{WorldClim2}, ::Type{T}) where {T <: WorldClim2Dataset} = true

Expand All @@ -29,6 +32,27 @@ months(::RasterData{WorldClim2, Elevation}) = nothing

# Update the layers
layers(::RasterData{WorldClim2, BioClim}) = "BIO" .* string.(1:19)
layerdescriptions(::RasterData{WorldClim2, BioClim}) = Dict([
"BIO1" => "Annual Mean Temperature",
"BIO2" => "Mean Diurnal Range (Mean of monthly (max temp - min temp))",
"BIO3" => "Isothermality (BIO2/BIO7) (×100)",
"BIO4" => "Temperature Seasonality (standard deviation ×100)",
"BIO5" => "Max Temperature of Warmest Month",
"BIO6" => "Min Temperature of Coldest Month",
"BIO7" => "Temperature Annual Range (BIO5-BIO6)",
"BIO8" => "Mean Temperature of Wettest Quarter",
"BIO9" => "Mean Temperature of Driest Quarter",
"BIO10" => "Mean Temperature of Warmest Quarter",
"BIO11" => "Mean Temperature of Coldest Quarter",
"BIO12" => "Annual Precipitation",
"BIO13" => "Precipitation of Wettest Month",
"BIO14" => "Precipitation of Driest Month",
"BIO15" => "Precipitation Seasonality (Coefficient of Variation)",
"BIO16" => "Precipitation of Wettest Quarter",
"BIO17" => "Precipitation of Driest Quarter",
"BIO18" => "Precipitation of Warmest Quarter",
"BIO19" => "Precipitation of Coldest Quarter",
])

# The following functions are the list of URL codes for the datasets. Note that
# they dispatch on the dataset within the context of WorldClim2
Expand Down Expand Up @@ -88,4 +112,4 @@ function layername(
res_code = get(resolutions(data), resolution, "10m")
var_code = _var_slug(data)
return "wc2.1_$(res_code)_$(var_code).tif"
end
end
14 changes: 8 additions & 6 deletions SimpleSDMDatasets/test/chelsa_v1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,40 @@ for T in Base.uniontypes(SimpleSDMDatasets.CHELSA1Dataset)
@test SimpleSDMDatasets.resolutions(data) |> isnothing
end

@test layerdescriptions(RasterData(CHELSA1, BioClim))["BIO1"] == "Annual Mean Temperature"

@test SimpleSDMDatasets.months(RasterData(CHELSA1, BioClim)) |> isnothing
@test SimpleSDMDatasets.extrakeys(RasterData(CHELSA1, BioClim)) |> isnothing
@test SimpleSDMDatasets.layers(RasterData(CHELSA1, BioClim)) |> !isnothing

begin
out = downloader(RasterData(CHELSA1, BioClim); layer = "BIO12")
out = downloader(RasterData(CHELSA1, BioClim); layer="BIO12")
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(CHELSA1, BioClim))
end

begin
out = downloader(RasterData(CHELSA1, AverageTemperature); month = Month(6))
out = downloader(RasterData(CHELSA1, AverageTemperature); month=Month(6))
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(CHELSA1, AverageTemperature))
end

begin
out = downloader(RasterData(CHELSA1, MinimumTemperature); month = Month(12))
out = downloader(RasterData(CHELSA1, MinimumTemperature); month=Month(12))
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(CHELSA1, MinimumTemperature))
end

begin
out = downloader(RasterData(CHELSA1, MaximumTemperature); month = Month(1))
out = downloader(RasterData(CHELSA1, MaximumTemperature); month=Month(1))
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(CHELSA1, MaximumTemperature))
end

begin
out = downloader(RasterData(CHELSA1, Precipitation); month = Month(10))
out = downloader(RasterData(CHELSA1, Precipitation); month=Month(10))
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(CHELSA1, Precipitation))
end

end
end
14 changes: 8 additions & 6 deletions SimpleSDMDatasets/test/chelsa_v2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ for T in Base.uniontypes(SimpleSDMDatasets.CHELSA2Dataset)
@test SimpleSDMDatasets.resolutions(data) |> isnothing
end

@test layerdescriptions(RasterData(CHELSA2, BioClim))["BIO1"] == "Annual Mean Temperature"

@test SimpleSDMDatasets.months(RasterData(CHELSA2, BioClim)) |> isnothing
@test SimpleSDMDatasets.extrakeys(RasterData(CHELSA2, BioClim)) |> isnothing
@test SimpleSDMDatasets.layers(RasterData(CHELSA2, BioClim)) |> !isnothing
Expand All @@ -22,33 +24,33 @@ end
@test SimpleSDMDatasets.layers(RasterData(CHELSA2, MinimumTemperature)) |> isnothing

begin
out = downloader(RasterData(CHELSA2, BioClim); layer = "BIO12")
out = downloader(RasterData(CHELSA2, BioClim); layer="BIO12")
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(CHELSA2, BioClim))
end

begin
out = downloader(RasterData(CHELSA2, AverageTemperature); month = Month(6))
out = downloader(RasterData(CHELSA2, AverageTemperature); month=Month(6))
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(CHELSA2, AverageTemperature))
end

begin
out = downloader(RasterData(CHELSA2, MinimumTemperature); month = Month(12))
out = downloader(RasterData(CHELSA2, MinimumTemperature); month=Month(12))
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(CHELSA2, MinimumTemperature))
end

begin
out = downloader(RasterData(CHELSA2, MaximumTemperature); month = Month(1))
out = downloader(RasterData(CHELSA2, MaximumTemperature); month=Month(1))
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(CHELSA2, MaximumTemperature))
end

begin
out = downloader(RasterData(CHELSA2, Precipitation); month = Month(10))
out = downloader(RasterData(CHELSA2, Precipitation); month=Month(10))
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(CHELSA2, Precipitation))
end

end
end
36 changes: 19 additions & 17 deletions SimpleSDMDatasets/test/worldclim_v2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using Dates
for T in Base.uniontypes(SimpleSDMDatasets.WorldClim2Dataset)
@test SimpleSDMDatasets.provides(WorldClim2, T)
data = RasterData(WorldClim2, T)
@test typeof(data) == RasterData{WorldClim2, T}
@test typeof(data) == RasterData{WorldClim2,T}
@test SimpleSDMDatasets.resolutions(data) |> !isnothing
end

Expand All @@ -20,29 +20,31 @@ end
@test SimpleSDMDatasets.layers(RasterData(WorldClim2, AverageTemperature)) |> isnothing
@test SimpleSDMDatasets.layers(RasterData(WorldClim2, BioClim)) |> !isnothing

@test layerdescriptions(RasterData(WorldClim2, BioClim))["BIO1"] == "Annual Mean Temperature"

begin
out = downloader(RasterData(WorldClim2, BioClim); resolution = 10.0, layer = "BIO8")
out = downloader(RasterData(WorldClim2, BioClim); resolution=10.0, layer="BIO8")
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(WorldClim2, BioClim))
end

begin
out = downloader(RasterData(WorldClim2, BioClim); resolution = 5.0, layer = "BIO4")
out = downloader(RasterData(WorldClim2, BioClim); resolution=5.0, layer="BIO4")
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(WorldClim2, BioClim))
end

begin
out = downloader(RasterData(WorldClim2, Elevation); resolution = 5.0)
out = downloader(RasterData(WorldClim2, Elevation); resolution=5.0)
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(WorldClim2, Elevation))
end

begin
out = downloader(
RasterData(WorldClim2, MaximumTemperature);
resolution = 10.0,
month = Month(4),
resolution=10.0,
month=Month(4)
)
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(WorldClim2, MaximumTemperature))
Expand All @@ -51,8 +53,8 @@ end
begin
out = downloader(
RasterData(WorldClim2, MinimumTemperature);
resolution = 2.5,
month = Month(12),
resolution=2.5,
month=Month(12)
)
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(WorldClim2, MinimumTemperature))
Expand All @@ -61,8 +63,8 @@ end
begin
out = downloader(
RasterData(WorldClim2, AverageTemperature);
resolution = 10.0,
month = Month(4),
resolution=10.0,
month=Month(4)
)
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(WorldClim2, AverageTemperature))
Expand All @@ -71,8 +73,8 @@ end
begin
out = downloader(
RasterData(WorldClim2, SolarRadiation);
resolution = 10.0,
month = Month(4),
resolution=10.0,
month=Month(4)
)
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(WorldClim2, SolarRadiation))
Expand All @@ -81,8 +83,8 @@ end
begin
out = downloader(
RasterData(WorldClim2, WindSpeed);
resolution = 10.0,
month = Month(4),
resolution=10.0,
month=Month(4)
)
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(WorldClim2, WindSpeed))
Expand All @@ -91,11 +93,11 @@ end
begin
out = downloader(
RasterData(WorldClim2, WaterVaporPressure);
resolution = 10.0,
month = Month(4),
resolution=10.0,
month=Month(4)
)
@test isfile(first(out))
@test out[2] == SimpleSDMDatasets.filetype(RasterData(WorldClim2, WaterVaporPressure))
end

end
end
6 changes: 3 additions & 3 deletions docs/src/SimpleSDMDatasets/dev/interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ SimpleSDMDatasets.resolutions
## Available layers

```@docs
SimpleSDMDatasets.layers
SimpleSDMDatasets.layerdescriptions
layers
layerdescriptions
```

## Available months
Expand Down Expand Up @@ -115,4 +115,4 @@ SimpleSDMDatasets.source

```@docs
SimpleSDMDatasets.destination
```
```
Loading

0 comments on commit f243c40

Please sign in to comment.