Skip to content

Commit 2654ecb

Browse files
solve ambiguities with filter
1 parent 923a524 commit 2654ecb

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

src/cfconventions.jl

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,9 @@ end
4242

4343
allowmissing(x::AbstractArray{T}) where {T} = convert(AbstractArray{Union{T, Missing}}, x)
4444

45-
"""
46-
data = CommonDataModel.filter(ncv, indices...; accepted_status_flags = nothing)
4745

48-
Load and filter observations by replacing all variables without an acepted status
49-
flag to `missing`. It is used the attribute `ancillary_variables` to identify
50-
the status flag.
5146

52-
```
53-
# da["data"] is 2D matrix
54-
good_data = NCDatasets.filter(ds["data"],:,:, accepted_status_flags = ["good_data","probably_good_data"])
55-
```
56-
57-
"""
58-
function filter(ncv::AbstractVariable, indices...; accepted_status_flags = nothing)
59-
#function filter_(ncv, indices...)
60-
# accepted_status_flags = ("good_value", "probably_good_value")
47+
function _filter(ncv::AbstractVariable, indices::Union{<:Integer,AbstractVector{<:Integer},Colon}...; accepted_status_flags = nothing)
6148
data = allowmissing(ncv[indices...])
6249

6350
if (accepted_status_flags != nothing)
@@ -99,6 +86,27 @@ function filter(ncv::AbstractVariable, indices...; accepted_status_flags = nothi
9986
return data
10087
end
10188

89+
"""
90+
data = CommonDataModel.filter(ncv, indices...; accepted_status_flags = nothing)
91+
92+
Load and filter observations by replacing all variables without an acepted status
93+
flag to `missing`. It is used the attribute `ancillary_variables` to identify
94+
the status flag.
95+
96+
```
97+
# da["data"] is 2D matrix
98+
good_data = NCDatasets.filter(ds["data"],:,:, accepted_status_flags = ["good_data","probably_good_data"])
99+
```
100+
101+
"""
102+
filter(ncv::AbstractVariable, indices::TIndices...; kwargs...) =
103+
_filter(ncv, indices...; kwargs...)
104+
105+
filter(ncv::AbstractVariable, indices::Vector{<:Integer}; kwargs...) =
106+
_filter(ncv, indices...; kwargs...)
107+
108+
filter(ncv::AbstractVariable, indices::BitVector; kwargs...) =
109+
_filter(ncv, indices...; kwargs...)
102110

103111
"""
104112
cv = coord(v::Union{CFVariable,Variable},standard_name)

src/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
const SymbolOrString = Union{Symbol, AbstractString}
33

4-
4+
const TIndices = Union{<:Integer,AbstractVector{<:Integer},AbstractArray{<:CartesianIndex}, CartesianIndex ,Colon}
55

66
"""
77

0 commit comments

Comments
 (0)