diff --git a/src/esdc.jl b/src/esdc.jl index 816b746..a154b53 100644 --- a/src/esdc.jl +++ b/src/esdc.jl @@ -7,21 +7,19 @@ global cubesdict function __init__() - global cubesdict, cubesdict3 + global cubesdict cubesdict = Dict( - ("low","ts","global") => ("esdl-esdc-v2.1.1","esdc-8d-0.25deg-184x90x90-2.1.1.zarr"), - ("low","map","global") => ("esdl-esdc-v2.1.1","esdc-8d-0.25deg-1x720x1440-2.1.1.zarr"), - ("high","ts","global") => ("esdl-esdc-v2.1.1","esdc-8d-0.083deg-184x270x270-2.1.1.zarr"), - ("high","map","global") => ("esdl-esdc-v2.1.1","esdc-8d-0.083deg-1x2160x4320-2.1.1.zarr"), - ("low","ts","Colombia") => ("esdl-esdc-v2.0.1","Cube_2019lowColombiaCube_184x60x60.zarr"), - ("low","map","Colombia") => ("esdl-esdc-v2.0.1","Cube_2019lowColombiaCube_1x336x276.zarr/"), - ("high","ts","Colombia") => ("esdl-esdc-v2.0.1","Cube_2019highColombiaCube_184x120x120.zarr"), - ("high","map","Colombia") => ("esdl-esdc-v2.0.1","Cube_2019highColombiaCube_1x3360x2760.zarr"), - ) - cubesdict3 = Dict( - "ts" => "esdc-8d-0.25deg-256x128x128-3.0.2.zarr", - "map" => "esdc-8d-0.25deg-1x720x1440-3.0.2.zarr", - "tiny" => "esdc-16d-2.5deg-46x72x1440-3.0.2.zarr", + ("low", "ts", "global", 2) => ("esdl-esdc-v2.1.1", "esdc-8d-0.25deg-184x90x90-2.1.1.zarr"), + ("low", "map", "global", 2) => ("esdl-esdc-v2.1.1", "esdc-8d-0.25deg-1x720x1440-2.1.1.zarr"), + ("high", "ts", "global", 2) => ("esdl-esdc-v2.1.1", "esdc-8d-0.083deg-184x270x270-2.1.1.zarr"), + ("high", "map", "global", 2) => ("esdl-esdc-v2.1.1", "esdc-8d-0.083deg-1x2160x4320-2.1.1.zarr"), + ("low", "ts", "Colombia", 2) => ("esdl-esdc-v2.0.1", "Cube_2019lowColombiaCube_184x60x60.zarr"), + ("low", "map", "Colombia", 2) => ("esdl-esdc-v2.0.1", "Cube_2019lowColombiaCube_1x336x276.zarr"), + ("high", "ts", "Colombia", 2) => ("esdl-esdc-v2.0.1", "Cube_2019highColombiaCube_184x120x120.zarr"), + ("high", "map", "Colombia", 2) => ("esdl-esdc-v2.0.1", "Cube_2019highColombiaCube_1x3360x2760.zarr"), + ("low", "ts", "global", 3) => ("esdl-esdc-v3.0.2", "esdc-8d-0.25deg-256x128x128-3.0.2.zarr"), + ("low", "map", "global", 3) => ("esdl-esdc-v3.0.2", "esdc-8d-0.25deg-1x720x1440-3.0.2.zarr"), + ("tiny", "ts", "global", 3) => ("esdl-esdc-v3.0.2", "esdc-16d-2.5deg-46x72x1440-3.0.2.zarr") ) end @@ -35,29 +33,45 @@ and `store` or pick a resolution, chunking and cube region. ### Keyword arguments * `bucket=nothing` specify an OBS bucket for example "obs-esdc-v2.0.0" - * `store=""` specify the root path of the cube, for example "esdc-8d-0.25deg-184x90x90-2.0.0.zarr" + * `store=nothing` specify the root path of the cube, for example "esdc-8d-0.25deg-184x90x90-2.0.0.zarr" * `res="low"` pick a datacube resolution (`"low"` or `"high"` for v2 or `"low"` or `"tiny"` for v3) * `chunks="ts"` choose a chunking (`"ts"` for time series access or `"map"` for spatial analyses) * `region="global"` choose a datacube (either `"global"` or `"Colombia"`), works only for esdc v2 - * `version=3` + * `version=nothing` """ -function esdd(;bucket=nothing, store="", res="low", chunks="ts", region="global", version=3) - if version == 2 - if bucket===nothing - bucket, store = cubesdict[(res,chunks,region)] - end - elseif version == 3 - if bucket===nothing - bucket = "esdl-esdc-v3.0.2" - if res=="tiny" - store = cubesdict3[res] +function esdd(; bucket = nothing, store = nothing, res = "low", chunks = "ts", region = "global", version = nothing) + + if version === nothing + if region == "global" + if res == "high" + version = 2 else - store = cubesdict3[chunks] + version = 3 end + elseif region == "Colombia" + version = 2 end end + + k = (res, chunks, region, version) + + # give a sensible error if key does not exist + if !haskey(cubesdict, k) + @info "possible keys are" keys(cubesdict) + error("key $(k) does not exist") + end + b, s = cubesdict[k] + + # switch out defaults + if bucket === nothing + bucket = b + end + if store === nothing + store = s + end + path = "https://s3.bgc-jena.mpg.de:9000/" * bucket * "/" * store - open_dataset(zopen(path,consolidated=true,fill_as_missing=true)) + open_dataset(zopen(path, consolidated = true, fill_as_missing = true)) end """ @@ -70,10 +84,11 @@ and `store` or pick a resolution, chunking and cube region. ### Keyword arguments * `bucket=nothing` specify an OBS bucket for example "obs-esdc-v2.0.0" - * `store=""` specify the root path of the cube, for example "esdc-8d-0.25deg-184x90x90-2.0.0.zarr" + * `store=nothing` specify the root path of the cube, for example "esdc-8d-0.25deg-184x90x90-2.0.0.zarr" * `res="low"` pick a datacube resolution (`"low"` or `"high"`) * `chunks="ts"` choose a chunking (`"ts"` for time series access or `"map"` for spatial analyses) * `region="global"` choose a datacube (either `"global"` or `"Colombia"`) + * `version=nothing` """ esdc(;kwargs...) = Cube(esdd(;kwargs...),target_type = Union{Float32,Missing}) diff --git a/test/access.jl b/test/access.jl index 9777cca..19bc218 100644 --- a/test/access.jl +++ b/test/access.jl @@ -1,4 +1,5 @@ using Dates +import DimensionalData c=Cube() @@ -126,4 +127,22 @@ end c = esdd(res="tiny") c.gross_primary_productivity[time=DD.Near(DateTime(2005))].data[44,14] == 2.3713999f0 -end \ No newline at end of file +end + +@testset "esdd smarts" begin + c1 = esdc(region = "Colombia") + @test DimensionalData.bounds(c1, :lon) == (-82.9587215, -60.0421465) + @test DimensionalData.bounds(c1, :lat) == (-13.957917500000002, 13.9586375) + + c2 = esdc() # global low resolution + @test DimensionalData.bounds(c2, :lon) == (-179.875, 179.875) + @test DimensionalData.span(c2, :lon).step == 0.25 + + c3 = esdc(res = "high") # global high resolution + @test DimensionalData.bounds(c3, :lon) == (-179.95833333333331, 179.95833333333331) + @test DimensionalData.span(c3, :lon).step == 0.08333333333333333 + + c4 = esdc(res = "tiny") # global tiny cube + @test DimensionalData.span(c4, :lon).step == 2.5 + @test DimensionalData.bounds(c4, :lon) == (-178.75, 178.75) +end