diff --git a/pyphare/pyphare/pharesee/run/run.py b/pyphare/pyphare/pharesee/run/run.py index ea2883d80..003943497 100644 --- a/pyphare/pyphare/pharesee/run/run.py +++ b/pyphare/pyphare/pharesee/run/run.py @@ -1,4 +1,5 @@ import os +import glob import numpy as np from pyphare.pharesee.hierarchy import hierarchy_from @@ -9,7 +10,6 @@ from pyphare.core.phare_utilities import listify from pyphare.logger import getLogger -from .utils import _current1d from .utils import ( _compute_to_primal, _compute_pop_pressure, @@ -36,8 +36,6 @@ class Run: def __init__(self, path, default_time=None): self.path = path self.default_time_ = default_time - import glob - self.available_diags = glob.glob(os.path.join(self.path, "*.h5")) def _get_hierarchy(self, times, filename, hier=None, **kwargs): @@ -92,7 +90,7 @@ def GetTags(self, time, merged=False, **kwargs): return self._get(hier, time, merged, "nearest") def GetB(self, time, merged=False, interp="nearest", all_primal=True, **kwargs): - if merged == True: + if merged: all_primal = False hier = self._get_hierarchy(time, "EM_B.h5", **kwargs) if not all_primal: @@ -102,7 +100,7 @@ def GetB(self, time, merged=False, interp="nearest", all_primal=True, **kwargs): return VectorField(h) def GetE(self, time, merged=False, interp="nearest", all_primal=True, **kwargs): - if merged == True: + if merged: all_primal = False hier = self._get_hierarchy(time, "EM_E.h5", **kwargs) if not all_primal: @@ -164,7 +162,7 @@ def GetPe(self, time, merged=False, interp="nearest", all_primal=True): return ScalarField(h) * Te def GetJ(self, time, merged=False, interp="nearest", all_primal=True, **kwargs): - if merged == True: + if merged: all_primal = False B = self.GetB(time, all_primal=False, **kwargs) J = compute_hier_from(_compute_current, B) @@ -239,16 +237,9 @@ def GetDl(self, level="finest", time=None): :param level: the level at which get the associated grid size :param time: the time because level depends on it """ - import glob - h5_time_grp_key = "t" - files = self.available_diags - any_file = files[0] - h5_filename = any_file import h5py - data_file = h5py.File(h5_filename, "r") - def _get_time(): if time: return time @@ -257,21 +248,31 @@ def _get_time(): self.default_time_ = float(list(data_file[h5_time_grp_key].keys())[0]) return self.default_time_ - time = _get_time() + h5_time_grp_key = "t" + files = self.available_diags - hier = self._get_hierarchy(time, h5_filename.split("/")[-1]) + for h5_filename in files: + data_file = h5py.File(h5_filename, "r") - if level == "finest": - level = hier.finest_level(time) - fac = np.power(hier.refinement_ratio, level) + time = _get_time() - root_cell_width = np.asarray(data_file.attrs["cell_width"]) + try: + hier = self._get_hierarchy(time, h5_filename.split("/")[-1]) + + if level == "finest": + level = hier.finest_level(time) + fac = np.power(hier.refinement_ratio, level) + + root_cell_width = np.asarray(data_file.attrs["cell_width"]) + + return root_cell_width / fac + + except KeyError: + ... # time may not be avilaable for given quantity - return root_cell_width / fac + raise RuntimeError("Unable toGetDl") def all_times(self): - from glob import glob - import os import h5py files = self.available_diags diff --git a/pyphare/pyphare/simulator/simulator.py b/pyphare/pyphare/simulator/simulator.py index 5bebe5e30..70b97f1f4 100644 --- a/pyphare/pyphare/simulator/simulator.py +++ b/pyphare/pyphare/simulator/simulator.py @@ -113,7 +113,7 @@ def setup(self): self.cpp_hier, ) return self - except: + except Exception: import sys import traceback @@ -137,7 +137,7 @@ def initialize(self): self._auto_dump() # first dump might be before first advance return self - except: + except Exception: import sys print( diff --git a/tests/functional/tdtagged/CMakeLists.txt b/tests/functional/tdtagged/CMakeLists.txt index 54b9a1bcb..3556e2b5e 100644 --- a/tests/functional/tdtagged/CMakeLists.txt +++ b/tests/functional/tdtagged/CMakeLists.txt @@ -10,5 +10,6 @@ endif() if(HighFive) ## These test use dump diagnostics so require HighFive! -phare_python3_exec(11 test-td-tagged td1dtagged.py ${CMAKE_CURRENT_BINARY_DIR}) + phare_python3_exec(11 test-td-tagged td1dtagged.py ${CMAKE_CURRENT_BINARY_DIR}) + endif() diff --git a/tests/functional/tdtagged/td1dtagged.py b/tests/functional/tdtagged/td1dtagged.py index b3a240ed2..2d30e59f5 100644 --- a/tests/functional/tdtagged/td1dtagged.py +++ b/tests/functional/tdtagged/td1dtagged.py @@ -10,10 +10,13 @@ import matplotlib as mpl import numpy as np -mpl.use("Agg") +from tests.simulator.test_advance import AdvanceTestBase +from tests.diagnostic import all_timestamps +from pyphare.cpp import cpp_lib +cpp = cpp_lib() -from tests.diagnostic import all_timestamps +mpl.use("Agg") def density(x): @@ -240,12 +243,6 @@ def by_fit(x, x0, L): raise RuntimeError(f"x0 (={x0}) too far from 172") -from tests.simulator.test_advance import AdvanceTestBase -from pyphare.cpp import cpp_lib - -cpp = cpp_lib() - - test = AdvanceTestBase()