diff --git a/yt/frontends/flash/data_structures.py b/yt/frontends/flash/data_structures.py index 6456e229840..7428eb4e3f1 100644 --- a/yt/frontends/flash/data_structures.py +++ b/yt/frontends/flash/data_structures.py @@ -1,6 +1,7 @@ import os import sys import weakref +from pathlib import Path import numpy as np @@ -189,17 +190,27 @@ def __init__( self.particle_filename = particle_filename + filepath = Path(filename) + if self.particle_filename is None: # try to guess the particle filename - try: - self._particle_handle = HDF5FileHandler( - filename.replace("plt_cnt", "part") - ) - self.particle_filename = filename.replace("plt_cnt", "part") - mylog.info( - "Particle file found: %s", self.particle_filename.split("/")[-1] - ) - except OSError: + if "hdf5_plt_cnt" in filepath.name: + # We have a plotfile, look for the particle file + try: + pfn = str( + filepath.parent.resolve() + / filepath.name.replace("plt_cnt", "part") + ) + self._particle_handle = HDF5FileHandler(pfn) + self.particle_filename = pfn + mylog.info( + "Particle file found: %s", + os.path.basename(self.particle_filename), + ) + except OSError: + self._particle_handle = self._handle + elif "hdf5_chk" in filepath.name: + # This is a checkpoint file, should have the particles in it self._particle_handle = self._handle else: # particle_filename is specified by user @@ -207,9 +218,10 @@ def __init__( # Check if the particle file has the same time if self._particle_handle != self._handle: - part_time = self._particle_handle.handle.get("real scalars")[0][1] - plot_time = self._handle.handle.get("real scalars")[0][1] - if not np.isclose(part_time, plot_time): + plot_time = self._handle.handle.get("real scalars") + if (part_time := self._particle_handle.handle.get("real scalars")) is None: + raise RuntimeError("FLASH 2.x particle files are not supported!") + if not np.isclose(part_time[0][1], plot_time[0][1]): self._particle_handle = self._handle mylog.warning( "%s and %s are not at the same time. "