diff --git a/Project.toml b/Project.toml index 2af3d7b..f346e24 100644 --- a/Project.toml +++ b/Project.toml @@ -16,7 +16,7 @@ RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00" [compat] Aqua = "0.8.9" CSV = "0.10" -CommonDataModel = "0.3" +CommonDataModel = "0.4" Compat = "4.10" Dates = "1" DiskArrays = "0.3, 0.4" diff --git a/src/Instruments/IASI/VariableExtra.jl b/src/Instruments/IASI/VariableExtra.jl index 5d46ba7..8c4de9a 100644 --- a/src/Instruments/IASI/VariableExtra.jl +++ b/src/Instruments/IASI/VariableExtra.jl @@ -28,7 +28,7 @@ function CDM.variable( T = eltype(disk_array) N = ndims(disk_array) - return MetopVariable{T, N, R}(ds, disk_array, varname) + return MetopVariable{T, N, R, typeof(disk_array)}(ds, disk_array, varname) else return default_variable(ds, varname) end @@ -106,7 +106,7 @@ function CDM.variable( data_array = getfield(gaird, varname) T = eltype(data_array) N = ndims(data_array) - return MetopVariable{T, N, R}(ds, data_array, varname) + return MetopVariable{T, N, R, typeof(data_array)}(ds, data_array, varname) end return default_variable(ds, varname) diff --git a/src/InterfaceDataModel/variable.jl b/src/InterfaceDataModel/variable.jl index 5c0731d..eb46c41 100644 --- a/src/InterfaceDataModel/variable.jl +++ b/src/InterfaceDataModel/variable.jl @@ -7,9 +7,9 @@ `MetopVariable` wraps an `AbstractArray` so it can be used with `MetopDataset`. The data array is normally `AbstractMetopDiskArray`. """ -struct MetopVariable{T, N, R} <: CDM.AbstractVariable{T, N} +struct MetopVariable{T, N, R, A <: AbstractArray{T, N}} <: CDM.AbstractVariable{T, N} parent::MetopDataset{R} - data_array::AbstractArray{T, N} + data_array::A field_name::Symbol end @@ -80,7 +80,7 @@ function default_variable(ds::MetopDataset{R}, varname::CDM.SymbolOrString) wher T = eltype(disk_array) N = ndims(disk_array) - return MetopVariable{T, N, R}(ds, disk_array, varname) + return MetopVariable{T, N, R, typeof(disk_array)}(ds, disk_array, varname) end function default_dimnames(v::MetopVariable{T, N, R}) where {T, N, R} @@ -130,12 +130,21 @@ function CDM.attrib(v::MetopVariable, name::CDM.SymbolOrString) end Base.size(v::MetopVariable) = size(v.data_array) +Base.parent(v::MetopVariable) = v.data_array -### get index -function Base.getindex(v::MetopVariable, indices...) - checkbounds(v, indices...) - return getindex(v.data_array, indices...) +function DiskArrays.readblock!(v::MetopVariable{T, N, R, <:DiskArrays.AbstractArray}, + aout, + indexes::Vararg{OrdinalRange, N}) where {T, N, R} + return DiskArrays.readblock!(parent(v), aout, indexes...) end + +function DiskArrays.readblock!(v::MetopVariable{T, N}, + aout, + indexes::Vararg{OrdinalRange, N}) where {T, N} + aout .= getindex(parent(v), indexes...) + return nothing +end + # fix ambiguity Base.getindex(v::MetopVariable, n::CDM.CFStdName) = getindex(v::CDM.AbstractVariable, n) function Base.getindex(v::MetopVariable, name::CDM.SymbolOrString) diff --git a/src/MetopDatasets.jl b/src/MetopDatasets.jl index a308c1a..135b3e8 100644 --- a/src/MetopDatasets.jl +++ b/src/MetopDatasets.jl @@ -7,7 +7,7 @@ using Dates: DateFormat, Day, Millisecond, Microsecond, format import CommonDataModel as CDM import CSV import Dates: DateTime -import Base: size, keys, close, getindex +import Base: size, keys, close, getindex, parent import DiskArrays using Compat: @compat using PrecompileTools: @setup_workload, @compile_workload @@ -36,7 +36,7 @@ Returns path to folder storing reduced test data. Note that the test data is dow the first time the function it called. """ get_test_data_artifact() = joinpath( - LazyArtifacts.artifact"test_data_MetopDatasets", "reduced_data") + LazyArtifacts.artifact"test_data_MetopDatasets", "reduced_data") export MetopDataset