harphub / harpIO

IO functions for HARP
https://harphub.github.io/harpIO/
Other
6 stars 16 forks source link

Extend grib_opts to allow more explicit grib message selection #66

Closed andrew-MET closed 3 years ago

andrew-MET commented 3 years ago

Resolves #46

Grib messages can now be selected more explicitly using the new param_find and level_find arguments in grib_opts(). This can be necessary when local grib tables are used and shortNames are unknown, or fields use a different vertical coordinate than expected.

The PR also introduces a set of functions use_grib_*() to help set the values for param_find and level_find.

As an example, a grib file containing precipitation with indicatorOfParameter = 206 and unknown grib shortName can be read with:

read_forecast(
  ...,
  parameter = "Pcp",
  ...,
  file_format_opts = grib_opts(
    param_find = list(Pcp = use_grib_indicatorOfParameter(206))
  )
)

Another example might have 2m temperature stored with shortName "TA" and on the surface coordinate:

read_forecast(
  ...,
  parameter = "T2m",
  ...,
  file_format_opts = grib_opts(
    param_find = list(T2m = use_grib_shortName("TA")),
    level_find = list(T2m = use_grib_surface())
  )
)

Additionally level find can be used to select multiple vertical levels from grib files (read_grid() or read_forecast() can only read in one or all levels)

read_forecast(
  ...,
  parameter = "T",
  ...,
  file_format_opts = grib_opts(
    level_find = list(T = use_grib_pressure(c(1000, 850, 700)))
  )
)