Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.1 on 2022-01-26 at 16:00 UTC+1 (a few minutes of down time)

Commit 87e209bc authored by Pierre Augier's avatar Pierre Augier
Browse files

spatiotemporal_spectra: _get_path_saved_spectra and RuntimeError if MPI

parent 880ee37147ca
......@@ -382,6 +382,12 @@ class SpatioTemporalSpectra(SpecificOutput):
def load_time_series(self, keys=None, tmin=0, tmax=None, dtype=None):
"""load time series from files"""
if mpi.nb_proc > 1:
raise RuntimeError(
"This postprocessing function should not be called with MPI."
)
if keys is None:
keys = self.keys_fields
if tmax is None:
......
......@@ -10,7 +10,6 @@ Provides:
"""
from pathlib import Path
from math import pi
import numpy as np
......@@ -75,6 +74,14 @@ def loop_spectra_kzkhomega(
class SpatioTemporalSpectraNS3D(SpatioTemporalSpectra):
def _get_path_saved_spectra(self, tmin, tmax, dtype, save_urud):
base = f"spatiotemporal_spectra_{tmin}_{tmax}"
if dtype is not None:
base += "_{dtype}"
if save_urud:
base += "_urud"
return self.path_dir / (base + ".h5")
def save_spectra_kzkhomega(
self, tmin=0, tmax=None, dtype=None, save_urud=False
):
......@@ -140,7 +147,7 @@ class SpatioTemporalSpectraNS3D(SpatioTemporalSpectra):
pass
# save to file
path_file = Path(self.sim.output.path_run) / "spatiotemporal_spectra.h5"
path_file = self._get_path_saved_spectra(tmin, tmax, dtype, save_urud)
with h5py.File(path_file, "w") as file:
file.attrs["tmin"] = tmin
file.attrs["tmax"] = tmax
......@@ -184,13 +191,15 @@ class SpatioTemporalSpectraNS3D(SpatioTemporalSpectra):
if tmax is None:
tmax = self.sim.params.time_stepping.t_end
path_file = path_file = (
Path(self.sim.output.path_run) / "spatiotemporal_spectra.h5"
)
key_spect = "spectrum_" + key_field
if key_spect.startswith("spectrum_Kh"):
save_urud = True
else:
save_urud = False
spectra_kzkhomega = {}
path_file = self._get_path_saved_spectra(tmin, tmax, dtype, save_urud)
key_spect = "spectrum_" + key_field
spectra_kzkhomega = {}
if path_file.exists():
# we should check if times match?
......@@ -209,10 +218,6 @@ class SpatioTemporalSpectraNS3D(SpatioTemporalSpectra):
spectra_kzkhomega["omegas"] = file["omegas"][...]
else:
# compute spectra and save to file, then load
if key_spect.startswith("spectrum_Kh"):
save_urud = True
else:
save_urud = False
self.save_spectra_kzkhomega(
tmin=tmin, tmax=tmax, dtype=dtype, save_urud=save_urud
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment