diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/transivent/io.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/transivent/io.py b/src/transivent/io.py index 5eb46f6..b272283 100644 --- a/src/transivent/io.py +++ b/src/transivent/io.py @@ -335,16 +335,16 @@ def rd( # x = x.astype(np.float32) # NB: data is already in physical units (V) # Use np.linspace for more robust time array generation + # Generate with float64 precision to handle very large arrays, then convert to float32 num_points = len(x) - if num_points > 0: - t = np.linspace(0, (num_points - 1) * si, num_points, dtype=np.float32) - else: - t = np.array([], dtype=np.float32) - warnings.warn( - f"Generated an empty time array for file {rel_fp}. " - f"Length of signal: {len(x)}, sampling interval: {si}. " - "This might indicate an issue with input data or sampling interval." + if num_points == 0: + raise RuntimeError( + f"No data points found in file {rel_fp}. " + f"This indicates an empty or corrupted binary file." ) + + t = np.linspace(0, (num_points - 1) * si, num_points, dtype=np.float64) + t = t.astype(np.float32) return t, x @@ -445,8 +445,9 @@ def rd_chunked( start_time, start_time + (num_points - 1) * si, num_points, - dtype=np.float32, + dtype=np.float64, ) + t_chunk = t_chunk.astype(np.float32) yield t_chunk, x_chunk.astype(np.float32) |
