Last updated on Jun 04, 2026.

Source code for netsse.dataset

# -*- coding: utf-8 -*-
"""Functions for handling **example datasets** that are used in the example scripts included in the NetSSE documentation for illustration purposes.

.. dropdown:: Copyright (C) 2023-2026 Technical University of Denmark, R.E.G. Mounet
    :color: primary
    :icon: law

    *This code is part of the NetSSE software.*

    NetSSE is free software: you can redistribute it and/or modify it under
    the terms of the GNU General Public License as published by the Free
    Software Foundation, either version 3 of the License, or (at your
    option) any later version.

    NetSSE is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License along
    with this program.  If not, see https://www.gnu.org/licenses/.

    To credit the author, users are encouraged to use below reference:

    .. code-block:: text

        Mounet, R. E. G., & Nielsen, U. D. NetSSE: An open-source Python package
        for network-based sea state estimation from ships, buoys, and other
        observation platforms (version 2.3). Technical University of Denmark,
        GitLab. July 2026. https://doi.org/10.11583/DTU.26379811.

*Last updated on 04-06-2026 by R.E.G. Mounet*

"""

from importlib import resources

import numpy as np
import pandas as pd


[docs] def load_example_data(name: str, **kwargs): """Load an example dataset from the NetSSE package's data directory. Parameters ---------- name : str Name of the dataset file, including the extension (e.g., ``"example_WP_meas.csv"``). **kwargs Additional keyword arguments to pass to the data loading function (e.g., ``index_col=0`` for ``pd.read_csv``). Returns ------- pd.DataFrame or np.ndarray The loaded dataset as a pandas DataFrame (for CSV files) or a NumPy array (for TXT files). Raises ------- ValueError If the file format is unsupported (not CSV or TXT). Examples -------- Load a CSV dataset as a pandas DataFrame: >>> df = load_example_data("example_WP_meas.csv", index_col=0) Load a TXT dataset as a NumPy array: >>> arr = load_example_data("example_spectrum.txt", delimiter="\\t") """ with resources.files("netsse.data").joinpath(name).open("r") as f: if f.name.endswith(".csv"): return pd.read_csv(f, **kwargs) elif f.name.endswith(".txt"): return np.loadtxt(f, **kwargs) else: raise ValueError(f"Unsupported file format for {name}")