From 563d75080b9721952fe0d7abb326b9a6a46334b3 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Fri, 4 Oct 2024 15:48:52 -0400 Subject: [PATCH 1/4] Better detection of particle handle for checkpoint files --- yt/frontends/flash/data_structures.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/yt/frontends/flash/data_structures.py b/yt/frontends/flash/data_structures.py index 6456e22984..5d660404bd 100644 --- a/yt/frontends/flash/data_structures.py +++ b/yt/frontends/flash/data_structures.py @@ -191,15 +191,19 @@ def __init__( 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 filename: + # We have a plotfile, look for the particle file + try: + pfn = filename.replace("plt_cnt", "part") + self._particle_handle = HDF5FileHandler(pfn) + self.particle_filename = pfn + mylog.info( + "Particle file found: %s", self.particle_filename.split("/")[-1] + ) + except OSError: + self._particle_handle = self._handle + elif "hdf5_chk" in filename: + # This is a checkpoint file, should have the particles in it self._particle_handle = self._handle else: # particle_filename is specified by user From c5f562988605024e1a4d436e718442540c41b156 Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Fri, 4 Oct 2024 16:05:04 -0400 Subject: [PATCH 2/4] Explicit check for FLASH 2.5 particle file --- yt/frontends/flash/data_structures.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/yt/frontends/flash/data_structures.py b/yt/frontends/flash/data_structures.py index 5d660404bd..4c97e896c8 100644 --- a/yt/frontends/flash/data_structures.py +++ b/yt/frontends/flash/data_structures.py @@ -211,9 +211,11 @@ 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): + part_time = self._particle_handle.handle.get("real scalars", None) + plot_time = self._handle.handle.get("real scalars", None) + if part_time 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. " From da1a33bee228d39c14018af1dd5e0e212af0f9ea Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Sat, 5 Oct 2024 11:14:56 -0400 Subject: [PATCH 3/4] Better handling for this that avoids situations where the substring is in the rest of the path --- yt/frontends/flash/data_structures.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/yt/frontends/flash/data_structures.py b/yt/frontends/flash/data_structures.py index 4c97e896c8..854245aed7 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,20 +190,26 @@ def __init__( self.particle_filename = particle_filename + filepath = Path(filename) + if self.particle_filename is None: # try to guess the particle filename - if "hdf5_plt_cnt" in filename: + if "hdf5_plt_cnt" in filepath.name: # We have a plotfile, look for the particle file try: - pfn = filename.replace("plt_cnt", "part") + 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", self.particle_filename.split("/")[-1] + "Particle file found: %s", + os.path.basename(self.particle_filename), ) except OSError: self._particle_handle = self._handle - elif "hdf5_chk" in filename: + elif "hdf5_chk" in filepath.name: # This is a checkpoint file, should have the particles in it self._particle_handle = self._handle else: From 0e6259b9024e118bd10552a6bcce06cb038e783a Mon Sep 17 00:00:00 2001 From: John ZuHone Date: Sat, 5 Oct 2024 11:15:48 -0400 Subject: [PATCH 4/4] Update yt/frontends/flash/data_structures.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Robert --- yt/frontends/flash/data_structures.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/yt/frontends/flash/data_structures.py b/yt/frontends/flash/data_structures.py index 854245aed7..7428eb4e3f 100644 --- a/yt/frontends/flash/data_structures.py +++ b/yt/frontends/flash/data_structures.py @@ -218,9 +218,8 @@ 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", None) - plot_time = self._handle.handle.get("real scalars", None) - if part_time is None: + 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