CFMessage
CFMessage contains a number of utility functions for converting variables in a GRIB message to the values a user would expect to work with.
CfGRIB.COMPUTED_KEYS
— ConstantDictionary which maps a key to a conversion method. The first function is the 'to' conversion, the second is 'from'.
TODO: Actually applying the from_grib_step
function results in different values to cfgrib.py, so step -> (from_grib_step, to_grib_step)
is currently disabled.
Currently converts:
"time" => (from_grib_date_time, to_grib_date_time)
"valid_time" => (
message -> from_grib_date_time(message, date_key="validityDate", time_key="validityTime"),
message -> to_grib_date_time(message, date_key="validityDate", time_key="validityTime"),
)
"verifying_time" => (from_grib_month, m -> throw(ErrorException("Unimplemented")))
"indexing_time" => (
message -> from_grib_date_time(message, date_key="indexingDate", time_key="indexingTime"),
message -> to_grib_date_time(message, date_key="indexingDate", time_key="indexingTime"),
)
Example
A GRIB message containing 20160501
as the date key and 0
as the time key would end up calling:
julia> CfGRIB.COMPUTED_KEYS["time"](20160501, 0)
1462060800
CfGRIB.DEFAULT_EPOCH
— ConstantDates.DateTime
Default epoch used for from_
and to_
methods, set to 1970-01-01T00:00:00.
CfGRIB.GRIB_STEP_UNITS_TO_SECONDS
— ConstantArray{Union{Missing, Int64},1}
Array used to convert the grib step units to seconds. As Julia is 1-indexed, not 0 like Python, you should take care to correctly access the array, typically just +1 to the step units before using it as an index.
Taken from eccodes stepUnits.table
.
CfGRIB.build_valid_time
— FunctionReturns a pair of (dims, data)
based on the type of input
CfGRIB.build_valid_time
— Methodbuild_valid_time(time::Array{Int64,1}, step::Array{Int64,1}) -> Union{Tuple{Tuple{},Int64}, Tuple{Tuple{String,String},Array{Int64,2}}}
julia> CfGRIB.build_valid_time([10, 10], [10, 10])
(("time", "step"), [36010 36010; 36010 36010])
julia> CfGRIB.build_valid_time([10], [10])
((), 36010)
CfGRIB.build_valid_time
— Methodbuild_valid_time(time::Array{Int64,1}, step::Int64) -> Tuple{Tuple{String},Array{Int64,1}}
julia> CfGRIB.build_valid_time([10], 10)
(("time",), [36010])
CfGRIB.build_valid_time
— Methodbuild_valid_time(time::Int64, step::Array{Int64,1}) -> Tuple{Tuple{String},Array{Int64,1}}
julia> CfGRIB.build_valid_time(1, [10])
(("step",), [36001])
CfGRIB.build_valid_time
— Methodbuild_valid_time(time::Int64, step::Int64) -> Tuple{Tuple{},Int64}
julia> CfGRIB.build_valid_time(10, 10)
((), 36010)
CfGRIB.from_grib_date_time
— FunctionReturns the integer seconds from epoch to the given date and time.
from_grib_date_time(date, time; epoch)
from_grib_date_time(message; date_key, time_key, epoch)
CfGRIB.from_grib_date_time
— Methodfrom_grib_date_time(message::GRIB.Message; date_key, time_key, epoch) -> Union{Missing, Int64}
Pulls out the date and time from given keys and passes them to from_grib_date_time(::Int, ::Int)
CfGRIB.from_grib_date_time
— Methodfrom_grib_date_time(date::Int64, time::Int64; epoch) -> Int64
CfGRIB.from_grib_month
— Functionfrom_grib_month(message::GRIB.Message) -> Union{Missing, Int64}
from_grib_month(message::GRIB.Message, verifying_month_key::String) -> Union{Missing, Int64}
from_grib_month(message::GRIB.Message, verifying_month_key::String, epoch::Dates.DateTime) -> Union{Missing, Int64}
Returns the integer seconds from the epoch to the verifying month value in the GRIB message.
CfGRIB.from_grib_step
— Functionfrom_grib_step(message::GRIB.Message) -> Float64
from_grib_step(message::GRIB.Message, step_key::String) -> Float64
from_grib_step(message::GRIB.Message, step_key::String, step_unit_key::String) -> Float64
Returns the step_key
value in hours.
Uses GRIB_STEP_UNITS_TO_SECONDS
to convert the step values to seconds, then divides by 3600.0
to get hours.
CfGRIB.read_message
— Methodread_message(message::GRIB.Message, key::String) -> Any
Reads a specific key from a GRIB.jl message. Attempts to convert the raw value associated with that key using the COMPUTED_KEYS
mapping to from_grib_*
functions.