Welcome to metocean-api’s documentation!

metocean-api is a Python tool to extract time series of metocean data from global/regional/coastal hindcasts/reananalysis.

The package contains functions to extract time series to csv-format from:
  • NORA3 hindcast dataset

  • ERA5 reanalysis dataset

Installing metocean-api

Alternative 1: Using Mambaforge (alternative to Miniconda)

  1. Install mambaforge (download)

  2. Set up a Python 3 environment for metocean-api and install metocean-api

$ mamba create -n metocean-api python=3 metocean-api
$ conda activate metocean-api

Alternative 2: Using Mambaforge (alternative to Miniconda) and Git

  1. Install mambaforge (download)

  2. Clone metocean-api:

$ git clone https://github.com/MET-OM/metocean-api.git
$ cd metocean-api/
  1. Create environment with the required dependencies and install metocean-api

$ mamba env create -f environment.yml
$ conda activate metocean-api
$ pip install --no-deps -e .

This installs the metocean-api as an editable package. Therefore, you can directly make changes to the repository or fetch the newest changes with git pull.

To update the local conda environment in case of new dependencies added to environment.yml:

$ mamba env update -f environment.yml

Creating a TimeSeries-object

This section documents the ts-module. The ts-object is initialized with the following python command:

from metocean_api import ts
df_ts = ts.TimeSeries(lon=1.320, lat=53.324,
                   start_time='2000-01-01', end_time='2000-03-31' ,
                   product='NORA3_wind_wave')

Several options for product are available. Please check the data catalog for the time coverage:

Import data from server to ts-object and save it as csv:

df_ts.import_data(save_csv=True)

Data is saved in:

print(df_ts.datafile) #'NORA3_wind_wave_lon1.32_lat53.324_20000101_20000331.csv'

To import data from a local csv-file to ts-object:

df_ts.load_data(local_file=df_ts.datafile)
print(df_ts.data)
_images/ts.data0.png

To combine several csv-files produced by metocean-api:

df = ts.ts_mod.combine_data(list_files=['NORA3_wind_sub_lon1.32_lat53.324_20210101_20210131.csv',
                                        'NORA3_atm_sub_lon1.32_lat53.324_20210101_20210331.csv'],
                                output_file='combined_NORA3_lon1.32_lat53.324.csv')