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

Esdc error #302

Open
wants to merge 3 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
73 changes: 44 additions & 29 deletions src/esdc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@


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

Expand All @@ -35,29 +33,45 @@
### 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")

Check warning on line 61 in src/esdc.jl

View check run for this annotation

Codecov / codecov/patch

src/esdc.jl#L60-L61

Added lines #L60 - L61 were not covered by tests
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

"""
Expand All @@ -70,10 +84,11 @@
### 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})
Expand Down
21 changes: 20 additions & 1 deletion test/access.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dates
import DimensionalData

c=Cube()

Expand Down Expand Up @@ -126,4 +127,22 @@ end

c = esdd(res="tiny")
c.gross_primary_productivity[time=DD.Near(DateTime(2005))].data[44,14] == 2.3713999f0
end
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
Loading