pecos.io module

The io module contains functions to read/send data and write results to files/html reports.

pecos.io.read_campbell_scientific(file_name, index_col='TIMESTAMP', encoding=None)[source]

Read Campbell Scientific CSV file.

Parameters:

file_name : string

File name, with full path

index_col : string (optional)

Index column name, default = ‘TIMESTAMP’

encoding : string (optional)

Character encoding (i.e. utf-16)

Returns:

df : pd.DataFrame

Data

pecos.io.send_email(subject, body, recipient, sender, attachment=None, host='localhost', username=None, password=None)[source]

Send email using python smtplib and email packages.

Parameters:

subject : string

Subject text

body : string

Email body, in HTML or plain format

recipient : list of string

Recipient email address or addresses

sender : string

Sender email address

attachment : string (optional)

Name of file to attach

host : string (optional)

Name of email host (or host:port), default = ‘localhost’

username : string (optional)

Email username for authentication

password : string (optional)

Email password for authentication

pecos.io.write_metrics(filename, metrics)[source]

Write metrics file.

Parameters:

filename : string

File name, with full path

metrics : pd.DataFrame

Data to add to the metrics file

pecos.io.write_test_results(filename, test_results)[source]

Write test results file.

Parameters:

filename : string

File name, with full path

test_results : pd.DataFrame

Test results stored in pm.test_results

pecos.io.write_monitoring_report(filename, pm, test_results_graphics=[], custom_graphics=[], metrics=None, title='Pecos Monitoring Report', config={}, logo=False, im_width_test_results=700, im_width_custom=700, encode=False)[source]

Generate a monitoring report. The monitoring report is used to report quality control test results for a single system. The report includes custom graphics, performance metrics, and test results.

Parameters:

filename : string

File name, with full path

pm : PerformanceMonitoring object

Contains data (pm.df) and test results (pm.test_results)

test_results_graphics : list of strings (optional)

Graphics files, with full path. These graphics highlight data points that failed a quality control test, created using pecos.graphics.plot_test_results()

custom_graphics : list of strings (optional)

Custom files, with full path. Created by the user.

metrics : pd.DataFrame (optional)

Performance metrics to add as a table to the monitoring report

title : string (optional)

Monitoring report title, default = ‘Pecos Monitoring Report’

config : dictionary (optional)

Configuration options, to be printed at the end of the report

logo : string (optional)

Graphic to be added to the report header

im_width_test_results=700 : float (optional)

Image width for test results graphics in the HTML report, default = 700

im_width_custom=700 : float (optional)

Image width for custom graphics in the HTML report, default = 700

encode : boolean (optional)

Encode graphics in the html, default = False

pecos.io.write_dashboard(filename, column_names, row_names, content, title='Pecos Dashboard', footnote='', logo=False, im_width=250, datatables=False, encode=False)[source]

Generate a dashboard. The dashboard is used to compare multiple systems. Each cell in the dashboard includes custom system graphics and metrics.

Parameters:

filename : string

File name, with full path

column_names : list of strings

Column names listed in the order they should appear in the dashboard, i.e. [‘location1’, ‘location2’]

row_names : list of strings

Row names listed in the order they should appear in the dashboard, i.e. [‘system1’, ‘system2’]

content : dictionary

Dashboard content for each cell.

Dictionary keys are tuples indicating the row name and column name, i.e. (‘row name’, ‘column name’), where ‘row name’ is in the list row_names and ‘column name’ is in the list column_names.

For each key, another dictionary is defined that contains the content to be included in each cell of the dashboard. Each cell can contain text, graphics, a table, and an html link. These are defined using the following keys:

  • text (string) = text at the top of each cell
  • graphics (list of strings) = a list of graphics file names. Each file name includes the full path
  • table (string) = a table in html format, for example a table of performance metrics. DataFrames can be converted to an html string using df.to_html() or df.transpose().to_html().
  • link (string) = html link, with full path
  • link text (string) = the name of the link, i.e. ‘Link to monitoring report’

For example:

content = {('row name', 'column name'): {
    'text': 'text at the top', 
    'graphic': ['C:\\pecos\\results\\custom_graphic.png'], 
    'table': df.to_html(), 
    'link': 'C:\\pecos\\results\\monitoring_report.html', 
    'link text': 'Link to monitoring report'}}

title : string (optional)

Dashboard title, default = ‘Pecos Dashboard’

footnote : string (optional)

Text to be added to the end of the report

logo : string (optional)

Graphic to be added to the report header

im_width : float (optional)

Image width in the HTML report, default = 250

datatables : boolean (optional)

Use datatables.net to format the dashboard, default = False. See https://datatables.net/ for more information.

encode : boolean (optional)

Encode graphics in the html, default = False