EfdClient

class lsst_efd_client.EfdClient(efd_name, db_name='efd', port='443', creds_service='https://roundtable.lsst.codes/segwarides/', client=None)

Bases: object

Class to handle connections and basic queries

Parameters
efd_namestr

Name of the EFD instance for which to retrieve credentials.

db_namestr, optional

Name of the database within influxDB to query (‘efd’ by default).

portstr, optional

Port to use when querying the database (‘443’ by default).

creds_servicestr, optional

URL to the service to retrieve credentials (https://roundtable.lsst.codes/segwarides/ by default).

clientobject, optional

An instance of a class that ducktypes as aioinflux.InfluxDBClient. The intent is to be able to substitute a mocked client for testing.

Attributes Summary

deployment

influx_client

The aioinflux.client.InfluxDBClient used for queries.

subclasses

Methods Summary

build_time_range_query(topic_name, fields, ...)

Build a query based on a time range.

from_name(efd_name, *args, **kwargs)

Construct a client for the specific named subclass.

get_fields(topic_name)

Query the list of field names for a topic.

get_schema(topic)

Givent a topic, get a list of dictionaries describing the fields

get_topics()

Query the list of possible topics.

list_efd_names([creds_service])

List all valid names for EFD deployments available.

select_packed_time_series(topic_name, ...[, ...])

Select fields that are time samples and unpack them into a dataframe.

select_time_series(topic_name, fields, ...)

Select a time series for a set of topics in a single subsystem

select_top_n(topic_name, fields, num[, ...])

Select the most recent N samples from a set of topics in a single subsystem.

Attributes Documentation

deployment = ''
influx_client = None

The aioinflux.client.InfluxDBClient used for queries.

This should be used to execute queries not wrapped by this class.

subclasses = {}

Methods Documentation

build_time_range_query(topic_name, fields, start, end, is_window=False, index=None)

Build a query based on a time range.

Parameters
topic_namestr

Name of topic for which to build a query.

fieldsstr or list

Name of field(s) to query.

startastropy.time.Time

Start time of the time range, if is_window is specified, this will be the midpoint of the range.

endastropy.time.Time or astropy.time.TimeDelta

End time of the range either as an absolute time or a time offset from the start time.

is_windowbool, optional

If set and the end time is specified as a TimeDelta, compute a range centered on the start time (default is False).

indexint, optional

For indexed topics set this to the index of the topic to query (default is None).

Returns
querystr

A string containing the constructed query statement.

from_name(efd_name, *args, **kwargs)

Construct a client for the specific named subclass.

Parameters
efd_namestr

Name of the EFD instance for which to construct a client.

*args

Extra arguments to pass to the subclass constructor.

**kwargs

Extra keyword arguments to pass to the subclass constructor.

Raises
NotImpementedError

Raised if there is no subclass corresponding to the name.

async get_fields(topic_name)

Query the list of field names for a topic.

Parameters
topic_namestr

Name of topic to query for field names.

Returns
resultslist

List of field names in specified topic.

async get_schema(topic)

Givent a topic, get a list of dictionaries describing the fields

Parameters
topicstr

The name of the topic to query. A full list of valid topic names can be obtained using get_schema_topics.

Returns
resultPandas.DataFrame

A dataframe with the schema information for the topic. One row per field.

async get_topics()

Query the list of possible topics.

Returns
resultslist

List of valid topics in the database.

classmethod list_efd_names(creds_service='https://roundtable.lsst.codes/segwarides/')

List all valid names for EFD deployments available.

Parameters
creds_servicestr, optional
Returns
resultslist

A list of str each specifying the name of a valid deployment.

async select_packed_time_series(topic_name, base_fields, start, end, is_window=False, index=None, ref_timestamp_col='cRIO_timestamp', ref_timestamp_fmt='unix_tai', ref_timestamp_scale='tai')

Select fields that are time samples and unpack them into a dataframe.

Parameters
topic_namestr

Name of topic to query.

base_fieldsstr or list

Base field name(s) that will be expanded to query all vector entries.

startastropy.time.Time

Start time of the time range, if is_window is specified, this will be the midpoint of the range.

endastropy.time.Time or astropy.time.TimeDelta

End time of the range either as an absolute time or a time offset from the start time.

is_windowbool, optional

If set and the end time is specified as a TimeDelta, compute a range centered on the start time (default is False).

indexint, optional

For indexed topics set this to the index of the topic to query (default is False).

ref_timestamp_colstr, optional

Name of the field name to use to assign timestamps to unpacked vector fields (default is ‘cRIO_timestamp’).

ref_timestamp_fmtstr, optional

Format to use to translating ref_timestamp_col values (default is ‘unix_tai’).

ref_timestamp_scalestr, optional

Time scale to use in translating ref_timestamp_col values (default is ‘tai’).

Returns
resultpandas.DataFrame

A pandas.DataFrame containing the results of the query.

async select_time_series(topic_name, fields, start, end, is_window=False, index=None, convert_influx_index=False)

Select a time series for a set of topics in a single subsystem

Parameters
topic_namestr

Name of topic to query.

fieldsstr or list

Name of field(s) to query.

startastropy.time.Time

Start time of the time range, if is_window is specified, this will be the midpoint of the range.

endastropy.time.Time or astropy.time.TimeDelta

End time of the range either as an absolute time or a time offset from the start time.

is_windowbool, optional

If set and the end time is specified as a TimeDelta, compute a range centered on the start time (default is False).

indexint, optional

For indexed topics set this to the index of the topic to query (default is None).

convert_influx_indexbool, optional

Convert influxDB time index from TAI to UTC? This is for using legacy instances that may still have timestamps stored internally as TAI. Modern instances all store index timestamps as UTC natively. Default is False, don’t translate from TAI to UTC.

Returns
resultpandas.DataFrame

A pandas.DataFrame containing the results of the query.

async select_top_n(topic_name, fields, num, time_cut=None, index=None, convert_influx_index=False)

Select the most recent N samples from a set of topics in a single subsystem. This method does not guarantee sort direction of the returned rows.

Parameters
topic_namestr

Name of topic to query.

fieldsstr or list

Name of field(s) to query.

numint

Number of rows to return.

time_cutastropy.time.Time, optional

Use a time cut instead of the most recent entry. (default is None)

indexint, optional

For indexed topics set this to the index of the topic to query (default is None)

convert_influx_indexbool, optional

Convert influxDB time index from TAI to UTC? This is for using legacy instances that may still have timestamps stored internally as TAI. Modern instances all store index timestamps as UTC natively. Default is False, don’t translate from TAI to UTC.

Returns
resultpandas.DataFrame

A pandas.DataFrame containing teh results of the query.