|
| 1 | +# Quickstart |
| 2 | +# This script provides a quick demonstration of the basic usage of tagreader. It will show you the steps from importing the package to fetching data and making a plot. Some cells contain links to more details that can be found in the [manual](../docs/manual.md). |
| 3 | + |
| 4 | +# Start by importing the package: |
| 5 | +from tagreader import IMSClient, list_sources |
| 6 | + |
| 7 | +# If we don't know the name of the data source, we can check which PI (piwebapi) and IP.21 (aspenone) servers we have access to via Web API ([more details](https://equinor.github.io/tagreader-python/docs/about/usage/data-source)): |
| 8 | +print(list_sources("aspenone")) |
| 9 | + |
| 10 | +# Let's establish a web API connection to PINO. |
| 11 | +c = IMSClient(datasource="TRB") |
| 12 | + |
| 13 | +# After connecting, we can search for a tag ([more details](../docs/manual.md#searching-for-tags)): |
| 14 | +tags = list(map(str, c.search("AverageC*", return_desc=False))) |
| 15 | + |
| 16 | +# Selecting three of the tags found above, we can read values for a duration of 3.5 hours starting January 5th at 8 in the morning with 3-minute (180-seconds) intervals. The default query method is interpolated, but several other methods are available by providing the `read_type` argument. Timestamps are parsed using [pandas.Timestamp](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Timestamp.html), and can therefore be provided in many different string formats. [More details](../docs/manual.md#reading_data) |
| 17 | +df = c.read( |
| 18 | + tags, |
| 19 | + "05-Jan-2024 08:00:00", |
| 20 | + "15/01/24 11:30am", |
| 21 | + 180, |
| 22 | +) |
| 23 | +# *Note*: Tags with maps (relevant for some InfoPlus.21 servers) can be specified on the form `'tag;map'`, e.g. `'17B-HIC192;CS A_AUTO'`. |
| 24 | + |
| 25 | +# The result from the last call is a Pandas dataframe, and can be manipulated as such: |
| 26 | +print(df.tail()) |
| 27 | +print(df["AverageCPUTimeTest"].size) |
| 28 | +print(df["AverageCPUTimeVals"].loc["2024-01-05 11:24:00"]) |
| 29 | +print(max(df["AverageCPUTimeVals"])) |
| 30 | + |
| 31 | +# Sometimes it can be handy to obtain the unit and description for the tags: |
| 32 | +units = c.get_units(tags) |
| 33 | +desc = c.get_descriptions(tags) |
| 34 | +print(units) |
| 35 | +print(desc) |
| 36 | + |
| 37 | +# Requires matplotlib to be installed. |
| 38 | +# tag = tags[0] |
| 39 | +# df[tag].plot(grid=True, title=desc[tag]).set_ylabel(units[tag]) |
0 commit comments