getobs.getobs

Class to handle requests to the observation database. Incoming observations are stored in a raw format in the database, this class is used to prepare or compute the observations as needed for the Wetterturnier (the parameters forecasted).

Todo

Link to repos containing the observation parser.

class getobs.getobs(config, db, city, date, wmoww=None)[source]

Main observation handling class. Loading observations from the ‘raw’ database (Obsdatabase) and computes the observations required for the tournament (e.g, daily sunshine duration or precipitation sums (sum over 24h between pre-specified times). These values are stored into the Wetterturnier Wordpress Plugin and used for the penalties/judging.

Parameters:
  • config (list) – Contains all necessary configs for the pywetterturnier package. Please have a look into See utils.readconfig() for more details.
  • db (database.database) – A pywetterturnier (database.database object handling the database I/O.
  • city (int) – Numeric city ID.

:param date (datetime.datetime.date object with the date for which: the request should be made. :param wmoww: Or None. If None, no conversion will

be performed. If set the utils.wmowwConversion.convert() method is used to convert observed weather codes into the required ones.
__init__(config, db, city, date, wmoww=None)[source]

Initialization of the @ref getobs.getobs class.

__weakref__

list of weak references to the object (if defined)

_add_obs_value_(parameter, wmo, value)[source]

Adds a loaded observation to the final data object stored on the parent getobs.getobs object. Appends all data to the public attribute getobs.getobs.data.

Parameters:
  • parameter (str) – Parameter shortname.
  • wmo (int) – WMO station number.
  • value (float) – Either a numeric value or None.
_get_proper_WvWn_(w1, ww_now, ww_after, returnlist=False)[source]

Helper class to properly prepare Wv and Wn. Returns highest observed value “w1” where observed w1=1,2,3 will be set to w1=0. In additioin, ww is considered in two ways: input inww contains the values which are used to check the ‘past weather’ (do not include the leading hour, e.g., do not include 0600 UTC for the time period 0600 UTC to 1200 UTC) while inxX contains the same data (ww) but including the leading hour and is used to extract ‘current weather’ from the ww observations.

Please see documentation of utils.wmowwConversion() and check the config file (wmo_ww.conf) to see what will be converted into what.

Parameters:
  • inw1 (int) – Observed w1 value (may contain None or ‘missing observation’ numbers (e.g, w1=10)
  • ww_now (list) – List of all observed ww values (may contain None values and ‘missing observation’ numbers (e.g., ww=508). Similar to ww_after but contains less data (not including leading hour). From this list values 20-29 will be neglected!
  • ww_after (list) – List of all observed ww values (may contain None values and ‘missing observation’ numbers (e.g., ww=508). From this list only values 20-19 will be consisered!
  • returnlist (bool) – If set to true not only one single value will be returned but a list of all observed w1/ww/wX whch are considiered in this method. Is used for the raincheck where we don’t want to have the highest number only but all (as if highest is 9 (thunderstorm) it might have been a dry thunderstorm, but there might be additional reports on rain before/after).
Returns:

Returns a single value between 0 and 90 (w1=0 to we=90, multiplied by 10 as it will be stored in the databases) or None if no valid w1 is available.

Return type:

float

_prepare_fun_N_(station, special)[source]

Helper function for cloud cover at 12 UTC. Return value will be in 1/10 octas, rounded to full octas [0,10,20,30,…,80]. Observations based on database column cc.

  1. if observation is available: return value
  2. if observation not recorded but 12 UTC database entry exists we assume that there were no clouds: return 0
  3. else: return None
Parameters:
Returns:

Returns observed value if loading data was successful or None if observation not available or nor recorded.

Return type:

float

_prepare_fun_PPP_(station, special)[source]

Helper function for mean sea level pressure at 12 UTC. Based on database column pmsl. Return value will be in 1/10 hPa.

Parameters:
Returns:

Returns observed value if loading data was successful or None if observation not available or nor recorded.

Return type:

float

_prepare_fun_RR_(station, special)[source]

Helper function for 24h sum of precipitation based on database column ‘rrr12’ at +18 and +30h (as the reported observations are 12h sums this means from 06 UTC today to 06 UTC tomorrow). Returns precipitation in 1/10 mm OR -30 if there was no precipitation at all. Note: if there is no recorded precipitation amount or the amount of precipitation recorded is 0.0 I also check the W1 observations for the time period of interest. If there is no sign. precipitation weather recorded in W1 (w1 = 5, 6, 7, 8 or 9) the value will be set to -3.0. In addition w1/ww are checked to set precip sum to 0 if -0.1 sum’s were received but rain weather types have been reported in the same time. Therefore the method getobs._prepare_fun_Wall_() is used for the time period 0600 to 0600 UTC of the following day.

First: if database entry for 18 UTC is here but there is no recorded amount of precipitation we have to assume that there was no precipitation. The same for +30h (06 UTC next day).

Second: If observed precipitation amount is negative (some stations send -0.1mm/12h for no precipitation) we

Third: If w1/ww reports precipitation types [5,6,7,8] but rain sum is -0.1 (-3.0): return 0.0 for precip!

Parameters:
Returns:

Returns observed value if loading data was successful or None if observation not available or nor recorded.

Return type:

float

_prepare_fun_Sd_(station, special)[source]

Helper function for relative sun shine duration for the full day. Will be returned in 1/10 percent rounded to full percent (34% will result in 340.).

  1. if 24h sum is available on ‘sunday’ on 06 UTC we will take this value.
  2. if 06UTC sunday is not available but we have a sunday value at 00 UTC: take this one.
  3. else sum up the ‘sun’ 1h-rly obs. WARNING: seems that ‘none’ is either ‘no sun’ or ‘not reported’. I can’t decide which one is which one at the moment. I just take none = 0 and sum up.
Parameters:
Returns:

Returns observed value if loading data was successful or None if observation not available or nor recorded.

Return type:

float

_prepare_fun_TTd_(station, special)[source]

Helper function for dew point temperature. Returns 12 UTC observed dew point temperature from database column td in 1/10 degrees Celsius.

Parameters:
Returns:

Returns observed value if loading data was successful or None if observation not available or nor recorded.

Return type:

float

_prepare_fun_TTm_(station, special)[source]

Helper function for TTM, maximum temperature. Returns 18 UTC maximum temperature, either from column tmax12 or - if tmax12 not available but tmax24 exists - maximum temperature from tmax24. Temperature will be in 1/10 degrees Celsius.

Parameters:
Returns:

Returns observed value if loading data was successful or None if observation not available or nor recorded.

Return type:

float

_prepare_fun_TTn_(station, special)[source]

Helper function for TTN, minimum temperature. Returns 06 UTC minimum temperature. Simply the tmin12 column at 06 UTC in 1/10 degrees Celsius.

Parameters:
Returns:

Returns observed value if loading data was successful or None if observation not available or nor recorded.

Return type:

float

_prepare_fun_Wall_(station, special)[source]

Helper function for significant weather for 24h period between 0600 to 0600 UTC. This function is used internally when computing the observed precipitation sum. If precipitation would return a -3.0 (-0.1mm/24h) but there were observed precipitation classes, set precipitation sum to 0.

Parameters:
Returns:

Returns None if no valid Wv/Wn could have been computed, else a float between 00. and 90. (for Wv/Wn = [0,1,2,3,…,9] as [0.,10.,…,90.]) will be returned.

Return type:

float

_prepare_fun_Wn_(station, special)[source]

Helper function for significant weather for afternoon between 1200 UTC and 1800 UTC. w1 (past weather) at 1800 UTC is used (main obs time, w1 contains weathr over last 6 hours), the past weather (ww) observations for 1200 UTC to 1800 UTC are used to identify “current weather” while ww between 1300 UTC to 1800 UTC is used to check the “past weather” (ww=20 to ww=29). Uses _get_proper_WvWn_() method, the detailed rules can be found in the method description from the helper class (_get_proper_WvWn_()).

Parameters:
Returns:

Returns None if no valid Wv/Wn could have been computed, else a float between 00. and 90. (for Wv/Wn = [0,1,2,3,…,9] as [0.,10.,…,90.]) will be returned.

Return type:

float

_prepare_fun_Wv_(station, special)[source]

Helper function for significant weather for noon between 0600 UTC and 1200 UTC. w1 (past weather) at 1200 UTC is used (main obs time, w1 contains weathr over last 6 hours), the past weather (ww) observations for 0600 UTC to 1200 UTC are used to identify “current weather” while ww between 0700 UTC to 1200 UTC is used to check the “past weather” (ww=20 to ww=29). Uses _get_proper_WvWn_() method, the detailed rules can be found in the method description from the helper class (_get_proper_WvWn_()).

Parameters:
Returns:

Returns None if no valid Wv/Wn could have been computed, else a float between 00. and 90. (for Wv/Wn = [0,1,2,3,…,9] as [0.,10.,…,90.]) will be returned.

Return type:

float

_prepare_fun_dd_(station, special)[source]

Helper function for the wind direction at 12 UTC from database column dd. Values will be returned in 1/10 degrees but rounded to full 10 degrees. E.g., observed ‘138’ degrees will be converted into ‘1400’ (1/10 degrees, rounded to full 10 degrees). Special case: also depends on database column ff. The following cases will be used:

  1. if dd not observed/received: return None
  2. if dd==0 and ff==0: return 0.0
  3. if dd==0 and ff>0: return None (variable wind direction)
  4. else: return value
Parameters:
Returns:

Returns observed value if loading data was successful or None if observation not available or nor recorded.

Return type:

float

_prepare_fun_ff_(station, special)[source]

Helper function for the wind speed at 12 UTC. Based on database column ff. Values will be in 1/10 knots but rounded to full knots. E.g., if 3.2m/s observed -> 6.22kt -> Return value will be 60.

Parameters:
Returns:

Returns observed value if loading data was successful or None if observation not available or nor recorded.

Return type:

float

_prepare_fun_fx_(station, special)[source]

Helper function for the maximum gust speed (fx > 25kt). Based on database column fx1. Return value will be in 1/10 knots but rounded to full knots. E.g., if 21.2m/s observed -> 41.21kt -> Return value will be 410. Special cases:

  1. no observation available but +30h observation (row) is in database: Assume that there were no gusts at all: return 0
  2. no observations available and +30h observation (row) not yet in database: return None
  3. observation available, below 25 knots: return 0
  4. observation available, >= 25 knots: return value
Parameters:
Returns:

Returns observed value if loading data was successful or None if observation not available or nor recorded.

Return type:

float

check_record(wmo, hour)[source]

Checks if database record exists. Just checks if for the current date/time/station combination a row exists in the database and not what a specific cell contains. Note: date, and table name are coming from the public attributes of @ref getobs.getobs .

Parameters:
  • wmo (int) – WMO station number.
  • hour (int) – Hour time shift relative to the ‘date’, 00:00 UTC. As an example: hour=30 means that we are checking ‘tomorrow 06:00 UTC’.
Returns:

False if no such row exists, else True.

Return type:

bool

get_columns(table)[source]

Returns database table columns.

Parameters:table (str) – Name of the database table.
Results:
list: A list of all available table columns.

Todo

reference to database required here.

get_maximum_Sd(stations, date)[source]

Computes astronomic (maximum) sun shine duration for a set of stations. Note that the station has to be stored in the database table obs.stations. If not, we dont know the position of the station and therefore we can’t compute astronomical sunshine duration resulting in a None value. Uses external python package @astral.

Parameters:
  • stations (list) – of stationclass.stationclass objects.
  • date (datetime.datetime.date) – Date object for which the data should be retrieved or for which date the day length should be computed.
Returns:

A dict consisting of WMO station number and the length of the astronomic day in seconds.

Return type:

dict

load_obs(wmo, hour, parameter)[source]

Loading a specific observation from the database. The date for which the observation should be valid and the name of the database are coming from the public attributes of the class (@ref getobs.getobs).

Parameters:
  • wmo (int) – Numeric WMO station number.
  • hour (int) – Hour for which the observation should be valid [0,…,24], in UTC.
  • parameter (str) – Parameter name (short name) for which observations should be loaded.
Returns:

None will be returned if the database

is empty or the parameter could not have been found, Else the numeric value is returned by this method.

Return type:

float or None

load_special_obs(wmo, special)[source]

Loading a specific observation from the database. The date for which the observation should be valid and the name of the database are coming from the public attributes of the class (see getobs.getobs).

Parameters:
  • wmo (int) – WMO station number.
  • special (getobs.getobs.special_obs_class) – Selector for handling special requests (modifies the time-selector).
Returns:

Either a numeric value or None if the cell in the database was empty (NULL).

Return type:

float

prepare(parameter, special=None)[source]

Prepares the different observed parameters like TTn, TTm, N, and so on (depending on what’s defined in the database table params). Note that the script will ignore a wrong specified or unknown parameter as the internal method then does not exist. The date will be taken from the public arguments of the parent class :class`getobs.getobs`. The additional data (specified via special input argument will only be used when the final value is not yet available.

Parameters:
  • parameter (str) – shortname of the Wetterturnier parameters.
  • special (str) – String with a very specific format. This is to compute some live observations such as min/max.

Examples

Prepare weather type parameter Wv, in addition select database column w1 and select all available observations between 07:00 today and 18:00 of the requested date (today), see input argument date on getobs.getobs.

x.prepare( "Wv", "w1 today 07:00 to today 12:00" )

Compute minimum temperature TTn, in addition select database column T between yesterday 18:00 and today 06:00.

x.prepare( "TTn", "T yesterday 18:00 to today 6:00" )

Todo

Reference to database table param.

show()[source]

Shows a summary of the current @ref getobs.getobs class. Was mainly used for development purposes. Shows data and stuff stored on class attributes.

class special_obs_object(special, date)[source]

This class is used to parse the ‘special’ input arguments to getobs.getobs.load_special_obs`().

__init__(special, date)[source]

This class is used to parse the ‘special’ input arguments to get_obs.

Parameters:
  • special (str) – String in a very special format.
  • date (datetime.date) – Date object (date of the tournament).
__weakref__

list of weak references to the object (if defined)

write_to_db()[source]

Write prepared observations to database. Writes all prepared observations which are stored in the parent getobs.getobs to the Wetterturnier database.

Nested class getobs.getobs.special_obs_object

The getobs.getobs contains a nested class called getobs.getobs.special_obs_object to handle special input arguments for getobs.getobs.get_speical_obs().

class getobs.special_obs_object(special, date)[source]

This class is used to parse the ‘special’ input arguments to getobs.getobs.load_special_obs`().