Read about our upcoming Code of Conduct on this issue

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

Commit 5a10d0bd authored by Jason Reneuve's avatar Jason Reneuve
Browse files

fix plot dtype + filter_tmins_path

parent e77bb7bd4d4c
......@@ -27,7 +27,7 @@ from transonic import boost
# TODO: uncomment this @boost when it works well
# @boost
def find_index_first_leq(arr: "float[:]", value: float):
def find_index_first_geq(arr: "float[:]", value: float):
"""find the first index such that `arr[index] >= value`"""
for i, v in enumerate(arr):
if v >= value:
......@@ -35,8 +35,31 @@ def find_index_first_leq(arr: "float[:]", value: float):
raise ValueError("No index such that `arr[index] >= value`")
# TODO: uncomment this @boost when it works well
# @boost
def find_index_first_g(arr: "float[:]", value: float):
"""find the first index such that `arr[index] > value`"""
for i, v in enumerate(arr):
if v > value:
return i
raise ValueError("No index such that `arr[index] > value`")
# TODO: uncomment this @boost when it works well
# @boost
def find_index_first_l(arr: "float[:]", value: float):
"""find the first index such that `arr[index] < value`"""
for i, v in enumerate(arr):
if v < value:
return i
raise ValueError("No index such that `arr[index] < value`")
def filter_tmins_paths(tmin, tmins, paths):
start = find_index_first_leq(tmins, tmin)
if tmins.size == 1:
return tmins, paths
delta_tmin = np.diff(tmins).mean()
start = find_index_first_l(tmin - tmins, delta_tmin)
return tmins[start:], paths[start:]
......@@ -49,15 +72,15 @@ def get_arange_minmax(times: "float[:]", tmin: float, tmax: float):
"""
if tmin < times[0]:
if tmin <= times[0]:
start = 0
else:
start = find_index_first_leq(times, tmin)
start = find_index_first_geq(times, tmin)
if tmax < times[-1]:
if tmax >= times[-1]:
stop = len(times)
else:
stop = find_index_first_leq(times, tmax)
stop = find_index_first_g(times, tmax)
return np.arange(start, stop)
......
......@@ -180,16 +180,14 @@ class SpatioTemporalSpectraNS3D(SpatioTemporalSpectra):
# we should check if times match?
print("loading spectra from file...")
with h5py.File(path_file, "r") as file:
spectra_kzkhomega[key_spect] = file[key_spect][...]
if dtype == "complex64":
spectra_kzkhomega[key_spect] = file[key_spect][...].astype(
"float32"
)
float_dtype = "float32"
elif dtype == "complex128":
spectra_kzkhomega[key_spect] = file[key_spect][...].astype(
"float64"
)
else:
spectra_kzkhomega[key_spect] = file[key_spect][...]
float_dtype = "float64"
if dtype:
spectrum = spectrum.astype(float_dtype)
spectra_kzkhomega[key_spect] = spectrum
else:
# compute spectra and save to file, then load
if key_spect.startswith("spect_Kh"):
......
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