Python wreport package¶
Module contents¶
wreport provides access to weather data in BUFR and CREX formats.
This is the Python interface to it
-
wreport.convert_units(from_unit: str, to_unit: str, value: float) → float¶ convert a value from a unit to another, as understood by wreport
-
class
wreport.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)
-
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. 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
wreport.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
wreport.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
-