GRIB 格式#
- reki.format.grib.eccodes.load_field_from_file(file_path: str | Path, parameter: str | Dict = None, level_type: str | Dict = None, level: int | float | List | Dict | str = None, level_dim: str | None = None, field_name: str | None = None, show_progress: bool = False, **kwargs) DataArray | None#
Load one field from local GRIB2 file using eccodes-python. Or load multi levels into one field.
- 参数:
file_path (str or Path)
parameter (str or Dict) --
parameter name.
Use GRIB key shortName or a dict of filter conditions such as:
{ "discipline": 0, "parameterCategory": 2, "parameterNumber": 225, }
level_type (str or Dict or None) --
level type.
Use "pl", "ml" or "sfc". They will be converted into dict.
- Use GRIB key typeOfLevel, such as
"isobaricInhPa"
"isobaricInPa"
"surface"
"heightAboveGround"
"nominalTop"
"atmosphere"
"meanSea"
"depthBelowLandLayer"
...
See https://apps.ecmwf.int/codes/grib/format/edition-independent/3/ for more values.
If typeOfLevel is not available, use dict to specify filter conditions. For example, to get one filed from GRAPES GFS modelvar GRIB2 file, use:
{ "typeOfFirstFixedSurface": 131 }
level (int or float or List or Dict or None) --
level value(s).
If use a scalar, level will be a non-dimension coordinate.
If your want to extract multi levels, use a list and level will be a dimension (level, lat, lon).
- If use a dict, message will be filtered by dict keys. Support custom calculate keys:
first_levelsecond_level
If use "all", all levels of level_type will be packed in the result field.
If use None, only the first field will be returned.
level_dim (str or None) --
name of level dimension. If none, function will generate a name for level dim. If level_type="pl", some values can be used:
None or pl or isobaricInhPa: level_dim is a float number with unit hPa.
isobaricInPa: level_dim is a float number with unit Pa.
field_name --
name of field.
- If
None, generate field name automatically. use
parameterif it's a stringuse GRIB Key shortName if it's not unknown
use GRIB Keys to combine a name: discipline_parameterCategory_parameterNumber
- If
If string, set the field's name with it.
show_progress (bool) -- show progress bar.
- 返回:
DataArray if found, or None if not.
- 返回类型:
DataArray or None
示例
Load 850hPa temperature field from a GRIB2 file generated by GRAPES GFS.
>>> load_field_from_file( ... file_path="/sstorage1/COMMONDATA/OPER/NWPC/GRAPES_GFS_GMF/Prod-grib/2020031721/ORIG/gmf.gra.2020031800105.grb2", ... parameter="t", ... level_type="isobaricInhPa", ... level=850, ... ) <xarray.DataArray 't' (latitude: 720, longitude: 1440)> array([[249.19234375, 249.16234375, 249.16234375, ..., 249.15234375, 249.19234375, 249.14234375], [249.45234375, 249.45234375, 249.42234375, ..., 249.45234375, 249.44234375, 249.44234375], [249.69234375, 249.68234375, 249.68234375, ..., 249.70234375, 249.67234375, 249.68234375], ..., [235.33234375, 235.45234375, 235.62234375, ..., 235.47234375, 235.63234375, 235.48234375], [235.78234375, 235.91234375, 235.64234375, ..., 235.80234375, 235.72234375, 235.82234375], [235.66234375, 235.86234375, 235.82234375, ..., 235.85234375, 235.68234375, 235.70234375]]) Coordinates: time datetime64[ns] 2020-03-18 step timedelta64[ns] 4 days 09:00:00 valid_time datetime64[ns] 2020-03-22T09:00:00 isobaricInhPa int64 850 * latitude (latitude) float64 89.88 89.62 89.38 ... -89.38 -89.62 -89.88 * longitude (longitude) float64 0.0 0.25 0.5 0.75 ... 359.2 359.5 359.8 Attributes: GRIB_edition: 2 GRIB_centre: babj GRIB_subCentre: 0 GRIB_tablesVersion: 4 GRIB_localTablesVersion: 1 GRIB_dataType: fc GRIB_dataDate: 20200318 GRIB_dataTime: 0 GRIB_validityDate: 20200322 GRIB_validityTime: 900 GRIB_step: 105 GRIB_stepType: instant GRIB_stepUnits: 1 GRIB_stepRange: 105 GRIB_endStep: 105 GRIB_name: Temperature GRIB_shortName: t GRIB_cfName: air_temperature GRIB_discipline: 0 GRIB_parameterCategory: 0 GRIB_parameterNumber: 0 GRIB_gridType: regular_ll GRIB_gridDefinitionDescription: Latitude/longitude GRIB_typeOfFirstFixedSurface: pl GRIB_typeOfLevel: isobaricInhPa GRIB_level: 850 GRIB_numberOfPoints: 1036800 GRIB_missingValue: 9999 GRIB_units: K long_name: Temperature units: K