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

Fix open_mfdataset #477

Open
wants to merge 2 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "YAXArrays"
uuid = "c21b50f5-aa40-41ea-b809-c0f5e47bfa5c"
authors = ["Fabian Gans <fgans@bgc-jena.mpg.de>"]
version = "0.5.14"
version = "0.5.15"

[deps]
CFTime = "179af706-886a-5703-950a-314cd64e0468"
Expand Down
6 changes: 3 additions & 3 deletions src/DatasetAPI/Datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ using IntervalSets: Interval, (..)
using CFTime: timedecode, timeencode, DateTimeNoLeap, DateTime360Day, DateTimeAllLeap
using YAXArrayBase
using YAXArrayBase: iscontdimval, add_var
using DiskArrayTools: CFDiskArray, ConcatDiskArray
using DiskArrays: DiskArrays, GridChunks
using DiskArrayTools: CFDiskArray, diskstack
using DiskArrays: DiskArrays, GridChunks, ConcatDiskArray
using Glob: glob
using DimensionalData: DimensionalData as DD

Expand Down Expand Up @@ -341,7 +341,7 @@ function merge_new_axis(alldatasets, firstcube,var,mergedim)
newdim = DD.rebuild(mergedim,1:length(alldatasets))
alldiskarrays = map(ds->ds.cubes[var].data,alldatasets).data
newda = diskstack(alldiskarrays)
newdims = (DD.dim(firstcube)...,newdim)
newdims = (DD.dims(firstcube)...,newdim)
YAXArray(newdims,newda,deepcopy(firstcube.properties))
end
function merge_existing_axis(alldatasets,firstcube,var,mergedim)
Expand Down
33 changes: 33 additions & 0 deletions test/Datasets/datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,36 @@ end
ds = Dataset(a=a1, b=a2, c=a3, d=a4, e=a5)
@test_throws ArgumentError Cube(ds)
end

@testset "Open_mfdataset" begin
import NetCDF
d1 = DD.X(1:20)
d2 = DD.Y(1:10)
a1 = rand(20,10)
a2 = rand(20,10)
td = mktempdir()
f1, f2 = joinpath.(td,("file_1.nc","file_2.nc"))

array1 = YAXArray((d1,d2),a1)
array2 = YAXArray((d1,d2),a2)

savecube(array1,f1)
savecube(array2,f2)

ds = open_mfdataset(DD.DimArray([f1,f2],(DD.Ti(1:2),)))

@test ds.layer.data[:,:,1] == array1
@test ds.layer.data[:,:,2] == array2

td = mktempdir()
f1, f2 = joinpath.(td,("file_1.nc","file_2.nc"))
td1, td2 = DD.Ti(1:2), DD.Ti(3:4)
a1,a2 = rand(20,10,2), rand(20,10,2)
array1,array2 = YAXArray((d1,d2,td1),a1), YAXArray((d1,d2,td2),a2)
savecube(array1,f1)
savecube(array2,f2)

ds = open_mfdataset(joinpath(td,"*.nc"))
@test ds.layer.data[:,:,1:2] == array1
@test ds.layer.data[:,:,3:4] == array2
end
Loading