|
|
import pandas as pd |
|
|
import os |
|
|
from tqdm import tqdm |
|
|
import argparse |
|
|
|
|
|
def main(): |
|
|
""" |
|
|
Main function to process CSV data and generate input and gt data files for ETT forecasting. |
|
|
""" |
|
|
|
|
|
parser = argparse.ArgumentParser(description="Process ETT forecasting data.") |
|
|
parser.add_argument("--data_path", type=str, required=True, help="Path to the ETTh1.csv file.") |
|
|
args = parser.parse_args() |
|
|
|
|
|
try: |
|
|
|
|
|
csv_file_path = args.data_path |
|
|
|
|
|
|
|
|
df = pd.read_csv(csv_file_path) |
|
|
|
|
|
|
|
|
target_folder = "Energy-ETT-Transformer_sensor_signal-Forecasting" |
|
|
input_data_path = os.path.join(target_folder, "raw_input_data") |
|
|
gt_data_path = os.path.join(target_folder, "raw_gt_data") |
|
|
|
|
|
|
|
|
os.makedirs(input_data_path, exist_ok=True) |
|
|
os.makedirs(gt_data_path, exist_ok=True) |
|
|
|
|
|
|
|
|
seq_len_list = [96, 96] |
|
|
pred_len_list = [96, 720] |
|
|
label = 0 |
|
|
|
|
|
|
|
|
generate_data_type = "test" |
|
|
|
|
|
|
|
|
for seq_len, pred_len in zip(seq_len_list, pred_len_list): |
|
|
|
|
|
|
|
|
start_idx = { |
|
|
"train": 0, |
|
|
"val": 12 * 30 * 24 - pred_len, |
|
|
"test": (12 + 4) * 30 * 24 - pred_len, |
|
|
} |
|
|
|
|
|
end_idx = { |
|
|
"train": 12 * 30 * 24 - seq_len - pred_len, |
|
|
"val": (12 + 4) * 30 * 24 - seq_len - pred_len, |
|
|
"test": (12 + 8) * 30 * 24 - seq_len - pred_len, |
|
|
} |
|
|
|
|
|
|
|
|
for i in tqdm(range(start_idx[generate_data_type], end_idx[generate_data_type] + 1), desc=f"Generating data: context_length: {seq_len}, prediction_length: {pred_len}"): |
|
|
|
|
|
data_input = df.iloc[i : i + seq_len] |
|
|
data_gt = df.iloc[i + seq_len : i + seq_len + pred_len] |
|
|
|
|
|
|
|
|
data_input[['OT']].to_csv( |
|
|
os.path.join(input_data_path, f'seq{seq_len}_label{label}_pred{pred_len}_index{i}_input_ts_OT.csv'), |
|
|
index=False, |
|
|
header=False, |
|
|
encoding='utf-8' |
|
|
) |
|
|
data_gt[['OT']].to_csv( |
|
|
os.path.join(gt_data_path, f'seq{seq_len}_label{label}_pred{pred_len}_index{i}_target_ts_OT.csv'), |
|
|
index=False, |
|
|
header=False, |
|
|
encoding='utf-8' |
|
|
) |
|
|
|
|
|
except FileNotFoundError: |
|
|
print(f"Error: File {csv_file_path} not found. Please check the path or filename.") |
|
|
except pd.errors.EmptyDataError: |
|
|
print(f"Error: File {csv_file_path} is empty.") |
|
|
except pd.errors.ParserError: |
|
|
print(f"Error: File {csv_file_path} is not a valid CSV file.") |
|
|
except Exception as e: |
|
|
print(f"An unexpected error occurred: {e}") |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|