_images/wavespectra_logo.png

Input & Output

Input

Wavespectra provides several functions for reading datasets from different file formats into SpecDataset objects. The functions are defined in submodules within wavespectra.input. They can be imported from the main module level for convenience, for instance:

In [1]: from wavespectra import read_swan

Note

The following conventions are expected for defining reading functions:

  • Funcions for different file types are defined in different modules within wavespectra.input subpackage.

  • Modules are named as filetype.py, e.g., swan.py.

  • Functions are named as read_`filetype`, e.g., read_swan.

Input functions can also be defined without following these conventions. However they are not accessible from the main module level and need to be imported from their full module path, e.g.

In [2]: from wavespectra.input.swan import read_hotswan

Note

Wavespectra currently supports data formats that include NetCDF, ASCII and JSON type files. NetCDF type datasets, i.e. those that can be open with xarray’s open_dataset and open_mfdataset functions, can also be prescribed in ZARR format (wavespectra uses xarray’s open_zarr function behind the scenes to open these files). Functions that support ZARR have a file_format argument option.

Note

Files in ZARR format can be open from both local and remote (bucket) stores.

These input functions are currently available from the main module level:

read_ww3

Read Spectra from WAVEWATCHIII native netCDF format.

read_ncswan

Read Spectra from SWAN native netCDF format.

read_wwm

Read Spectra from WWMII native netCDF format.

read_netcdf

Read Spectra from generic netCDF format.

read_era5

Read Spectra from ECMWF ERA5 netCDF format.

read_swan

Read Spectra from SWAN ASCII file.

read_triaxys

Read spectra from TRIAXYS wave buoy ASCII files.

read_ndbc

Read spectra from NDBC wave buoy ASCII files.

read_spotter

Read Spectra from spotter JSON file.

read_octopus

Read spectra from Octopus file format.

read_dataset

Format and attach SpecArray accessor to an existing xarray dataset.

read_json

Read Spectra from json.

read_funwave

Read Spectra in Funwave format.

These functions are not accessible from the main module level and need to be imported from their full module path:

input.swan.read_swans

Read multiple SWAN ASCII files into single Dataset.

input.swan.read_hotswan

Read partial SWAN hotfiles into single gridded hotfile Dataset.

input.swan.read_swanow

Read SWAN nowcast from fileglob, keep overlapping dates from most recent files.

Output

Wavespectra provides functions to write SpecDataset objects into different file types. They are defined in module within wavespectra.output. They are attached as methods in the SpecDataset accessor.

Note

The following conventions are expected for defining output functions:

  • Funcions for different file types are defined in different modules within wavespectra.output subpackage.

  • Modules are named as filetype.py, e.g., swan.py.

  • Functions are named as to_`filetype`, e.g., to_swan.

  • Function must accept self as the first input argument.

These output functions are currently available as methods of SpecDataset:

SpecDataset.to_netcdf

Write spectra in netCDF format using wavespectra conventions.

SpecDataset.to_ww3

Save spectra in native WW3 netCDF format.

SpecDataset.to_swan

Write spectra in SWAN ASCII format.

SpecDataset.to_octopus

Save spectra in Octopus format.

SpecDataset.to_json

Write spectra in json format.

SpecDataset.to_funwave

Write spectra in Funwave format.

SpecDataset.to_orcaflex

Writes the spectrum to an Orcaflex model