arkimet.formatter package

Module contents

class arkimet.formatter.Formatter[source]

Registry for metadata formatters implemented in Python.

This is used to register formatter implementations, and access them while formatting.

Use arkimet.Formatter to do the actual formatting: it will call either into this or in C++ implementations as needed.

format(t: Dict[str, Any]) str[source]

Look up and call a formatter for the given metadata item.

formatters = {'area': [<function format_area>], 'level': [<function format_level>], 'origin': [<function format_origin>], 'proddef': [<function format_proddef>], 'product': [<function format_product>], 'timerange': [<function format_timerange>]}
classmethod register(type: str, formatter: Callable[[Dict[str, Any]], Optional[str]])[source]

Register a callable as a formatter for the given metadata type.

A registered callable can return None to fall back on previously registered callables. This allows to add formatters for specific cases only, without losing the default handling.

Submodules

arkimet.formatter.area module

arkimet.formatter.area.format_area(v)[source]

arkimet.formatter.eccodes module

class arkimet.formatter.eccodes.GribTable(edition: int, table: str)[source]

Read a grib table.

edition is the GRIB edition: 1 or 2

table is the table name, for example “0.0”

Returns a table where the index maps to a couple { abbreviation, description }, or nil if the file had no such entry.

For convenience, the table has also two functions, ‘abbr’ and ‘desc’, that return the abbreviation or the description, falling back on returning the table index if they are not available.

For example:

origins = GribTable(1, “0”) print(origins.abbr(98)) – Prints ‘ecmf’ print(origins.desc(98)) – Prints ‘European Center for Medium-Range Weather Forecasts’ print(origins.abbr(999)) – Prints ‘999’ print(origins.desc(999)) – Prints ‘999’

abbr(val: int) str[source]

Get an abbreviated description

cache = {(1, '0'): <arkimet.formatter.eccodes.GribTable object>}
desc(val: int) str[source]

Get a long description

classmethod get_grib2_table_prefix(centre, table_version, local_table_version)[source]
has(val: int) bool[source]
classmethod load(edition: int, table: str) arkimet.formatter.eccodes.GribTable[source]
re_table_line = re.compile('^\\s*(?P<idx>\\d+)\\s+(?P<abbr>\\S+)\\s+(?P<desc>.+)$')
set(code: int, abbr: str, desc: str)[source]

Add/replace a value in the table

arkimet.formatter.eccodes.get_eccodes_def_dir() str[source]

get the list of directories (separated by :) where grib_api/eccodes keep their definitions

arkimet.formatter.formatter module

This module implements a registry of Python formatters for various metadata types, along with default implementations.

class arkimet.formatter.formatter.Formatter[source]

Registry for metadata formatters implemented in Python.

This is used to register formatter implementations, and access them while formatting.

Use arkimet.Formatter to do the actual formatting: it will call either into this or in C++ implementations as needed.

format(t: Dict[str, Any]) str[source]

Look up and call a formatter for the given metadata item.

formatters = {'area': [<function format_area>], 'level': [<function format_level>], 'origin': [<function format_origin>], 'proddef': [<function format_proddef>], 'product': [<function format_product>], 'timerange': [<function format_timerange>]}
classmethod register(type: str, formatter: Callable[[Dict[str, Any]], Optional[str]])[source]

Register a callable as a formatter for the given metadata type.

A registered callable can return None to fall back on previously registered callables. This allows to add formatters for specific cases only, without losing the default handling.

arkimet.formatter.level module

arkimet.formatter.level.format_level(v)[source]

arkimet.formatter.origin module

arkimet.formatter.origin.format_origin(v)[source]

Format an origin: return a string, or None to fall back to other formatters

arkimet.formatter.proddef module

arkimet.formatter.proddef.format_proddef(v)[source]

arkimet.formatter.product module

arkimet.formatter.product.format_product(v)[source]

Format a product: return a string, or nil to fall back to other formatters

arkimet.formatter.timerange module

arkimet.formatter.timerange.format_timerange(v)[source]