def split_seq(sequences, covariates, seq_length, slide_step, predict_length, save_dir):
    """Divide the training sequence into windows"""
    data_length = len(sequences[0])
    windows = (data_length-seq_length+slide_step) // slide_step
    train_windows = int(0.97 * windows)
    test_windows = windows - train_windows
    train_data = np.zeros((train_windows*len(sequences), seq_length+predict_length-1, 5), dtype=np.float32)
    test_data = np.zeros((test_windows*len(sequences), seq_length+predict_length-1, 5), dtype=np.float32)

    count = 0
    split_start = 0
    seq_ids = np.arange(len(sequences))[:, None]
    end = split_start + seq_length + predict_length - 1
    while end <= data_length:
        if count < train_windows:
            train_data[count*len(sequences):(count+1)*len(sequences), :, 0] = sequences[:, split_start:end]
            train_data[count*len(sequences):(count+1)*len(sequences), :, 1:4] = covariates[split_start:end, :]
            train_data[count*len(sequences):(count+1)*len(sequences), :, -1] = seq_ids
        else:
            test_data[(count-train_windows)*len(sequences):(count-train_windows+1)*len(sequences), :, 0] = sequences[:, split_start:end]
            test_data[(count-train_windows)*len(sequences):(count-train_windows+1)*len(sequences), :, 1:4] = covariates[split_start:end, :]
            test_data[(count-train_windows)*len(sequences):(count-train_windows+1)*len(sequences), :, -1] = seq_ids

        count += 1
        split_start += slide_step
        end = split_start + seq_length + predict_length - 1

    os.makedirs(save_dir, exist_ok=True)

    train_data, v = normalize(train_data, seq_length)
    save(train_data, v, save_dir + 'train')
    test_data, v = normalize(test_data, seq_length)
    save(test_data, v, save_dir + 'test')
Divide the training sequence into windows
PatchTST_supervised/Formers/Pyraformer/preprocess_wind.py