Skip to content

Commit 2e65cb9

Browse files
authored
[BUG] Better logic for detection of particle handle for checkpoint files (#5019)
1 parent 1e7b2c5 commit 2e65cb9

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

yt/frontends/flash/data_structures.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
import weakref
4+
from pathlib import Path
45

56
import numpy as np
67

@@ -189,27 +190,38 @@ def __init__(
189190

190191
self.particle_filename = particle_filename
191192

193+
filepath = Path(filename)
194+
192195
if self.particle_filename is None:
193196
# try to guess the particle filename
194-
try:
195-
self._particle_handle = HDF5FileHandler(
196-
filename.replace("plt_cnt", "part")
197-
)
198-
self.particle_filename = filename.replace("plt_cnt", "part")
199-
mylog.info(
200-
"Particle file found: %s", self.particle_filename.split("/")[-1]
201-
)
202-
except OSError:
197+
if "hdf5_plt_cnt" in filepath.name:
198+
# We have a plotfile, look for the particle file
199+
try:
200+
pfn = str(
201+
filepath.parent.resolve()
202+
/ filepath.name.replace("plt_cnt", "part")
203+
)
204+
self._particle_handle = HDF5FileHandler(pfn)
205+
self.particle_filename = pfn
206+
mylog.info(
207+
"Particle file found: %s",
208+
os.path.basename(self.particle_filename),
209+
)
210+
except OSError:
211+
self._particle_handle = self._handle
212+
elif "hdf5_chk" in filepath.name:
213+
# This is a checkpoint file, should have the particles in it
203214
self._particle_handle = self._handle
204215
else:
205216
# particle_filename is specified by user
206217
self._particle_handle = HDF5FileHandler(self.particle_filename)
207218

208219
# Check if the particle file has the same time
209220
if self._particle_handle != self._handle:
210-
part_time = self._particle_handle.handle.get("real scalars")[0][1]
211-
plot_time = self._handle.handle.get("real scalars")[0][1]
212-
if not np.isclose(part_time, plot_time):
221+
plot_time = self._handle.handle.get("real scalars")
222+
if (part_time := self._particle_handle.handle.get("real scalars")) is None:
223+
raise RuntimeError("FLASH 2.x particle files are not supported!")
224+
if not np.isclose(part_time[0][1], plot_time[0][1]):
213225
self._particle_handle = self._handle
214226
mylog.warning(
215227
"%s and %s are not at the same time. "

0 commit comments

Comments
 (0)