Skip to content

Commit

Permalink
[BUG] Better logic for detection of particle handle for checkpoint fi…
Browse files Browse the repository at this point in the history
…les (#5019)
  • Loading branch information
jzuhone authored Oct 6, 2024
1 parent 1e7b2c5 commit 2e65cb9
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions yt/frontends/flash/data_structures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
import weakref
from pathlib import Path

import numpy as np

Expand Down Expand Up @@ -189,27 +190,38 @@ 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
self._particle_handle = HDF5FileHandler(self.particle_filename)

# 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. "
Expand Down

0 comments on commit 2e65cb9

Please sign in to comment.