Welcome to metocean-api’s documentation!

metocean-api is a Python tool designed to extract time series of metocean (meteorological and oceanographic) data from various sources, including global, regional, and coastal hindcasts and reanalysis. The extracted data can be saved in CSV format or NetCDF for further analysis and usage. Please look at the section below for more information about the available datasets and variables.

Installing metocean-api

Quick installation

$ pip install metocean-api

or

$ conda install -c conda-forge 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 change 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')

Available Datasets in metocean-api

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

warning:

Parallel downloading is not allowed for NORA3 data. It’s a breach of the terms of service for thredds.met.no and may result in the blocking of your computer.

information:

If you are using the default variables, using use_cache=True is recommended to reduce the load on the server and allow you to restart the download in case of failure.

Import data

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

df_ts.import_data(save_csv=True, save_nc=False)

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

Combine csv-files

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')

Command Line Interface (CLI) - metocean-cli

Download Command

The download command is used to download metocean data for a specified product, location, and time range.

By default, we are using the existing cached data, if you want to ignore the cached data (product change, redownload…) please use --no_cache

Usage:

metocean-cli download <product> <lat> <lon> <start_time> <stop_time> <file_format> [--no_cache] [--max_retry MAX_RETRY] [-o OUTPUT]

Arguments:

  • <product>: Name of the product to download.

  • <lat>: Latitude of the location.

  • <lon>: Longitude of the location.

  • <start_time>: Start time for data in ISO 8601 format (e.g., "2023-01-01").

  • <stop_time>: Stop time for data in ISO 8601 format (e.g., "2023-01-02").

  • <file_format>: Format of the output file: "csv", "netcdf", or "both".

  • --no_cache: Optional flag to removed the cached data at the end of the processing.

  • --max_retry MAX_RETRY: Optional argument to specify the maximum number of retry attempts for the download. Default is 5.

  • -o OUTPUT, --output OUTPUT: Path to the output file where the downloaded data will be saved.

Example:

metocean-cli download NORA3_offshore_wind 54.01 6.58 "2023-01-01" "2023-01-02" csv

Combine Command

The combine command is used to combine multiple metocean data files into a single output file.

Usage:

metocean-cli combine <files>... -o OUTPUT

Arguments:

  • <files>...: List of file paths to combine. You can specify multiple files separated by spaces.

  • -o OUTPUT, --output OUTPUT: Path to the output file where the combined data will be saved.

Example:

metocean-cli combine 'NORA3_wind_sub_lon1.32_lat53.324_20210101_20210131.csv' 'NORA3_atm_sub_lon1.32_lat53.324_20210101_20210331.csv' -o combined.csv