YAXArrays.jl icon indicating copy to clipboard operation
YAXArrays.jl copied to clipboard

mapCube not saving cube when using path argument in the outdims

Open jcortesr opened this issue 3 years ago • 0 comments

Only when I try it as below it does not work, i.e., wrapping the mapCube function in another function:

axlist = [
    RangeAxis("time", Date(1979,1,1):Day(1):Date(2021,12,31)),
    RangeAxis("lon", range(-60,-70, length=11)),
    RangeAxis("lat", range(-30, -40, length=11)),
    ]
data = rand(Bool,length(axlist[1]), 11, 11)
ds = YAXArray(axlist, data)

function aggregate(xout, xin)
    for m in xout.Time.values
        aggval = sum(xin[time=(m, m + Year(1) - Day(1))].data)
        xout[Time=m].data .= aggval
    end
end

function aggregate(cube::YAXArray, var_name, thr)
    indims = InDims("Time", artype=YAXArray)
    ym = unique(year.(cube.time.values))
    outdims = OutDims(RangeAxis("Time", Date.(ym)), artype=YAXArray, outtype = UInt16, path =  "/scratch/jcortes/git_test_$(var_name)_$thr.zarr")
    mapCube(aggregate, cube; indims, outdims)
end 

var_names  = ["t2m", "t2mmax", "t2mmin", "tp", "spei_30", "spei_90", "spei_180"]
thrs = [0.95, 0.05]

for var_name in var_names
    for thr in thrs
        event_cube = ds
        aggregate(event_cube, var_name, thr)                    
    end
end

The above code runs without errors, but the cubes are not saved.

jcortesr avatar Sep 30 '22 14:09 jcortesr