Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Better logic for detection of particle handle for checkpoint files #5019

Merged
merged 4 commits into from
Oct 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading