{ "cells": [ { "cell_type": "markdown", "id": "33be0049", "metadata": {}, "source": [ "# Null timestamps example\n", "\n", "This notebook shows how to retrieve timestamps where the requested metrics return null values.\n", "\n", "API-24SEA endpoint: [https://api.24sea.eu/routes/v1/datasignals/null_timestamps](https://api.24sea.eu/docs/v1/#/operations/datasignals_metrics_null_timestamps)\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "2b43a3b6", "metadata": {}, "outputs": [], "source": [ "# **Package Imports**\n", "# - From the Python Standard Library\n", "import logging\n", "import os\n", "import sys\n", "\n", "# - API-24SEA\n", "from api_24sea.version import __version__, parse_version\n", "from api_24sea.datasignals.core import AsyncAPI\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "c9444121", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Package Version(major=2, minor=1, patch=6, release=None, num=None)\n" ] } ], "source": [ "# **Package Version**\n", "print(f\"Package {parse_version(__version__)}\")\n", "\n", "# **Notebook Configuration**\n", "logger = logging.getLogger()\n", "logger.setLevel(logging.WARNING)\n" ] }, { "cell_type": "markdown", "id": "e3e8afcd", "metadata": {}, "source": [ "
\n", "

Login Credentials

\n", " \n", " \n", " \n", " \n", "

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.

\n", "
" ] }, { "cell_type": "code", "execution_count": 3, "id": "fa19611b", "metadata": {}, "outputs": [], "source": [ "# **Set Sample API Credentials**\n", "os.environ[\"API_24SEA_USERNAME\"] = \"Sample.User\"\n", "os.environ[\"API_24SEA_PASSWORD\"] = \"CheckOutSomeData!\"\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "af59711e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Package Version(major=2, minor=1, patch=6, release=None, num=None)\n" ] } ], "source": [ "# **Package Versions**\n", "print(f\"Package {parse_version(__version__)}\")\n", "# **Notebook Configuration**\n", "logger = logging.getLogger()\n", "logger.setLevel(logging.WARNING)\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "9d699b60", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7c70354f14b94b918c12919c51c476dc", "version_major": 2, "version_minor": 0 }, "text/plain": [ "API-24SEA get_data: 0%| | 0/1 [00:00\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
metrictimestampsnotfoundsitelocationdata_groupstatisticshort_handprint_str
0mean_WF_A01_pitch[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA01scadameanpitchPitch
1mean_WF_A01_power[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA01scadameanpowerPower
2mean_WF_A01_rpm[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA01scadameanrpmRotor speed
3mean_WF_A01_TP_INC_LAT015_DEG240_X_nr1[2020-03-22T14:20:00+00:00, 2020-03-22T14:30:0...WindFarmWFA01inclinationmeanTP_INC_LAT015_DEG240_X_nr1TP INC LAT015 DEG240 X nr1
4mean_WF_A01_TP_INC_LAT015_DEG240_Y_nr2[2020-03-22T14:20:00+00:00, 2020-03-22T14:30:0...WindFarmWFA01inclinationmeanTP_INC_LAT015_DEG240_Y_nr2TP INC LAT015 DEG240 Y nr2
5mean_WF_A01_winddirection[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA01scadameanwinddirectionWind direction
6mean_WF_A01_windspeed[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA01scadameanwindspeedWind speed
7mean_WF_A01_yaw[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA01scadameanyawYaw
8mean_WF_A02_pitch[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA02scadameanpitchPitch
9mean_WF_A02_power[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA02scadameanpowerPower
10mean_WF_A02_rpm[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA02scadameanrpmRotor speed
11mean_WF_A02_TP_INC_LAT015_DEG240_X_nr1[2020-03-12T04:00:00+00:00, 2020-03-12T04:10:0...WindFarmWFA02inclinationmeanTP_INC_LAT015_DEG240_X_nr1TP INC LAT015 DEG240 X nr1
12mean_WF_A02_TP_INC_LAT015_DEG240_Y_nr2[2020-03-12T04:00:00+00:00, 2020-03-12T04:10:0...WindFarmWFA02inclinationmeanTP_INC_LAT015_DEG240_Y_nr2TP INC LAT015 DEG240 Y nr2
13mean_WF_A02_winddirection[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA02scadameanwinddirectionWind direction
14mean_WF_A02_windspeed[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA02scadameanwindspeedWind speed
15mean_WF_A02_yaw[2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0...WindFarmWFA02scadameanyawYaw
\n", "" ], "text/plain": [ " metric \\\n", "0 mean_WF_A01_pitch \n", "1 mean_WF_A01_power \n", "2 mean_WF_A01_rpm \n", "3 mean_WF_A01_TP_INC_LAT015_DEG240_X_nr1 \n", "4 mean_WF_A01_TP_INC_LAT015_DEG240_Y_nr2 \n", "5 mean_WF_A01_winddirection \n", "6 mean_WF_A01_windspeed \n", "7 mean_WF_A01_yaw \n", "8 mean_WF_A02_pitch \n", "9 mean_WF_A02_power \n", "10 mean_WF_A02_rpm \n", "11 mean_WF_A02_TP_INC_LAT015_DEG240_X_nr1 \n", "12 mean_WF_A02_TP_INC_LAT015_DEG240_Y_nr2 \n", "13 mean_WF_A02_winddirection \n", "14 mean_WF_A02_windspeed \n", "15 mean_WF_A02_yaw \n", "\n", " timestampsnotfound site location \\\n", "0 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA01 \n", "1 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA01 \n", "2 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA01 \n", "3 [2020-03-22T14:20:00+00:00, 2020-03-22T14:30:0... WindFarm WFA01 \n", "4 [2020-03-22T14:20:00+00:00, 2020-03-22T14:30:0... WindFarm WFA01 \n", "5 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA01 \n", "6 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA01 \n", "7 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA01 \n", "8 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA02 \n", "9 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA02 \n", "10 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA02 \n", "11 [2020-03-12T04:00:00+00:00, 2020-03-12T04:10:0... WindFarm WFA02 \n", "12 [2020-03-12T04:00:00+00:00, 2020-03-12T04:10:0... WindFarm WFA02 \n", "13 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA02 \n", "14 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA02 \n", "15 [2020-03-04T10:00:00+00:00, 2020-03-05T09:10:0... WindFarm WFA02 \n", "\n", " data_group statistic short_hand \\\n", "0 scada mean pitch \n", "1 scada mean power \n", "2 scada mean rpm \n", "3 inclination mean TP_INC_LAT015_DEG240_X_nr1 \n", "4 inclination mean TP_INC_LAT015_DEG240_Y_nr2 \n", "5 scada mean winddirection \n", "6 scada mean windspeed \n", "7 scada mean yaw \n", "8 scada mean pitch \n", "9 scada mean power \n", "10 scada mean rpm \n", "11 inclination mean TP_INC_LAT015_DEG240_X_nr1 \n", "12 inclination mean TP_INC_LAT015_DEG240_Y_nr2 \n", "13 scada mean winddirection \n", "14 scada mean windspeed \n", "15 scada mean yaw \n", "\n", " print_str \n", "0 Pitch \n", "1 Power \n", "2 Rotor speed \n", "3 TP INC LAT015 DEG240 X nr1 \n", "4 TP INC LAT015 DEG240 Y nr2 \n", "5 Wind direction \n", "6 Wind speed \n", "7 Yaw \n", "8 Pitch \n", "9 Power \n", "10 Rotor speed \n", "11 TP INC LAT015 DEG240 X nr1 \n", "12 TP INC LAT015 DEG240 Y nr2 \n", "13 Wind direction \n", "14 Wind speed \n", "15 Yaw " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# **API Initialization**\n", "# API initialization can happen either explicitly via the API class, or\n", "# implicitly when using the pandas `datasignals` accessor.\n", "# In this example we will use the Pandas accessor.\n", "api = AsyncAPI()\n", "# The Metrics Overview is a table containing all the locations and metrics\n", "# available in the API, together with their metadata. It is useful to query it\n", "# before getting data, to check which locations and metrics are available for\n", "# the site you want to query.\n", "m_o = api.metrics_overview\n", "\n", "# site is the wind farm name you want to query. The parameter can also be\n", "# a list of site names, e.g. [\"windfarm\", \"windfarm2\"]. Matching is\n", "# case-insensitive and passing the \"site-id\" is also accepted, e.g. \"windfarm\"\n", "# will match \"WindFarm\", but also \"WF\", \"wf\", etc.\n", "site = \"windfarm\"\n", "# Matching locations from Metrics Overview for the specified site\n", "# Also partial names of locations are accepted, e.g. \"a01\" will match\n", "# all locations containing \"a01\" in their name, such as \"A01\", \"a01\". Matching\n", "# is case-insensitive.\n", "locations = m_o[m_o[\"site\"].str.lower() == site][\"location\"].unique().tolist()\n", "# Metrics: partial matches and regexes are accepted.\n", "# Spaces are interpreted as .* in the name.\n", "# If you want to query all metrics, pass \"all\" or [\"all\"].\n", "metrics = [\"mean windspeed\", \"mean power\", \"mean yaw\", \"mean rpm\",\n", " \"mean pitch\", \"mean winddirection\", \"mean inc\"]\n", "# Start and end timestamp in ISO 8601 format. The API accepts also other\n", "# formats, such as the one provided by\n", "# https://www.elastic.co/docs/reference/elasticsearch/rest-apis/common-options#date-math\n", "start_timestamp = \"2020-03-01T00:00:00Z\"\n", "end_timestamp = \"2020-06-01T00:00:00Z\"\n", "\n", "data = await api.get_null_timestamps(site, locations, metrics,\n", " start_timestamp, end_timestamp)\n", "data\n" ] } ], "metadata": { "jupytext": { "custom_cell_magics": "kql", "encoding": "# -*- coding: utf-8 -*-" }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.1" } }, "nbformat": 4, "nbformat_minor": 5 }