pyiem.observation module#

A class representing an observation stored in the IEM database

pyiem.observation.bounded(val, floor, ceiling)[source]#

Return val if is a finite number within [floor, ceiling], else None.

class pyiem.observation.ObservationData(dict=None, /, **kwargs)[source]#

Bases: UserDict

Opinionated dictionary that ensures some QC.

What it does.
  • Returns None when asked for a key that does not exist.

  • Checks value bounds when set with a key that exists within VALUE_BOUNDS

__getitem__(key)[source]#

Return None for missing keys.

Parameters:

key (str)

Return type:

Any

__setitem__(key, value)[source]#

Set item with bounds checking.

Parameters:
Return type:

None

pyiem.observation.get_summary_table(valid)[source]#

Optimize the summary table we potentially use.

Parameters:

valid (datetime with time zone) – Datetime

Returns:

str table to query

pyiem.observation.summary_update(txn, data)[source]#

Updates the summary table and returns affected rows.

Parameters:
  • txn (psycopg.transaction)

  • data (dict)

Returns:

affected rows count

Return type:

int

class pyiem.observation.Observation(station=None, network=None, valid=None, iemid=None, tzname=None)[source]#

Bases: object

my observation object

Parameters:
load(txn)[source]#

Load the current observation for this site and time

calc()[source]#

Compute things not usually computed

compute_iemid(txn)[source]#

Load in what our metadata is to save future queries

save(txn, force_current_log=False, skip_current=False)[source]#

Save this observation to the database via a psycopg transaction @param txn is a psycopg transaction @param force_current_log boolean - make sure this observation goes to the current_log table in the case that it is old, this allows reprocessing by the METAR ingestor et al @param skip_current boolean - optionally skip updating the current table. This is useful for partial obs @return: boolean if this updated one row each