Commit fb8b621c authored by Jason Reneuve's avatar Jason Reneuve
Browse files

compute spectra

parent e695f10ffb6d
......@@ -396,3 +396,30 @@ class SpatiotemporalSpectra(SpecificOutput):
series["times"] = times
return series
def compute_spectra(self, tmin=0, tmax=None):
"""compute spatiotemporal spectra from files"""
if tmax is None:
tmax = self.sim.params.time_stepping.t_end
# load time series as state_spect arrays + times
series = self.load_time_series(tmin=tmin, tmax=tmax)
# get the sampling frequency
times = series["times"]
f_sample = 1 / np.mean(times[1:] - times[:-1])
# compute spectra
print("computing temporal spectra...")
dict_spectra = {}
for key, data in series.items():
if key.startswith("times"):
continue
freq, spectra = signal.periodogram(data, fs=f_sample)
dict_spectra[key] = spectra
dict_spectra["omegas"] = 2 * pi * freq
return dict_spectra
......@@ -222,7 +222,7 @@ class TestOutput(TestSimulBase):
sim3.output.temporal_spectra.save_data_as_phys_fields(
delta_index_times=2
)
sim3.output.spatiotemporal_spectra.load_time_series()
sim3.output.spatiotemporal_spectra.compute_spectra()
plt.close("all")
......
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