Skip to content
Timothy-Edward-Kendon edited this page Jun 6, 2019 · 4 revisions

get_pi_data.py

A script for extracting time series data from an OSI PI database

Requirements

  1. User needs to have python 3 installed
  2. User needs access rights to the PI database (For Equinor users, see accessIT)
  3. Equinor users need PI Network Manager running on their local machine.

Preparation before running

Create a list of tags you want to extract in a file. The name of the file can be specified as a command line argument but the default name is "tag.list". One tag per line. Lines starting with # will be ignored. Use say PI-Explorer to see a list of available tags.

Examples of usage:

For the tags in the tag.list file, the following extracts time series between 12:00 and 12:10 on the 7th of April 2019.

Using windowing option ‘se’

The windowing option “se” expects the user to provide 2 additional positioning arguments s and e, which represents the start and end datetimes for windowing. The key here is to wrap each datetime in " " and to avoid ambiguous datetimes.

python get_pi_data.py se "07.Apr.2019  12:00:00" "07.Apr.2019  12:10:00"
python get_pi_data.py se "Apr.07.2019  12:00:00" "12:10:00 Apr.2019.07"
python get_pi_data.py se "12:00 April.07.2019 " "12:10:00 2019.07.April"
python get_pi_data.py se "12:00 April/07/2019 " "12:10:00 2019/07/April" 

Using windowing option 'sw'

The windowing option “sw” expects the user to provide 1 positional argument, which is the start time, and one optional argument, which is the time window. As with the se option, the positional argument can be expressed in all reasonable datetime formats. The time window is optional because it defaults to 1 day. The optional argument flagged by -w has to take the following format

(<N1>d)(<N2>hrs)(<N3>m)(<N4>s)

where N1 N2, N3, and N4 represent a number, and d=days, hrs=hours, m=mins, s=seconds. At least one the bracketed items should be included if you specify the -w option. The following are all valid (note that the brackets themselves should be omitted):

python get_pi_data.py sw -w "2d10m" "12:00 April.07.2019"
python get_pi_data.py sw -w "2d2hrs5m" "12:00 April.07.2019"

To extract the time series in the example (ref 'se' case) you would type

python get_pi_data.py sw -w "10m" "12:00 April.07.2019"

Using windowing option 'ew'

Similar to sw, except that you specify the end time and the time window. In this case both arguments are optional. The time window defaults to 1 day and the end time defaults to the present time. To extract the time series in the example (ref 'se' case) you would type:

python get_pi_data.py ew -w "10m" -e "12:10 April.07.2019"

Additional Options

Averaging

A time series is fetched in packets. The values for the packets can be averaged so that only one value is written to file. So if the user is fetching a time series over the past 10 years and wants just daily averages, the following can be used:

python get_pi_data.py --pave --psize "1d" ew -w "3650d"

where --psize specifies the packet size with format as per time window, and --pave specifies that we want to average the values in the packet. The packet size is an optional parameter which defaults to one day. So in the above (verbose) example, the --psize "1d" does not need to be given.