Hi All,
If I’m not mistaken, read_checkpoint doesn’t provide a way to extract model time from checkpoint xdmf file. I can see a <Time Value>
line in xdmf file. I want to reload both data and corresponding time. Is there an easy way? Thanks!
Hi All,
If I’m not mistaken, read_checkpoint doesn’t provide a way to extract model time from checkpoint xdmf file. I can see a <Time Value>
line in xdmf file. I want to reload both data and corresponding time. Is there an easy way? Thanks!
Not that I am aware of. For similar needs, I typically export alongside the xdmf file a list containing all times.
Thanks! I can see that class XDMFFile does not have that method, which is not good.
Hi, I was struggling with the same problem, and asked ChatGPT to write me a function that extracts the time stamps from the xdmf file directly. Here is the resulting code:
import xml.etree.ElementTree as ET
def read_xdmf_time_values(xdmf_filename):
"""
Reads time values from an XDMF file and returns a dictionary
mapping grid names (e.g., "Vm_0", "Vm_1") to their corresponding time values.
"""
time_values = {}
# Parse the XML tree
tree = ET.parse(xdmf_filename)
root = tree.getroot()
# Find all grids inside the temporal collection
for grid in root.findall(".//Grid[@GridType='Uniform']"):
name = grid.get("Name")
time_element = grid.find("Time")
if name and time_element is not None:
time_values[name] = float(time_element.get("Value"))
return time_values
I tested it for my use case, and it worked.