Get data statistics#

This notebook shows how to use the get_stats method to get data from the AsyncAPI. It allows to get statistics about the data without loading it, which can be useful to get an overview of the data and to decide which data to load.

API-24SEA endpoint: https://api.24sea.eu/routes/v1/datasignals/stats

[5]:
# **Package Imports**
# - From the Python Standard Library
import logging
import os
import sys

# - API-24SEA
from api_24sea.version import __version__, parse_version
from api_24sea.datasignals.core import API

[6]:
# **Package Version**
print(f"Package {parse_version(__version__)}")

# **Notebook Configuration**
logger = logging.getLogger()
logger.setLevel(logging.WARNING)

Package Version(major=2, minor=1, patch=6, release=None, num=None)

Login Credentials

Do not store API credentials in plain text in your notebook. Rather use the python-dotenv package to load environment variables from a .env file.

[7]:
# **Set Sample API Credentials**
os.environ["API_24SEA_USERNAME"] = "Sample.User"
os.environ["API_24SEA_PASSWORD"] = "CheckOutSomeData!"

Statistics Example#

Get statistical parameters for the selected metrics and time range for the specified project and one or more locations.

The statistics calculated for every metric are the following:

  • max_: maximum value

  • min_: minimum value

  • avg_: average value

  • stddev_: standard deviation

  • variance_: variance

  • count_: count

  • countnotnull_: count of non-null values

  • median_: median value

  • q1_: first quartile

  • q3_: third quartile

  • mode_: mode

  • mintimestamp_: timestamp of the minimum value

  • maxtimestamp_: timestamp of the maximum value

[ ]:
# **API Initialization**
api = API()
# The Metrics Overview is a table containing all the locations and metrics
# available in the API, together with their metadata. It is useful to query it
# before getting data, to check which locations and metrics are available for
# the site you want to query.
m_o = api.metrics_overview

# site is the wind farm name you want to query. The parameter can also be
# a list of site names, e.g. ["windfarm", "windfarm2"]. Matching is
# case-insensitive and passing the "site-id" is also accepted, e.g. "windfarm"
# will match "WindFarm", but also "WF", "wf", etc.
site = "windfarm"
# Matching locations from Metrics Overview for the specified site
# Also partial names of locations are accepted, e.g. "a01" will match
# all locations containing "a01" in their name, such as "A01", "a01". Matching
# is case-insensitive.
locations = m_o[m_o["site"].str.lower() == site]["location"].unique().tolist()
# Metrics: partial matches and regexes are accepted.
# Spaces are interpreted as .* in the name.
# If you want to query all metrics, pass "all" or ["all"].
metrics = ["mean windspeed", "mean power", "mean yaw", "mean rpm",
           "mean pitch", "mean winddirection"]
# Start and end timestamp in ISO 8601 format. The API accepts also other
# formats, such as the one provided by
# https://www.elastic.co/docs/reference/elasticsearch/rest-apis/common-options#date-math
start_timestamp = "2020-03-01T00:00:00Z"
end_timestamp = "2020-06-01T00:00:00Z"

stats_df = api.get_stats(site, locations, metrics, start_timestamp, end_timestamp)
stats_df

metric avg count countnotnull max maxtimestamp median min mintimestamp mode q1 q3 stddev variance site location data_group statistic short_hand print_str
0 mean_WF_A01_pitch 53.305442 12887 12887 181.092861 2020-04-30T08:50:00+00:00 45.153488 -86.131771 2020-03-28T18:00:00+00:00 66.398788 44.013488 54.996638 19.628382 385.273376 WindFarm WFA01 scada mean pitch Pitch
1 mean_WF_A01_power 887.962483 12887 12887 3765.570578 2020-03-11T16:00:00+00:00 403.762354 -57.143372 2020-05-19T15:50:00+00:00 0.0 -3.392881 1275.300051 1163.053762 1352694.052959 WindFarm WFA01 scada mean power Power
2 mean_WF_A01_rpm 6.743165 12887 12887 11.244427 2020-03-12T12:20:00+00:00 7.025176 0.0 2020-03-01T00:20:00+00:00 0.0 4.949134 9.488106 3.510194 12.321463 WindFarm WFA01 scada mean rpm Rotor speed
3 mean_WF_A01_winddirection 148.826113 12880 12880 340.510079 2020-03-27T12:00:00+00:00 183.758007 7.621053 2020-05-14T12:20:00+00:00 21.577095 60.963421 211.973614 81.504743 6643.023207 WindFarm WFA01 scada mean winddirection Wind direction
4 mean_WF_A01_windspeed 11.567049 12875 12875 31.392411 2020-03-11T19:10:00+00:00 10.340554 1.218154 2020-03-01T01:00:00+00:00 8.18815 8.245163 13.968249 4.738203 22.450571 WindFarm WFA01 scada mean windspeed Wind speed
5 mean_WF_A01_yaw 200.028123 12875 12875 359.915861 2020-03-21T06:40:00+00:00 177.033961 -43.158374 2020-03-28T20:50:00+00:00 315.542861 107.300361 326.850061 116.137796 13487.987697 WindFarm WFA01 scada mean yaw Yaw
6 mean_WF_A02_pitch 55.277081 12789 12789 181.042861 2020-03-17T14:50:00+00:00 45.343388 -89.21203 2020-04-22T14:50:00+00:00 66.398788 44.020188 56.678288 23.057883 531.665981 WindFarm WFA02 scada mean pitch Pitch
7 mean_WF_A02_power 838.757361 12789 12789 3765.994109 2020-03-21T01:00:00+00:00 356.91991 -59.017616 2020-05-19T19:00:00+00:00 0.0 -7.338905 1177.507995 1131.943198 1281295.404286 WindFarm WFA02 scada mean power Power
8 mean_WF_A02_rpm 6.500222 12789 12789 11.699909 2020-03-08T05:40:00+00:00 6.999671 0.0 2020-03-01T00:10:00+00:00 0.0 4.35985 9.231297 3.680881 13.548884 WindFarm WFA02 scada mean rpm Rotor speed
9 mean_WF_A02_winddirection 149.820522 12778 12778 358.519112 2020-04-09T00:10:00+00:00 184.18562 5.366621 2020-03-09T13:50:00+00:00 18.63033 60.98125 213.173637 81.914104 6709.920367 WindFarm WFA02 scada mean winddirection Wind direction
10 mean_WF_A02_windspeed 11.240079 12771 12771 30.895205 2020-03-11T19:10:00+00:00 10.106204 0.815915 2020-03-09T12:20:00+00:00 7.95811 7.935652 13.818259 4.687034 21.968291 WindFarm WFA02 scada mean windspeed Wind speed
11 mean_WF_A02_yaw 196.959672 12771 12771 359.996361 2020-03-21T02:20:00+00:00 174.742861 -70.056842 2020-03-28T08:10:00+00:00 14.642861 102.685811 330.054061 118.936776 14145.9567 WindFarm WFA02 scada mean yaw Yaw