Datasets:
Download process/process_ETT.py from OpenTSLab/SciTS: direct link, hf CLI and curl.
- Browser
- Download file 3.45 kB
-
https://huggingface.co/datasets/OpenTSLab/SciTS/resolve/main/process/process_ETT.py
- Command line
-
hf download hf://datasets/OpenTSLab/SciTS/process/process_ETT.py
-
curl -L -o process_ETT.py https://huggingface.co/datasets/OpenTSLab/SciTS/resolve/main/process/process_ETT.py
3.45 kB
| 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. | |
| """ | |
| # Set up argument parser | |
| 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: | |
| # Define the source folder containing the original files | |
| csv_file_path = args.data_path | |
| # Read the CSV file into a DataFrame | |
| df = pd.read_csv(csv_file_path) | |
| # Define target folders for input and ground truth data | |
| 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") | |
| # Create directories if they don't exist | |
| os.makedirs(input_data_path, exist_ok=True) | |
| os.makedirs(gt_data_path, exist_ok=True) | |
| # Define sequence and prediction lengths | |
| seq_len_list = [96, 96] | |
| pred_len_list = [96, 720] | |
| label = 0 # No overloap | |
| # Specify the type of data to generate (e.g., "train", "val", "test") | |
| generate_data_type = "test" | |
| # Iterate over sequence and prediction lengths | |
| for seq_len, pred_len in zip(seq_len_list, pred_len_list): | |
| # Define start and end indices for different data types | |
| 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, | |
| } | |
| # Iterate over the specified range of indices | |
| 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}"): | |
| # Extract input and gt data | |
| data_input = df.iloc[i : i + seq_len] | |
| data_gt = df.iloc[i + seq_len : i + seq_len + pred_len] | |
| # Save input and gt data to CSV files, select 'OT' column | |
| 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() | |