Skip to content

Commit

Permalink
first draft for future wordclim climate
Browse files Browse the repository at this point in the history
  • Loading branch information
tiemvanderdeure committed Aug 22, 2024
1 parent 9fc47b6 commit 12f6ede
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/worldclim/future.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const WORLDCLIM_URI_CMIP6 = URI(scheme="https", host="geodata.ucdavis.edu", path="/cmip6")

layers(::Type{<:WorldClim{<:Future{Climate}}}) = (:tmin, :tmax, :prec)
getraster_keywords(::Type{<:WorldClim{<:Future{Climate}}}) = (:date, :res)


function getraster(T::Type{<:WorldClim{<:Future{Climate, CMIP6}}}, layers::Union{Tuple,Symbol};
res::String=defres(T), date
)
_getraster(T, layers, res, date)
end


function _getraster(T::Type{<:WorldClim{<:Future{Climate}}}, layer::Symbol, res::String, date)
#date_str = _date_string(T, date)
_check_layer(T, layer)
_check_res(T, res)
raster_path = rasterpath(T, layer; res, date)
if !isfile(raster_path)
_maybe_download(rasterurl(T, layer; res, date), raster_path)
end
return raster_path
end

function rasterurl(T::Type{<:WorldClim{<:Future{Climate, CMIP6, M, S}}}, layer; res, date) where {M, S}
joinpath(WORLDCLIM_URI_CMIP6, res, _format(WorldClim, M), _format(CHELSA, S), rastername(T, layer; res, date))
end

function rastername(T::Type{<:WorldClim{<:Future{Climate, CMIP6, M, S}}}, layer; res, date) where {M, S}
join(["wc2.1", res, string(layer), _format(WorldClim, M), _format(CHELSA, S), date], "_") * ".tif"
end


function _date_string(::Type{<:WorldClim{<:Future{Climate, CMIP6}}}, date)
if date < DateTime(2021)
_cmip6_date_error(date)
elseif date < DateTime(2041)
"2011-2040"
elseif date < DateTime(2061)
"2041-2060"
elseif date < DateTime(2081)
"2041-2080"
elseif date < DateTime(2101)
"2081-2100"
else
_cmip6_date_error(date)
end
end

const WORDCLIM_CMIP6_MODEL_STRINGS = [
"ACCESS-CM2"
"BCC-CSM2-MR"
"CMCC-ESM2"
"EC-Earth3-Veg"
"FIO-ESM-2-0"
"GFDL-ESM4"
"GISS-E2-1-G"
"HadGEM3-GC31-LL"
"INM-CM5-0"
"IPSL-CM6A-LR"
"MIROC6"
"MPI-ESM1-2-HR"
"MRI-ESM2-0"
"UKESM1-0-LL"
]

WORDCLIM_CMIP6_MODELS = Type{<:ClimateModel{CMIP6}}[]

for model_str in WORDCLIM_CMIP6_MODEL_STRINGS
type = Symbol(replace(model_str, "-" => "_"))
@eval begin
export $type
if !(@isdefined $type)
struct $type <: ClimateModel{CMIP6} end
export $type
end
push!(WORDCLIM_CMIP6_MODELS, $type)
_format(::Type{WorldClim}, ::Type{$type}) = $model_str
end
end

append!(CMIP6_MODELS, WORDCLIM_CMIP6_MODELS)
unique!(CMIP6_MODELS)

0 comments on commit 12f6ede

Please sign in to comment.