From ff366aae822a251b85f73b525d7fb5e1ac881285 Mon Sep 17 00:00:00 2001 From: cekees <613654+cekees@users.noreply.github.com> Date: Fri, 23 Oct 2026 21:48:02 +0200 Subject: [PATCH] xdmf: read_grid_fragment and collection_names, the two XDMF reads a Proteus archive reader needs Proteus <= 1.9.x stored one fragment per rank and step inside its HDF5 files and wrote the order of its collections only into the .xmf beside them. A current Proteus reads both when it hot starts from or converts such an archive. With these two functions it does so without importing an XML parser itself: XDMF is this module's business. Co-Authored-By: Claude Fable 5.1 --- src/ymf/xdmf.py | 50 ++++++++++++++++++++- tests/test_xdmf_fragments.py | 87 ++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 tests/test_xdmf_fragments.py diff --git a/src/ymf/xdmf.py b/src/ymf/xdmf.py index c1ddb84..d439973 100644 --- a/src/ymf/xdmf.py +++ b/src/ymf/xdmf.py @@ -66,7 +66,8 @@ import json from pathlib import Path from typing import Any, Dict, List, Optional, Tuple -from xml.etree.ElementTree import Element, ElementTree, ParseError, SubElement, parse as et_parse +from xml.etree.ElementTree import (Element, ElementTree, ParseError, SubElement, fromstring, + parse as et_parse) from ymf.archive import YmfArchiveError, canonicalize_domain @@ -392,6 +393,53 @@ def grid_element_time(grid_elem: Element, where: str = "Grid") -> Optional[float return float(_attr(time_elem, ("Value",), where + ".Time")) +def read_grid_fragment(text: str | bytes) -> Tuple[Dict[str, Any], Optional[float]]: + """Parse one serialized ```` element: ``(grid, time)``. + + For the per-step metadata that Proteus <= 1.9.x stored inside its HDF5 + files, one XDMF ```` fragment per rank and step, and that a + current Proteus still reads when it hot starts from or converts such an + archive. The time is the fragment's own ``