Query Clients#

The basic query clients, with some simple embellishments.

rubin_nights.connections.get_access_token(tokenfile=None)[source]#

Retrieve RSP access token.

Parameters:

tokenfile (str | None, default: None) –

Path to the RSP token file. See documentation on RSP tokens at https://rsp.lsst.io/guides/auth/creating-user-tokens.html The token will be read from the tokenfile if available. If tokenfile is None, then further attempts will be made to access the token value from:

  1. lsst.rsp.get_access_token

  2. the environment variable “ACCESS_TOKEN”

  3. the environment variable “ACCESS_TOKEN_FILE”

  4. the home directory + ‘.lsst’ + DEFAULT_TOKENFILE

If no RSP token is available, access to most services will not be available.

Returns:

token – Token value. A zero-length token will not be valid for use.

Return type:

str

Notes

RSP access tokens are unique to the different RSP sites, and the services which run on a particular site must receive tokens from the same site.

rubin_nights.connections.get_clients(tokenfile=None, site=None, auth_token=None)[source]#

Return a wide set of site-specific client connections.

Parameters:
  • tokenfile (str | None, default: None) – Path to the RSP tokenfile. See also get_access_token. Can be None if one of other methods to set token will be successful.

  • site (str | None, default: None) – Override site location to a preferred site. Most likely to be used to specify usdf-dev vs usdf. Note that this should be equivalent to the repertoire discovery site.

  • auth_token (str | None, default: None) – The authentication token itself. If not None, this will override any tokenfile argument. Useful in services running behind Gafaelfawr authentication.

Returns:

endpoints – Dictionary with efd, obsenv, sasquatch, narrative_log, exposure_log, night_log, and consdb connection information.

Return type:

dict

Note

The authentication token required to access the log services is an RSP token, and is RSP site-specific (including usdf vs usdf-dev). For users outside the RSP, a token can be created as described in https://rsp.lsst.io/v/usdfprod/guides/auth/creating-user-tokens.html

rubin_nights.connections.usdf_lfa(uri, bucket='s3://lfa@')[source]#

Convert LFA uri recorded in the EFD to a version accessible at USDF.

Parameters:
  • uri (str) – The URI written into the EFD from the summit.

  • bucket (str) – The bucket access at the USDF.

Returns:

uri – The LFA uri at USDF.

Return type:

str

rubin_nights.connections.usdf_s3_env()[source]#

Set convenient environment variables for USDF S3 use.

Return type:

None

class rubin_nights.consdb_query.AsyncConsDbFastAPI(api_base, auth_token, query_timeout=600)[source]#

Bases: ConsDb

Query the ConsDB through the REST API / FastAPI interface.

Asynchronous queries.

Parameters:
  • api_base (str) – Base API for services. e.g. https://usdf-rsp.slac.stanford.edu

  • auth_token (str) – The token for authentication.

  • query_timeout (float, default: 600) – Seconds to wait for the query to return data.

async query(query)[source]#

Execute asynchronous FastAPI ConsDB query.

Parameters:

query (str) – SQL query.

Returns:

results

Return type:

pd.DataFrame

class rubin_nights.consdb_query.ConsDbFastAPI(api_base, auth_token, query_timeout=600)[source]#

Bases: ConsDb

Query the ConsDB through the REST API / FastAPI interface.

Synchronous queries.

Parameters:
  • api_base (str) – Base API for services. e.g. https://usdf-rsp.slac.stanford.edu

  • auth_token (str) – The token for authentication to this service.

  • query_timeout (float, default: 600) – Seconds to wait for the query to return data.

query(query)[source]#

Execute synchronous FastAPI ConsDB query.

Parameters:

query (str) – SQL query.

Returns:

results

Return type:

pd.DataFrame

class rubin_nights.consdb_query.ConsDbSql(site='usdf', connection_string=None)[source]#

Bases: ConsDb

Query the ConsDB through pandas with a SQLAlchemy Postgres connection.

Parameters:
  • site (str, default: 'usdf') – Two options for site, to connect directly to the postgres servers, either ‘usdf’ or ‘summit’. Note that these postgres servers are not exposed outside of the USDF or Summit; you must use one of the other ConsDb query services in that case.

  • connection_string (str | None, default: None) – Optional kwarg to explicitly set the connection string instead of using the defaults for ‘usdf’ or ‘summit’.

