Skip to content

feat(med): preserve mesh name, description and units across read/write round-trip#12

Open
fznoussi wants to merge 2 commits into
mainfrom
feat/preserve-mesh-metadata
Open

feat(med): preserve mesh name, description and units across read/write round-trip#12
fznoussi wants to merge 2 commits into
mainfrom
feat/preserve-mesh-metadata

Conversation

@fznoussi
Copy link
Copy Markdown
Collaborator

@fznoussi fznoussi commented May 29, 2026

Previously, the mesh name was always hardcoded to 'mesh' on write, and the description/units attributes (DES, UNT, UNI) were always reset to their default values. This meant that any MED file that went through a read→write cycle would lose its original metadata.

Changes:

  • read(): extract DES, UNT, UNI attributes from the HDF5 mesh group and store them on the Mesh object as .description, .unit_time, .unit_coords
  • read(): store the original mesh name as .mesh_name on the Mesh object
  • write(): use getattr(mesh, 'mesh_name', 'mesh') so the original name is reused if present, falling back to 'mesh' for meshes not coming from a MED file
  • write(): use getattr() for description/unit_time/unit_coords with safe fallbacks so non-MED meshes still write valid files

Why: any tool (e.g. Salome, Code_Aster) that relies on the mesh name or units being preserved will now get correct output after a round-trip.

…e round-trip

Previously, the mesh name was always hardcoded to 'mesh' on write, and
the description/units attributes (DES, UNT, UNI) were always reset to
their default values. This meant that any MED file that went through a
read→write cycle would lose its original metadata.

Changes:
- read(): extract DES, UNT, UNI attributes from the HDF5 mesh group and
  store them on the Mesh object as .description, .unit_time, .unit_coords
- read(): store the original mesh name as .mesh_name on the Mesh object
- write(): use getattr(mesh, 'mesh_name', 'mesh') so the original name
  is reused if present, falling back to 'mesh' for meshes not coming
  from a MED file
- write(): use getattr() for description/unit_time/unit_coords with safe
  fallbacks so non-MED meshes still write valid files

Why: any tool (e.g. Salome, Code_Aster) that relies on the mesh name or
units being preserved will now get correct output after a round-trip.
@fznoussi fznoussi changed the title feat(med): preserve mesh name, description and units across read/writ… feat(med): preserve mesh name, description and units across read/write round-trip May 29, 2026
Add tests for the DES/UNT/UNI attributes and the mesh name introduced
by feat/preserve-mesh-metadata.

- defaults: a bare mesh round-trips to the documented fallbacks
  (mesh_name=mesh, default description, empty units), which exercises
  the getattr() default branches of write() that were previously
  untested.
- custom values: parametrized read->write->read loop for description,
  unit_time and unit_coords, asserting the value is both reconstructed
  on read and written back (not overwritten by a default).
- mesh name: a custom name survives a full round-trip and the default
  mesh does not reappear; uses write() to build a consistent file
  instead of renaming HDF5 groups.
- whitespace: read() trims padded string fields (justifies the .strip()
  cleanup, relevant for files written by Salome).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant