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 be select!ed.
  • All keys passed to Index must be select!ed before accessing any messages.
  • Like with GribFile, retreiving a message from an Index advances the Index.
  • Only the latest value select!ed per key is kept in the Index.
  • Files with multi-field messages cannot be used with Index. This includes most files created by NCEP.

API

GRIB.IndexMethod
Index(filename::AbstractString, keys...)

Create an index from a file with the given keys.

source
GRIB.IndexMethod
Index(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
source
GRIB.addfile!Function
addfile!(index::Index, filename::AbstractString)

Index the file at filename using index.

source
GRIB.keycountFunction
keycount(index::Index, key::AbstractString)

Get the number of distinct values of the key contained in the index.

source
GRIB.select!Function
select!(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
source