Skip to content

Commit

Permalink
WIP ESDC_v3 (#297)
Browse files Browse the repository at this point in the history
* Add path to version 3 of esdc

* Add tests for esdc v3
  • Loading branch information
meggart committed Jun 12, 2023
1 parent e2dd142 commit 866add5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
27 changes: 20 additions & 7 deletions src/esdc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ global cubesdict


function __init__()
global cubesdict
global cubesdict, cubesdict3
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"),
Expand All @@ -18,6 +18,11 @@ function __init__()
("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",
)
end

"""
Expand All @@ -31,20 +36,28 @@ and `store` or pick a resolution, chunking and cube region.
* `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"
* `res="low"` pick a datacube resolution (`"low"` or `"high"`)
* `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"`)
* `region="global"` choose a datacube (either `"global"` or `"Colombia"`), works only for esdc v2
* `version=3`
"""
function esdd(;bucket=nothing, store="", res="low", chunks="ts", region="global", version=2)
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
path = "https://s3.bgc-jena.mpg.de:9000/" * bucket * "/" * store
open_dataset(zopen(path,consolidated=true,fill_as_missing=true))
elseif version == 3
error("Not yet implemented")
if bucket===nothing
bucket = "esdl-esdc-v3.0.2"
if res=="tiny"
store = cubesdict3[res]
else
store = cubesdict3[chunks]
end
end
end
path = "https://s3.bgc-jena.mpg.de:9000/" * bucket * "/" * store
open_dataset(zopen(path,consolidated=true,fill_as_missing=true))
end

"""
Expand Down
11 changes: 11 additions & 0 deletions test/access.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ d.data.v.indices==(18:21, 17:20, 93:414)
@test d.axes[2] == RangeAxis("lat", 50.875:-0.25:50.125)
end



@testset "Access multiple variables" begin
d2 = subsetcube(c,variable=["air_temperature_2m","gross_primary_productivity"],lon=(10,11),lat=(50,51),
time=(Date("2002-01-01"),Date("2008-12-31")))
Expand Down Expand Up @@ -126,3 +128,12 @@ using DiskArrayTools: DiskArrayStack
cnc = Cube(ncf)
@test all(cnc.data[:,:,:,:] .== danom.data[:,:,:,:])
end

@testset "ESDC v3" begin
c = esdd(res="low")
d = c.gross_primary_productivity[time=Date(2005)][443:444,139:140]
d == Float32[3.1673577 3.7342484; 3.3267372 4.0305696]

c = esdd(res="tiny")
c.gross_primary_productivity[time=Date(2005)][44,14] == 2.3713999f0
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Test
newcubedir = mktempdir()
YAXdir(newcubedir)
# Download Cube subset
c = esdc()
c = esdc(version=2)

cgermany = c[
region = "Germany",
Expand Down

0 comments on commit 866add5

Please sign in to comment.