-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* download chelsa v2 bioclim * add version keyword, implement bioclim+ * avoid Val(version), use if-else instead * make constants UPPERCASE * display info when downloading new data * specify version and patch are keywords * fix some types in documentation * add future bioclimplus * add koppen-geiger to bioclimplus layers * add documentation for getraster with bioclimplus * swb (soil water balance) is not monthly * correct bioclimplus layers for future * pet is called pet_penman * add chelsa current climate * add tests for chelsa bioclimplus and chelsa climate * delete aqua toml formatting, test chelsa climate * fix tests * fix and test chelsa_warn_version * rastername for pet uses pet_penman * move a line away from docs * update readme and chelsa docs
- Loading branch information
1 parent
e36ed78
commit 37cf277
Showing
10 changed files
with
347 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
layers(::Type{CHELSA{Climate}}) = (:clt, :cmi, :hurs, :ncdf, :pet, :pr, :rsds, :sfcWind, :tas, :tasmax, :tasmin, :vpd) | ||
|
||
""" | ||
getraster(T::Type{CHELSA{Climate}}, [layer::Union{Tuple,Symbol}]; month) => Vector{String} | ||
Download [`CHELSA`](@ref) [`Climate`](@ref) data. | ||
# Arguments | ||
- `layer` `Symbol` or `Tuple` of `Symbol` from `$(layers(CHELSA{Climate}))`. | ||
# Keywords | ||
- `month`: `Integer` or `AbstractArray` of `Integer`. Chosen from `1:12`. | ||
Returns the filepath/s of the downloaded or pre-existing files. | ||
""" | ||
function getraster(T::Type{CHELSA{Climate}}, layers::Union{Tuple,Symbol}; month) | ||
_getraster(T, layers, month) | ||
end | ||
|
||
getraster_keywords(::Type{CHELSA{Climate}}) = (:month,) | ||
|
||
function _getraster(T::Type{CHELSA{Climate}}, layers, month::AbstractArray) | ||
_getraster.(T, Ref(layers), month) | ||
end | ||
function _getraster(T::Type{CHELSA{Climate}}, layers::Tuple, month::Integer) | ||
_map_layers(T, layers, month) | ||
end | ||
function _getraster(T::Type{CHELSA{Climate}}, layer::Symbol, month::Integer) | ||
_check_layer(T, layer) | ||
path = rasterpath(T, layer; month) | ||
url = rasterurl(T, layer; month) | ||
return _maybe_download(url, path) | ||
end | ||
|
||
# Climate layers don't get their own folder | ||
rasterpath(T::Type{<:CHELSA{Climate}}, layer; month) = | ||
joinpath(_rasterpath(T, layer), rastername(T, layer; month)) | ||
_rasterpath(T::Type{<:CHELSA{Climate}}, layer) = joinpath(rasterpath(T), string(layer)) | ||
rasterpath(T::Type{<:CHELSA{Climate}}) = joinpath(rasterpath(CHELSA), "Climate") | ||
function rastername(T::Type{<:CHELSA{Climate}}, layer; month) | ||
_layer = layer == :pet ? :pet_penman : layer | ||
"CHELSA_$(_layer)_$(_pad2(month))_1981-2010_V.2.1.tif" | ||
end | ||
rasterurl(T::Type{CHELSA{Climate}}, layer::Symbol; month) = joinpath(rasterurl(CHELSA, 2), "climatologies/1981-2010", string(layer), rastername(T, layer; month)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,47 @@ | ||
""" | ||
CHELSA{Union{BioClim,<:Future}} <: RasterDataSource | ||
CHELSA{Union{BioClim,BioClimPlus,Climate,<:Future}} <: RasterDataSource | ||
Data from CHELSA, currently implements the current `BioClim` and | ||
`Future{BioClim}` variables, and `Future{Climate}`. | ||
Data from CHELSA, currently implements the `BioClim` `BioClimPlus`, and `Climate` | ||
variables for current and future conditions. | ||
See: [chelsa-climate.org](https://chelsa-climate.org/) for the dataset, | ||
and the [`getraster`](@ref) docs for implementation details. | ||
""" | ||
struct CHELSA{X} <: RasterDataSource end | ||
|
||
rasterpath(::Type{CHELSA}) = joinpath(rasterpath(), "CHELSA") | ||
function rasterurl(T::Type{CHELSA}, version) | ||
if version == 1 | ||
joinpath(rasterurl(T), "chelsa_V1") | ||
elseif version == 2 | ||
joinpath(rasterurl(T), "chelsa_V2/GLOBAL") | ||
else | ||
CHELSA_invalid_version(version) | ||
end | ||
end | ||
rasterurl(::Type{CHELSA}) = URI(scheme="https", host="os.zhdk.cloud.switch.ch", path="/envicloud/chelsa/") | ||
|
||
function latest_patch(::Type{<:CHELSA}, v) | ||
if v == 1 | ||
2 | ||
elseif v == 2 | ||
1 | ||
else | ||
CHELSA_invalid_version(v) | ||
end | ||
end | ||
|
||
const CHELSA_KEYWORDS = """ | ||
- `version`: `Integer` indicating the CHELSA version, currently either `1` or `2`. | ||
- `patch`: `Integer` indicating the CHELSA patch number. Defaults to the latest patch (V1.2 and V2.1) | ||
""" | ||
|
||
CHELSA_invalid_version(v, valid_versions = [1,2]) = | ||
throw(ArgumentError("Version $v is not available for CHELSA. Available versions: $valid_versions.")) | ||
|
||
function CHELSA_warn_version(T, layer, version, patch, path) | ||
if version == 2 && !isfile(path) && isfile(rasterpath(T, layer; version = 1)) | ||
@info "File for CHELSA v1.2 detected, but requested version is CHELSA v$version.$patch. | ||
To load data for CHELSA v1.2 instead, set version keyword to 1" | ||
end | ||
end |
Oops, something went wrong.