Skip to main content

API 24SEA

api_24sea is a Python project designed to provide aid for the interaction with data from the 24SEA API.

Installation

The package supports Python 3.8 and above. To install it, run the following command in your terminal:

pip install api_24sea

DataSignals Usage

The following example shows the classical usage of the datasignals module.

  • The first step is to import the package and the necessary libraries.
  • Then, the environment variables are loaded from a .env file. This step is optional, since if any of the following names for user and password in the system, the package will authenticate automatically.
    • "API_24SEA_USERNAME", "24SEA_API_USERNAME", "TWOFOURSEA_API_USERNAME", "API_TWOFOURSEA_USERNAME" for the username.
    • "API_24SEA_PASSWORD", "24SEA_API_PASSWORD", "TWOFOURSEA_API_PASSWORD", "API_TWOFOURSEA_PASSWORD" for the password.
  • After that, API dataframe is initialized.
  • Finally, the user can get data from the API. The dataframe will authenticate lazily if the environment variables are loaded, or the user can authenticate manually before performing the data retrieval.

Importing the package

# %%
# **Package Imports**
# - From the Python Standard Library
import logging
import os
import sys

# - From third party libraries
import pandas as pd
import dotenv  # <-- Not necessary to api_24sea per se, but useful for
               #     loading environment variables. Install it with
               #     `pip install python-dotenv`

# - Local imports
from api_24sea.version import __version__, parse_version
import api_24sea
# %%
# **Package Versions**
print("Working Folder: ", os.getcwd())
print(f"Python Version: {sys.version}")
print(f"Pandas Version: {pd.__version__}")
print(f"Package {parse_version(__version__)}")
# **Notebook Configuration**
logging.basicConfig(level=logging.INFO)

Setting up the environment variables (optional)

This step assumes that you have a file structure similar to the following one:

.
├── env
│   └── .env
├── notebooks
│   └── example.ipynb
└── requirements.txt

The [.env]{.title-ref} file should look like this:

API_24SEA_USERNAME=your_username
API_24SEA_PASSWORD=your_password

With this in mind, the following code snippet shows how to load the environment variables from the [.env]{.title-ref} file:

# %%
# **Load Environment Variables from .env File**
_ = dotenv.load_dotenv("../env/.env")
if _:
    print("Environment Variables Loaded Successfully")
    print(os.getenv("API_24SEA_USERNAME"))
    # print(os.getenv("API_24SEA_PASSWORD"))
else:
    raise Exception("Environment Variables Not Loaded")

Initializing an empty dataframe

Initializing an empty dataframe is necessary to use the API, as here is where the data will be stored.

# %%
# **DataFrame initialization**
# The empty DataFrame is created beforehand because it needs to authenticate
# with the API to fetch the data.
df = pd.DataFrame()

Authentication (optional)

If any of the following names for user and password in the system, the package will authenticate automatically.

  • "API_24SEA_USERNAME", "24SEA_API_USERNAME", "TWOFOURSEA_API_USERNAME", "API_TWOFOURSEA_USERNAME" for the username.
  • "API_24SEA_PASSWORD", "24SEA_API_PASSWORD", "TWOFOURSEA_API_PASSWORD", "API_TWOFOURSEA_PASSWORD" for the password.

The user can also authenticate manually by calling the authenticate method from the DataFrame.

# %%
# **Authentication**
df.datasignals.authenticate("some_other_username", "some_other_password")

Alternatively, the user can authenticate with the API on DataFrame instantiation:

# %%
# **DataFrame initialization with authentication**
df = pd.DataFrame().datasignals.authenticate("some_other_username",
                                             "some_other_password")

Checking the available metrics

# %%
# **Metrics Overview**
# The metrics overview is a summary of the metrics available in the API and
# can be accessed from a hidden method in the DataSignals class.
df.datasignals._DataSignals__api.metrics_overview
# It will show all the available metrics with the corresponding units
# and the time window for which the user is allowed to get data

Getting sample data from the API

After loading the environment variables and authenticating with the API, the user can get data from 24SEA API endpoints.

The data is retrieved and stored in the DataFrame. All the metrics are stored in separate columns, and the timestamps are set as the index of the DataFrame.

The data retrieval is done by specifying the sites or the locations or both, the metrics, and timestamps.

  • Sites: Case insensitive, it can either match [site]{.title-ref} or [site_id]{.title-ref}. It is an optional parameter.
  • Locations: Case insensitive, it can either match [location]{.title-ref} or [location_id]{.title-ref}. It is an optional parameter. Prefer the locations parameter. The legacy singular location parameter is still accepted for backward compatibility, but it is deprecated.
  • Metrics: Case insensitive, it can be a partial match of the metric name. If the site and location are specified, and metrics equals all, all the "allowed" metrics for the specified site and location will be retrieved.
  • Timestamps: Timezone-aware datetime, strings in ISO 8601 format, or shorthand strings compatible with the shorthand_datetime package.
  • method: Optional HTTP method for the backend request. Default is GET. Supported values are GET, POST, PUT, PATCH, and DELETE.
