The mvbc package is a Python client to interact with the Meetnet Vlaamse Banken API. This package provides easy access to public weather and metocean data from the Belgian North Sea directly, and it returns the data in a pandas DataFrame format, making it convenient for further analysis.
To use the Meetnet Vlaamse Banken API, you first need to create an account and get credentials:
- Go to the Meetnet Vlaamse Banken registration page.
- Once registered, you will obtain your
MEETNET_USERNAMEandMEETNET_PASSWORD.
For best security practices, store your credentials in environment variables. You can set them as follows in your terminal:
export MEETNET_USERNAME="your_username"
export MEETNET_PASSWORD="your_password"Alternatively, you can decide to skip this step and provide your credentials directly into the Notebook. However, this poses a security risk when sharing your notebooks.
You can install the mvbc package via pip:
pip install mvbcOnce you have the package installed, you can start using it to retrieve weather data. Below is an example on how to use the package to fetch data.
import os
from pytz import utc
from datetime import datetime
# Import vub Meetenet Vlaamse Banken API functions
from mvbc.config import Credentials
from mvbc.client import Base
from mvbc.objects import Catalog, Data
import mvbc.data_getter as dg
# If you are using environmental variables
mvbc_username = os.getenv('MEETNET_USERNAME') # Collects your username
mvbc_password = os.getenv('MEETNET_PASSWORD') # Collects your password
# Use the credentials
creds = Credentials(username=mvbc_username, password=mvbc_password)
# Check the connection (optional)
b=Base(creds)
b.ping() # This should confirm your ability to login
# Specify the timeframe of interest
dt_start = datetime(2022,9,30,tzinfo=utc) # timestamp with timezone
dt_end = datetime(2022,10,1,tzinfo=utc)
# Get the information about the avialable data points
c = Catalog(credentials=creds)
df_unfiltered = c.data_points()The df_unfiltered DataFrame contains the information about the available data and the weather stations.
There are two main ways to retrieve data:
- By Weather Station Name: You can directly specify the name of the weather station to get data. A map of weather stations is available here; https://meetnetvlaamsebanken.be/map
weather_station = 'Wandelaar'
df_weather = \
dg.get_data_by_weatherstation(
weather_station,
dt_start,
dt_end,
creds,
df_unfiltered
)- By Asset Location: You can provide the location (latitude, longitude) of your asset (e.g., an offshore wind turbine) at sea, and the package will fetch data from the closest weather station.
# Replace this with location of interest in the from of [Latitude, Longitude]
location_of_interest = [2.81, 51.69]
df_weather, weatherstation_information, all_wetaherstations = dg.get_longterm_weather_data(location_of_interest, dt_start, dt_end, df=df_unfiltered, credentials=creds)
# Data comes in for every 30min, but you can resample to the time you want (e.g. 10 minutes)
df_weather = df_weather.resample('10T', axis=0).interpolate(method='linear', axis=0, limit=12)The weather data is returned as a pandas DataFrame (df_weather) with the timestamps in the rows and columns in the format:
mvbc_<weather station>_<Parameter Name>
For example, you might see columns such as:
mvbc_Thorntonbank_Wind_speed
mvbc_Wandelaar_Temperature
mvbc_Westhinder_Wave_height
The additional information about available weather stations and data can be accessed via the df_unfiltered DataFrame. This provides you with metadata about the stations and available parameters.
You can also set a list of preferred weather stations to prioritize fetching data from. The default preferred stations are:
- Thorntonbank
- Wandelaar
- Westhinder
You can provide your own list of preferred stations as follows:
preferred_stations = ["Westhinder", "Nieuwpoort"]
df_preferred = client.get_weather_data(preferred_stations=preferred_stations)
print(df_preferred)For a full usage example, check out the provided Jupyter notebook (mvbc_tutorial.ipynb) which showcases different ways of fetching data, including using preferred weather stations and fetching data by location.