Index
The Index
type is a way to reduce the size of a file so that only messages with specific key-value pairs are included. A typical use-case looks like this:
Index(filename, "shortName", "typeOfLevel", "level") do index
select!(index, "shortName", "t")
select!(index, "typeOfLevel", "isobaricInhPa")
select!(index, "level", 500)
for msg in index
# Do things with msg
end
end
This example selects all messages that are temperature at the 500 hPa level. Indexes are invaluable for reducing the complexity of the file before retreiving data from it. There are a few important things to note:
- Only keys passed to the
Index
when it is created can beselect!
ed. - All keys passed to
Index
must beselect!
ed before accessing any messages. - Like with
GribFile
, retreiving a message from anIndex
advances theIndex
. - Only the latest value
select!
ed per key is kept in theIndex
. - Files with multi-field messages cannot be used with
Index
. This includes most files created by NCEP.
API
GRIB.Index
— MethodIndex(filename::AbstractString, keys...)
Create an index from a file with the given keys.
GRIB.Index
— MethodIndex(f::Function, filename::AbstractString, keys...)
Create an index from a file with the given keys and automatically close the file.
Example
Index(filename, "shortName", "level") do index
# Do things with index
end
GRIB.addfile!
— Functionaddfile!(index::Index, filename::AbstractString)
Index the file at filename
using index
.
GRIB.keycount
— Functionkeycount(index::Index, key::AbstractString)
Get the number of distinct values of the key contained in the index.
GRIB.select!
— Functionselect!(index::Index, key::AbstractString, value::AbstractString)
select!(index::Index, key::AbstractString, value::AbstractFloat)
select!(index::Index, key::AbstractString, value::AbstractFloat)
Reduce the size of the index to messages that match the key-value pair.
Examples
Index(filename, "shortName") do index
select!(index, "shortName", "tp")
# Index now only has messages about total precipitation
end
Index(filename, "level") do index
select!(index, "level", 850)
# Index now only has messages at level 850
end
Base.iterate
— MethodIterate through the messages in the index.
GRIB.destroy
— MethodSafely destroy the index.