Skip to main content

Read and write Serafin (TELEMAC) binary files

Project description

Serafin for Python

Read and write Serafin binary files — the mesh / results format used by the TELEMAC-MASCARET hydraulic modelling system (also known as the Selafin format, file extension .slf).

Documentation: https://isl-ingenierie.gitlab.io/modules-python/python-serafin/

serafin provides a typed, dependency-light I/O layer for Serafin files:

  • single and double precision floats;
  • big- and little-endian byte ordering;
  • 2D and 3D meshes, with 2D ⇄ 3D conversion;
  • mesh geometry, boundary detection and transformations;
  • a catalogue of 2D / 3D variables and derived-variable computation.

The read/write code is adapted from PyTelTools; credits to its authors for documenting the format.

Installation

pip install python-serafin

The distribution is named python-serafin on PyPI; the import name is serafin (a common pattern, like python-dateutilimport dateutil).

Quickstart

Read a Serafin file

from serafin import Read

with Read("results.slf", "en") as f:
    f.read_header()
    f.get_time()

    print(f.header.nb_nodes, "nodes,", f.header.nb_frames, "frames")
    print("variables:", f.header.var_IDs)

    # values of variable "U" at the first time frame -> numpy array (nb_nodes,)
    u = f.read_var_in_frame(0, "U")
    print(u.shape, u.min(), u.max())

Write a Serafin file

from serafin import Read, Write

with Read("results.slf", "en") as src:
    src.read_header()
    src.get_time()
    header = src.header

    with Write("copy.slf", "en", overwrite=True) as dst:
        dst.write_header(header)
        for time_index, time in enumerate(src.time):
            values = src.read_vars_in_frame(time_index)
            dst.write_entire_frame(header, time, values)

Requirements

  • Python 3.10 or newer
  • numpy ≥ 1.24

Development

git clone https://gitlab.com/isl-ingenierie/modules-python/python-serafin.git
cd python-serafin
python -m venv .venv
. .venv/Scripts/activate     # PowerShell: . .venv/Scripts/Activate.ps1
pip install -e ".[dev]"
pre-commit install
pytest

Releasing

See CHANGELOG.md for the version history (format: Keep a Changelog 1.1.0, versions follow Semantic Versioning 2.0.0).

The release flow:

  1. Move entries from ## [Unreleased] to a new ## [VERSION] - YYYY-MM-DD section in CHANGELOG.md.
  2. Commit and tag (git tag vVERSION && git push origin vVERSION).
  3. GitLab CI uploads to PyPI / TestPyPI via Trusted Publisher (OIDC, no API token stored as a CI variable) and creates a GitLab Release whose body is the matching CHANGELOG section.

The leading v is optional; hatch-vcs strips it when computing the package version.

Tag pattern Target
0.1.0a1, v0.1.0rc2, 0.1.0.dev3 TestPyPI (pypi-test job)
0.1.0, v1.2.3 PyPI prod (pypi job)

License

This project is released under the GNU General Public License v3.0 or later.

The Serafin I/O code is adapted from PyTelTools, which is itself distributed under the GPL v3 — this package therefore inherits the same license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_serafin-0.1.0.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_serafin-0.1.0-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

Details for the file python_serafin-0.1.0.tar.gz.

File metadata

  • Download URL: python_serafin-0.1.0.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for python_serafin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 621a85a99a5352d9335369be8903486b4fb2565559d30707446cb35d5b1b67c8
MD5 a4c14e02df48b99020c693bf534f5ea4
BLAKE2b-256 664450a3bd2fe0b72e925acb0cf02a243a568101d3ca734d1e90154eeb571f13

See more details on using hashes here.

File details

Details for the file python_serafin-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: python_serafin-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 35.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for python_serafin-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2afd42ac11bded0182c0e90be7c72c3cf27ed48a45cb712f3b130df78e7edbc3
MD5 7f31d94dac440068d90f02e44d018dd0
BLAKE2b-256 80928b68e13e85cecd743fb0c96d1c10bd3b5cf255822767fc3b8a74aa03a3d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page