Notes

Credentials must be available in ~/.lsst/postgres-credentials.txt

For access external to the USDF, base or summit, a different method must be used.

async async_query(query)[source]#

The ConsDbSql client uses sqlalchemy + pandas.read_sql. Async queries are unavailable.

Parameters:

query (str)

Return type:

DataFrame

query(query)[source]#

Execute a SQL query

Parameters:

query (str) – SQL query.

Returns:

results

Return type:

pd.DataFrame

class rubin_nights.consdb_query.ConsDbTap(api_base, auth_token, query_timeout=600)[source]#

Bases: ConsDb

Query the ConsDB through the TAP service.

Parameters:
  • api_base (str) – Base API for services. e.g. https://usdf-rsp.slac.stanford.edu

  • auth_token (str) – The token for authentication.

  • query_timeout (float, default: 600) – Seconds to wait for a query to complete, in remote service.

Notes

This class provides a pyvo.dal.TAPService connection to the Consdb, accessible at ConsDbTap.tap.

query(query)[source]#

Execute TAP ConsDB query.

Parameters:

query (str) – SQL query.

Returns:

results

Return type:

pd.DataFrame

class rubin_nights.influx_query.AsyncInfluxQueryClient(site='usdf', db_name='efd', repertoire_site=None, auth_token=None, influx_auth_file=None, id_tag=None, query_timeout=300)[source]#

Bases: InfluxQueryClientBase

Parameters:
  • site (str, default: 'usdf')

  • db_name (str, default: 'efd')

  • repertoire_site (str | None, default: None)

  • auth_token (str | None, default: None)

  • influx_auth_file (str | Path | None, default: None)

  • id_tag (str | None, default: None)

  • query_timeout (float, default: 300)

async get_fields(measurement)[source]#

Query the list of field names for a topic.

Parameters:

measurement (str) – Name of measurement/topic to query for field names.

Returns:

fields – fieldKey / fieldType values.

Return type:

pd.DataFrame

async get_topics()[source]#

Find all available topics.

Return type:

list[str]

async query(query)[source]#

Send and receive results from the InfluxDB API, async.

Parameters:

query (str) – The query to send to the InfluxDb.

Returns:

result

Return type:

pd.DataFrame

async select_time_series(topic_name, fields, t_start, t_end, index=None)[source]#

Async query to return data from topic_name between t_start and t_end.

Parameters:
  • topic_name (str) – The name of the topic or measurement to query.

  • fields (str | list[str]) – The field or fields to return from topic_name. The entry ‘*’ will return all fields.

  • t_start (Time) – The start of the time window for the query.

  • t_end (Time) – The end of the time window for the query.

  • index (int | None, default: None)

Returns:

query_results – The result of the query.

Return type:

pd.DataFrame

async select_top_n(topic_name, fields, num, time_cut=None, index=None)[source]#

Async query to return num records from topic_name.

Parameters:
  • topic_name (str) – The name of the topic or measurement to query.

  • fields (str | list[str]) – The field or fields to return from topic_name. The entry ‘*’ will return all fields.

  • num (int) – The number of records to return.

  • time_cut (Time, default: None) – If not None, looks for records prior to this time.

  • index (int | None, default: None)

Returns:

query_results – The result of the query.

Return type:

pd.DataFrame

setup_client(influx_auth)[source]#

Override in the specific sync or async class.

Parameters:

influx_auth (tuple[str, str])

Return type:

None

class rubin_nights.influx_query.InfluxQueryClient(site='usdf', db_name='efd', repertoire_site=None, auth_token=None, influx_auth_file=None, id_tag=None, query_timeout=300)[source]#

Bases: InfluxQueryClientBase

Parameters:
  • site (str, default: 'usdf')

  • db_name (str, default: 'efd')

  • repertoire_site (str | None, default: None)

  • auth_token (str | None, default: None)

  • influx_auth_file (str | Path | None, default: None)

  • id_tag (str | None, default: None)

  • query_timeout (float, default: 300)

get_fields(measurement)[source]#

Query the list of field names for a topic.

Parameters:

