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 btable) 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
Varinfowith all available information (description, unit, precision, …) related to it.Var objects can be created from a
Varinfoobject, and an optional value. Omitting the value creates an unset variable.Examples:
table = wreport.Vartable.get_bufr(master_table_version_number=24) 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))
Constructor: Var(varinfo: Union[wreport.Varinfo, wreport.Var], value: Union[str, int, float] = None)
If the variable is a scaled decimal, getting and setting its value using integers or strings will use the raw unscaled representation of its value. This provides a way to work with the exact underlying representation of values, without dealing with the potential limitations of floating point representations.
- code¶
variable code
- enq() str | float | int¶
get the value of the variable, as int, float or str according the variable definition
- enqa(code: str) wreport.Var | None¶
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
If the variable is a scaled decimal value, this returns its unscaled integer representation. This provides a way to work with the exact underlying representation of values, without dealing with the potential limitations of floating point representations.
- enqd() float¶
get the value of the variable, as a float
- enqi() int¶
get the value of the variable, as an int
If the variable is a scaled decimal value, this returns its unscaled integer representation. This provides a way to work with the exact underlying representation of values, without dealing with the potential limitations of floating point representations.
- format(default: str=) str¶
return a string with the formatted value of the variable
- get(default: Any = None) str | float | long | Any¶
get the value of the variable, as int, float or str according the variable definition. If the variable is unset,
defaultis returned
- 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
Vartableobjects.- 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 one of the
get_bufr(),get_crex(),load_bufr(),load_crex()class methods:table = wreport.Vartable.get_bufr(master_table_version_number=23) print(table["B12101"].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.
- Parameters:
basename – load the table with the given name in
/usr/share/wreport/originating_centre – originating centre for the table data
originating_subcentre – originating subcentre for the table data
master_table_number – master table number for the table data
master_table_version_number – master table version number for the table data
master_table_version_number_local – local master table version number for the table data
- 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.
- Parameters:
basename – load the table with the given name in
/usr/share/wreport/edition_number – edition number for the table data
originating_centre – originating centre for the table data
originating_subcentre – originating subcentre for the table data
master_table_number – master table number for the table data
master_table_version_number – master table version number for the table data
master_table_version_number_bufr – BUFR master table version number for the table data
master_table_version_number_local – local master table version number for the table data
- load_bufr(pathname: str) wreport.Vartable¶
Load BUFR information from a Table B file and return it as a wreport.Vartable.
- Parameters:
pathname – pathname of the file to load
- load_crex(pathname: str) wreport.Vartable¶
Load CREX information from a Table B file and return it as a wreport.Vartable.
- Parameters:
pathname – pathname of the file to load
- 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)
- describe()¶
Return a string description for this level
- 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)
- describe()¶
Return a string description for this time range
- 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
- ilat¶
station latitude (as integer)
- ilon¶
station longitude (as integer)
- 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
- ilat¶
station latitude (as integer)
- ilon¶
station longitude (as integer)
- 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.
See Convert values from one B code to another for an example.