|
1 | 1 | import os
|
2 | 2 | import sys
|
3 | 3 | import weakref
|
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 | import numpy as np
|
6 | 7 |
|
@@ -189,27 +190,38 @@ def __init__(
|
189 | 190 |
|
190 | 191 | self.particle_filename = particle_filename
|
191 | 192 |
|
| 193 | + filepath = Path(filename) |
| 194 | + |
192 | 195 | if self.particle_filename is None:
|
193 | 196 | # 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 |
203 | 214 | self._particle_handle = self._handle
|
204 | 215 | else:
|
205 | 216 | # particle_filename is specified by user
|
206 | 217 | self._particle_handle = HDF5FileHandler(self.particle_filename)
|
207 | 218 |
|
208 | 219 | # Check if the particle file has the same time
|
209 | 220 | 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]): |
213 | 225 | self._particle_handle = self._handle
|
214 | 226 | mylog.warning(
|
215 | 227 | "%s and %s are not at the same time. "
|
|
0 commit comments