measurement (str) – Name of measurement/topic to query for field names.

Returns:

fields – fieldKey / fieldType values.

Return type:

pd.DataFrame

get_topics()[source]#

Find all available topics.

Return type:

list[str]

query(query)[source]#

Send and receive results from the InfluxDB API.

Parameters:

query (str) – The query to send to the InfluxDb.

Returns:

result

Return type:

pd.DataFrame

select_time_series(topic_name, fields, t_start, t_end, index=None)[source]#

Sync query to return data from topic_name between t_start and t_end.

Parameters:
  • topic_name (str) – The name of the topic or measurement to query.

  • fields (str | list[str]) – The field or fields to return from topic_name. The entry ‘*’ will return all fields.

  • t_start (Time) – The start of the time window for the query.

  • t_end (Time) – The end of the time window for the query.

  • index (int | None, default: None)

Returns:

query_results – The result of the query.

Return type:

pd.DataFrame

select_top_n(topic_name, fields, num, time_cut=None, index=None)[source]#

Sync query to return num records from topic_name.

Parameters:
  • topic_name (str) – The name of the topic or measurement to query.

  • fields (str | list[str]) – The field or fields to return from topic_name. The entry ‘*’ will return all fields.

  • num (int) – The number of records to return.

  • time_cut (Time, default: None) – If not None, looks for records prior to this time.

  • index (int | None, default: None)

Returns:

query_results – The result of the query.

Return type:

pd.DataFrame

setup_client(influx_auth)[source]#

Override in the specific sync or async class.

Parameters:

influx_auth (tuple[str, str])

Return type:

None

rubin_nights.influx_query.convert_time_to_tz_datetime(time)[source]#

Convert astropy Time to datetime.datetime with UTC timezone.

Useful for when you want to select EFD entries based on a Time, as the EFD indexes are timezone-aware datetimes.

Parameters:

time (Time)

Return type:

datetime

rubin_nights.influx_query.day_obs_from_efd_index(x)[source]#

Use with pandas apply(efd_values, axis=1) to get dayobs.

To be deprecated: Use day_obs_from_efd_index_array for faster conversion and safety in case of zero-length dataframes.

Parameters:

x (Series)

Return type:

int

rubin_nights.influx_query.day_obs_from_efd_index_array(utc_time_format)[source]#

Convert an array or series of astropy-readable times to dayobs ints.

>>> day_obs = day_obs_from_efd_index_array(efd_dataframe.index)
Parameters:

utc_time_format (Series | ndarray)

Return type:

Series | ndarray

class rubin_nights.logging_query.AsyncExposureLogClient(api_base, auth_token)[source]#

Bases: AsyncLoggingServiceClient, ExposureLogBase

Query for the exposure log, asynchronous.

Parameters:
async exposure_query(params)[source]#

Override to narrow the return type to list only.

Parameters:

params (dict[str, Any])

Return type:

DataFrame

async message_query(params)[source]#

Override to narrow the return type to list only.

Parameters:

params (dict[str, Any])

Return type:

DataFrame

async query_exposures(t_start, t_end, user_params=None)[source]#

Get exposure records over a specified timespan.

Parameters:
  • t_start (Time) – Time of start of exposure log exposure query.

  • t_end (Time) – Time of end of exposure log exposure query.

  • user_params (dict | None, default: None) – Additional parameters to add or override defaults. Passing {'limit': int} can override the default limit.

Returns:

exposures – Exposure log.

Return type:

pd.DataFrame

async query_log(t_start, t_end, user_params=None)[source]#

Get exposure log message entries over a specified timespan.

Parameters:
  • t_start (Time) – Time of start of exposure log message query.

  • t_end (Time) – Time of end of exposure log message query.

  • user_params (dict | None, default: None) – Additional parameters to add or override defaults. Passing {'limit': int} can override the default limit.

Returns:

messages – Exposure log messages.

Return type:

pd.DataFrame

class rubin_nights.logging_query.AsyncNarrativeLogClient(api_base, auth_token)[source]#

Bases: AsyncLoggingServiceClient, NarrativeLogBase

Query for the narrative log, asynchronous.

Parameters:
async query_log(t_start, t_end, user_params=None)[source]#

Async get narrative log entries over a specified timespan.

Parameters:
  • t_start (Time) – Time of start of narrative log query.

  • t_end (Time) – Time of end of narrative log query.

  • user_params (dict | None, default: None) – Additional parameters to add or override defaults. Passing {'limit': int} can override the default limit.

Returns:

messages – Narrative log messages.

Return type:

pd.DataFrame

Notes

Some modifications are made to the raw narrative logs. Extra space is stripped out and a simple “Log <component>” key is added to the dataframe (identifying Simonyi/Auxtel specific issues). The index is replaced by a time, in order to insert the narrative log values into other events at the telescope.

class rubin_nights.logging_query.ExposureLogClient(api_base, auth_token)[source]#

Bases: LoggingServiceClient, ExposureLogBase

Query for the exposure log.

Parameters:
exposure_query(params)[source]#

Query the exposure log for exposures.

Parameters:

params (dict[str, Any])

Return type:

DataFrame

message_query(params)[source]#

Query exposurelog messages.

Parameters:

params (dict[str, Any])

Return type:

DataFrame

query_exposures(t_start, t_end, user_params=None)[source]#

Get exposure records over a specified timespan.

Parameters:
  • t_start (Time) – Time of start of exposure log exposure query.

  • t_end (Time) – Time of end of exposure log exposure query.

  • user_params (dict | None, default: None) – Additional parameters to add or override defaults. Passing {'limit': int} can override the default limit.

Returns:

exposures – Exposure log.

Return type:

pd.DataFrame

query_log(t_start, t_end, user_params=None)[source]#

Get exposure log message entries over a specified timespan.

Parameters:
  • t_start (Time) – Time of start of exposure log message query.

  • t_end (Time) – Time of end of exposure log message query.

  • user_params (dict | None, default: None) – Additional parameters to add or override defaults. Passing {'limit': int} can override the default limit.

Returns:

messages – Exposure log messages.

Return type:

pd.DataFrame

class rubin_nights.logging_query.NarrativeLogClient(api_base, auth_token)[source]#

Bases: LoggingServiceClient, NarrativeLogBase

Query for the narrative log.

Parameters:
query_log(t_start, t_end, user_params=None)[source]#

Get narrative log entries over a specified timespan.

Parameters:
  • t_start (Time) – Time of start of narrative log query.

  • t_end (Time) – Time of end of narrative log query.

  • user_params (dict | None, default: None) – Additional parameters to add or override defaults. Passing {'limit': int} can override the default limit.

Returns:

messages – Narrative log messages.

Return type:

pd.DataFrame

Notes

Some modifications are made to the raw narrative logs. Extra space is stripped out and a simple “Log <component>” key is added to the dataframe (identifying Simonyi/Auxtel specific issues). The index is replaced by a time, in order to insert the narrative log values into other events at the telescope.

class rubin_nights.logging_query.NightReportClient(api_base, auth_token)[source]#

Bases: LoggingServiceClient

Query for the night report log. Synchronous only.

Parameters:
query_night_report(day_obs, telescope=None, return_html=True)[source]#

Fetch the night report logs.

Parameters:
  • day_obs (str | int) – The day_obs of the night report. Format YYYY-MM-DD (str) or YYYYMMDD (int).

  • telescope (Optional[Literal['AuxTel', 'Simonyi']], default: None) – Format the night report logs for this telescope. Options: AuxTel, Simonyi or None (None will return both). The night_report now returns both telescope’s summary reports.

  • return_html (bool, default: True) – Send back an HTML formatted version of the first night report log, optionally for a given telescope only.

Return type:

tuple[list[dict], str]

Returns:

  • night_reports (list {dict}) – The night report logs, which are a list (often a single-element list, but can be multiple during the night) of dictionary key:value pairs describing the night report.

  • html (str (optional)) – If return_html is True, also return an HTML formatted version of the night report, potentially for a given telescope only.

static query_params(day_obs)[source]#

Set query parameters for night report query.

Parameters:

day_obs (str | int) – The day_obs for the night report.

Returns:

params

Return type:

dict

query_report(params)[source]#

Override to narrow the return type to list only.

Parameters:

params (dict[str, Any])

Return type:

list[dict[Any, Any]]

This page was last modified on .