dballe types

Measured variables

A measured variable is represented by a dballe.Var object, which contains a value (int, float, or str) annotated with information in a dballe.Varinfo object.

dballe.Varinfo objects are catalogued in dballe.Vartable tables, which associate WMO B variable codes (like B12101) to name, descriptions, measurement units, significant digits, and so on.

dballe.Var, dballe.Varinfo, and dballe.Vartable come via wreport, and dballe.txt contents (see Local B table codes) can be accessed with the shortcut functions dballe.varinfo() and dballe.var().

class dballe.Var

Var holds a measured value, which can be integer, float or string, and a `wreport.Varinfo`_ with all available information (description, unit, precision, …) related to it.

Var objects can be created from a `wreport.Varinfo`_ object, and an optional value. Omitting the value creates an unset variable.

Examples:

v = wreport.Var(table["B12101"], 32.5)
# v.info returns detailed informations about the variable in a Varinfo object.
print("%s: %s %s %s" % (v.code, str(v), v.info.unit, v.info.desc))
code

variable code

enq() → Union[str, float, int]

get the value of the variable, as int, float or str according the variable definition

enqa(code: str) → Optional[wreport.Var]

get the variable for the attribute with the given code, or None if not found

enqc() → str

get the value of the variable, as a str

enqd() → float

get the value of the variable, as a float

enqi() → int

get the value of the variable, as an int

format(default: str=) → str

return a string with the formatted value of the variable

get(default: Any=None) → Union[str, float, long, Any]

get the value of the variable, with a default if it is unset

get_attrs() → List[wreport.Var]

get the attributes of this variable

info

Varinfo for this variable

isset

true if the value is set

seta(var: wreport.Var)

set an attribute in the variable

unseta(code: str)

unset the given attribute from the variable

class dballe.Varinfo

Varinfo object holds all possible information about a variable, such as its measurement unit, description and number of significant digits.

Varinfo objects cannot be instantiated directly, and are created by querying `wreport.Vartable`_ objects.

bit_len

number of bits used to encode the value in BUFR

bit_ref

reference value added after scaling, for BUFR decoding

code

variable code

desc

description

len

number of significant digits

scale

scale of the value as a power of 10

type

return a string describing the type of the variable (string, binary, integer, decimal)

unit

measurement unit

class dballe.Vartable

Collection of Varinfo objects indexed by WMO BUFR/CREX table B code.

A Vartable is instantiated by the name (without extension) of the table file installed in wreport’s data directory (normally, /usr/share/wreport/):

table = wreport.Vartable("B0000000000000023000")
print(table["B12101"].desc)

for i in table:
    print(i.code, i.desc)
get_bufr(basename: str=None, originating_centre: int=0, originating_subcentre: int=0, master_table_number: int=0, master_table_version_number: int=None, master_table_version_number_local: int=0) → wreport.Vartable

Look up a table B file using the information given, then load BUFR information from it.

You need to provide either basename or master_table_version_number.

get_crex(basename: str=None, edition_number=2, originating_centre: int=0, originating_subcentre: int=0, master_table_number: int=0, master_table_version_number: int=None, master_table_version_number_bufr: int=None, master_table_version_number_local: int=0) → wreport.Vartable

Look up a table B file using the information given, then load CREX information from it.

You need to provide either basename or master_table_version_number or master_table_version_number_bufr.

load_bufr(pathname: str) → wreport.Vartable

Load BUFR information from a Table B file and return it as a wreport.Vartable.

load_crex(pathname: str) → wreport.Vartable

Load CREX information from a Table B file and return it as a wreport.Vartable.

pathname

name of the table

dballe.varinfo(str) → dballe.Varinfo

Query the DB-All.e variable table returning a Varinfo

dballe.var(code, val: Any=None) → dballe.Var

Query the DB-All.e variable table returning a Var, optionally initialized with a value

Variable metadata

dballe.Level, dballe.Trange, dballe.Station, and dballe.DBStation, together with python’s datetime.datetime class, can be used to describe the DB-All.e metadata for measured variables, as shortcuts for groups of closely related values.

The difference between dballe.Station and dballe.DBStation is that the DB version also contains the database ID as ana_id.

DB-All.e also provides dballe.describe_level() and dballe.describe_trange() to turn level and timerange information into a string describing them.

class dballe.Level

Level or layer.

Constructor: Level(ltype1: int=None, l1: int=None, ltype2: int=None, l2: int=None)

l1

value of the level or of the first layer

l2

value of the second layer

ltype1

type of the level or of the first layer

ltype2

type of the second layer

class dballe.Trange

Time range.

Constructor: Trange(pind: int=None, p1: int=None, p2: int=None)

p1

Time range P1 indicator

p2

Time range P2 indicator

pind

Time range type indicator

class dballe.Station

Station information.

Constructor: Station(report: str, lat: float, lon: float, ident: str=None)

ident

mobile station identifier

lat

station latitude

lon

station longitude

report

report for this station

class dballe.DBStation

Station information with database ID.

Constructor: Station(report: str, id: int, lat: float, lon: float, ident: str=None)

id

database ID for this station

ident

mobile station identifier

lat

station latitude

lon

station longitude

report

report for this station

dballe.describe_level(ltype1: int, l1: int=None, ltype2: int=None, l2: int=None) → str

Return a string description for a level

dballe.describe_trange(pind: int, p1: int=None, p2: int=None) → str

Return a string description for a time range

Variables and their metadata

dballe.Data finally provides a way to group together one or more variables and their metadata.

class dballe.Data

key-value representation of a value with its associated metadata.

This is used when inserting values in a database, and can be indexed and assigned using insert parameters: see Parameters used when inserting values for a list.

Indexing by variable code also works. Assignment can take None, int, str, float, or a wreport.Var object. Assigning a wreport.Var object with a different varcode performs automatic unit conversion if possible.

For example:

# Select B12001 values and convert them to B12101
with tr.query_data({"var": "B12001"}) as cur:
    self.assertEqual(cur.remaining, 1)
    for rec in cur:
        data = rec.data
        rec.remove()
        # This converts units automatically
        data["B12101"] = data["12001"]
        del data["B12001"]
        tr.insert_data(data)