PyCDS

class pycds.Network(**kwargs)

This class maps to the table which represents various networks of data for the Climate Related Monitoring Program. There is one network row for each data provider, typically a BC Ministry, crown corporation or private company.

class pycds.Contact(**kwargs)

This class maps to the table which represents contact people and representatives for the networks of the Climate Related Monitoring Program.

class pycds.Variable(**kwargs)

This class maps to the table which records the details of the physical quantities which are recorded by the weather stations.

class pycds.Station(**kwargs)

This class maps to the table which represents a single weather station. One weather station can potentially have multiple physical locations (though, few do in practice) and periods of operation

class pycds.History(**kwargs)

This class maps to the table which represents a history record for a weather station. Since a station can potentially (and do) move small distances (e.g. from one end of the airport runway to another) or change the frequency of its observations, this table records the details of those changes.

class pycds.Obs(**kwargs)

This class maps to the table which records the details of weather observations. Each row is one single data point for one single quantity.

class pycds.CrmpNetworkGeoserver(**kwargs)

This table maps to a convenience view that is used by geoserver for mapping.

class pycds.ObsCountPerMonthHistory(**kwargs)

This class maps to a materialized view that is required for web app performance. It is used for approximating the number of observations which will be returned by station selection criteria.

class pycds.VarsPerHistory(**kwargs)

This class maps to a materialized view that is required for web app performance. It is used to link recorded quantities (variables) to the station/history level, rather than just the network level (just because one station in the network records a quantity, doesn’t mean that all stations in the network do). To some extent, this view is an add on to compensate for poor database normalization, but it’s close enough to get by.

class pycds.ObsWithFlags(**kwargs)

This class maps to a convenience view that is used to construct a table of flagged observations; i.e. one row per observation with additional columns for each attached flag.

class pycds.NativeFlag(**kwargs)

This class maps to the table which records all ‘flags’ for observations which have been flagged by the data provider (i.e. the network) for some reason. This table records the details of the flags. Actual flagging is recorded in the class/table ObsRawNativeFlags.

class pycds.PCICFlag(**kwargs)

This class maps to the table which records all ‘flags’ for observations which have been flagged by PCIC for some reason. This table records the details of the flags. Actual flagging is recorded in the class/table ObsRawNativeFlags.

class pycds.MetaSensor(**kwargs)
class pycds.util.TestContact(name, title, organization, email, phone)
email

Alias for field number 3

name

Alias for field number 0

organization

Alias for field number 2

phone

Alias for field number 4

title

Alias for field number 1

class pycds.util.TestHistory(station_name, elevation, sdate, edate, province, country, freq)
country

Alias for field number 5

edate

Alias for field number 3

elevation

Alias for field number 1

freq

Alias for field number 6

province

Alias for field number 4

sdate

Alias for field number 2

station_name

Alias for field number 0

class pycds.util.TestNetwork(name, long_name, color)
color

Alias for field number 2

long_name

Alias for field number 1

name

Alias for field number 0

class pycds.util.TestStation(native_id, network, histories)
histories

Alias for field number 2

native_id

Alias for field number 0

network

Alias for field number 1

class pycds.util.TestVariable(name, unit, standard_name, cell_method, precision, description, display_name, short_name, network)
cell_method

Alias for field number 3

description

Alias for field number 5

display_name

Alias for field number 6

name

Alias for field number 0

network

Alias for field number 8

precision

Alias for field number 4

short_name

Alias for field number 7

standard_name

Alias for field number 2

unit

Alias for field number 1

pycds.util.compile_query(statement, bind=None)

print a query, with values filled in for debugging purposes only for security, you should always separate queries from their values please also note that this function is quite slow

pycds.util.generic_sesh(sesh, sa_objects)

All session fixtures follow a common pattern, abstracted in this generator function.

Args:

sesh (sqlalchemy.orm.session.Session): database session

sa_objects: list of SQLAlchemy ORM objects to be added to database for setup and removed on teardown
Order within list is respected for setup and teardown, so that dependencies can be respected.
Returns:
yields sesh after setup

To use this generator correctly, i.e., so that the teardown after the yield is also performed, a fixture must first yield the result of next(g), then call next(g) again. This can be done two ways:

gs = generic_sesh(…) yield next(gs) next(gs)

or, slightly shorter:

for sesh in generic_sesh(…):
yield sesh

The shorter method is used throughout.

pycds.util.orm_station_table(sesh, stn_id, raw=True)

Construct a ‘station table’ i.e. a table such that each row corresponds to a single timestep and each column corresponds to a separate variable or flag

Parameters:
  • sesh – sqlalchemy session
  • stn_id (int) – id corresponding to meta_station.station_id or Station.id
  • raw (bool) – Should this query be for raw observations? Setting this to False will fetch climatologies.
Return type:

sqlalchemy.orm.query.Query