-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterpolate_aligned_data.py
More file actions
executable file
·70 lines (56 loc) · 2.61 KB
/
interpolate_aligned_data.py
File metadata and controls
executable file
·70 lines (56 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pandas as pd
import numpy as np
import os
import logging
logging.disable(logging.CRITICAL)
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def interpolate_stress_data(input_file, output_file=None):
"""
Interpolate stress data to whole millisecond values from 0-5000ms.
Parameters:
-----------
input_file : str
Path to the input CSV file with aligned stress traces.
output_file : str, optional
Path to save the interpolated data. If None, output filename is generated.
"""
# Load the data
logging.info(f"Loading data from {input_file}")
data = pd.read_csv(input_file)
# Get column names for time and stress traces
time_col = data.columns[0]
stress_cols = [col for col in data.columns if col.startswith('Stress_')]
# Create a new dataframe with whole millisecond values
new_time = np.arange(0, 5001) # 0 to 5000 inclusive
new_data = pd.DataFrame({time_col: new_time})
# Interpolate each stress column
for col in stress_cols:
logging.info(f"Interpolating {col}")
# Use scipy's interp1d for linear interpolation
new_data[col] = np.interp(new_time, data[time_col], data[col])
# Generate output filename if not provided
if output_file is None:
base_name = os.path.basename(input_file)
name_parts = os.path.splitext(base_name)
output_file = os.path.join(os.path.dirname(input_file),
f"{name_parts[0]}_interpolated{name_parts[1]}")
# Save the interpolated data
logging.info(f"Saving interpolated data to {output_file}")
new_data.to_csv(output_file, index=False)
return new_data
def main():
import argparse
parser = argparse.ArgumentParser(description='Interpolate stress data to whole millisecond values.')
parser.add_argument('--input_file', type=str, required=True,
help='Path to the input CSV file with aligned stress traces')
parser.add_argument('--output_file', type=str, default=None,
help='Path to save the interpolated data')
args = parser.parse_args()
# Interpolate the data
interpolated_data = interpolate_stress_data(args.input_file, args.output_file)
# Print information about the result
logging.info(f"Interpolation complete. Output shape: {interpolated_data.shape}")
logging.info(f"Time range: {interpolated_data[interpolated_data.columns[0]].min()} to {interpolated_data[interpolated_data.columns[0]].max()} ms")
if __name__ == "__main__":
main()