# %%
# **Data Retrieval**
sites = ["wf"]

locations = ["a01", "a02"]

metrics = ["mean WinDSpEed", "mean pitch", "mean-Yaw", "mean Power"]
# Assigning metrics="all" will retrieve all the metrics available for the
# specified sites and locations.

start_timestamp = "2020-03-01T00:00:00Z"
end_timestamp = "2020-06-01T00:00:00Z"

df.datasignals.get_data(sites, locations, metrics,
                        start_timestamp, end_timestamp)

Checking the metrics selected and the data

# %%
df.datasignals.selected_metrics
df

Split the data by site and location

The as_dict method is used to split the data by site and location and return a dictionary of dictionaries of DataFrames.

# %%
# Data is a dictionary of dictionary of DataFrames in the shape of:
# {
#   "site1": {
#     "location1": DataFrame,
#     "location2": DataFrame,
#     ...
#   },
#   ...
# }
data = df.datasignals.as_dict()
# %%
# Retrieve the DataFrame for the windfarm WFA01 only
data["windfarm"]["WFA02"]

If df was defined using local data, rather than from API call, the user can still use the as_dict method to split the data by site and location by passing a metrics_map dataframe (i.e., the metrics overview table) from the datasignals app. For example:

import pandas as pd
import api_24sea
df = pd.DataFrame({
    "timestamp": ["2021-01-01", "2021-01-02"],
    "mean_WF_A01_windspeed": [10.0, 11.0],
    "mean_WF_A02_windspeed": [12.0, 13.0]
})
metrics_map = pd.DataFrame({
    "site": ["wf", "wf"],
    "location": ["a01", "a02"],
    "metric": ["mean_WF_A01_windspeed", "mean_WF_A02_windspeed"]
})
df.datasignals.as_dict(metrics_map)
# output
# {
#     "wf": {
#         "a01": pd.DataFrame({
#             "timestamp": ["2021-01-01", "2021-01-02"],
#             "mean_WF_A01_windspeed": [10.0, 11.0]
#         }),
#         "a02": pd.DataFrame({
#             "timestamp": ["2021-01-01", "2021-01-02"],
#             "mean_WF_A02_windspeed": [12.0, 13.0]
#         })
#     }
# }

Project Structure

.
├── .azure/
├── api_24sea/
│   ├── __init__.py
│   ├── datasignals/
│   │   ├── __init__.py
│   │   ├── fatigue.py
│   │   └── schemas.py
│   ├── core.py
│   ├── exceptions.py
│   ├── singleton.py
│   ├── utils.py
│   └── version.py
├── tests/
├── docs/
├── notebooks/
├── pyproject.toml
├── LICENSE
├── VERSION
└── README.md

License

The package is licensed under the GNU General Public License v3.0.

Metadata

Release files for api-24sea 2.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for api-24sea 2.6.0
File Size Uploaded
api_24sea-2.6.0.tar.gz 73.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for api-24sea 2.6.0
File Interpreter ABI Platform
api_24sea-2.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 149.0 kB

Release files / api_24sea-2.6.0.tar.gz

Download URL api_24sea-2.6.0.tar.gz
Size 73.5 kB
Tags Source
SHA-256 checksum
How to use checksums
55506c992bf83b207cccd99fab6b746b5d1adbafeec9d6efbef083b47e5df330
BLAKE2b-256 checksum
How to use checksums
9c85e14b8420723b32ccefcf7bba19d97241ae2f5c7708114eed10fdd24c287d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / api_24sea-2.6.0-py3-none-any.whl

Download URL api_24sea-2.6.0-py3-none-any.whl
Size 75.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25fcfaa10419c30bf25284e6f0aa3f5fb14d73708696b2663c2270af9af92e4c
BLAKE2b-256 checksum
How to use checksums
2286048c185291a3d58f736b8d4928c186d9da3afccfaeddcba483cb9dda175c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

2.6.1

2 release files

This release

2.6.0 This release

2 release files

2.5.0

2 release files

2.4.1

2 release files

2.3.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.6

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.7.0

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.21

2 release files

1.5.20

2 release files

1.5.13

2 release files

1.5.12

2 release files

1.5.11

2 release files

1.5.10

2 release files

1.5.9

2 release files

1.5.8

2 release files

1.5.7

2 release files

1.5.6

2 release files

1.5.5

2 release files

1.5.4

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.19

2 release files

1.4.18

2 release files

1.4.17

1 release file

1.4.16

2 release files

1.4.15

2 release files

1.4.14

2 release files

1.4.13

2 release files

1.4.9

2 release files

1.4.8

2 release files

1.4.7

2 release files

1.4.6

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.10.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page