Ejemplo n.º 1
0
	def clear_directories(self, base_path, delete_all = False):
		# delete all files from a directory
		print("Clearing directories...")
		dir_names = self.dataloader.get_all_directory_namelist()
		base_path = os.path.join(self.f_prefix, base_path)
		for dir_ in dir_names:
			dir_path = os.path.join(base_path, dir_)
			file_names = get_all_file_names(dir_path)
			if delete_all:
				base_file_names = []
			else:
				base_file_names = self.dataloader.get_base_file_name(dir_)
			[delete_file(dir_path, [file_name]) for file_name in file_names if file_name not in base_file_names]
Ejemplo n.º 2
0
def main():


    parser = argparse.ArgumentParser()

    # frame rate of video
    parser.add_argument('--frame', type=int, default=1,
                        help='Frame of video created from plots')
    # gru model
    parser.add_argument('--gru', action="store_true", default=False,
                        help='Visualization of GRU model')
    # number of validation dataset
    parser.add_argument('--num_of_data', type=int, default=3,
                        help='Number of validation data will be visualized (If 0 is given, will work on test data mode)')
    # drive support
    parser.add_argument('--drive', action="store_true", default=False,
                        help='Use Google drive or not')
    # minimum lenght of trajectory
    parser.add_argument('--min_traj', type=int,  default=3,
                        help='Min. treshold of number of frame to be removed from a sequence')
    # percentage of peds will be taken for each frame
    parser.add_argument('--max_ped_ratio', type=float,  default=0.8,
                        help='Percentage of pedestrian will be illustrated in a plot for a sequence')
    # maximum ped numbers
    parser.add_argument('--max_target_ped', type=int,  default=20,
                        help='Maximum number of peds in final plot')
    # method to be visualized
    parser.add_argument('--method', type=int, default=1,
                        help='Method of lstm will be used (1 = social lstm, 2 = obstacle lstm, 3 = vanilla lstm)')


    # Parse the parameters
    args = parser.parse_args()

    prefix = ''
    f_prefix = '.'
    if args.drive is True:
      prefix='drive/semester_project/social_lstm_final/'
      f_prefix = 'drive/semester_project/social_lstm_final'

    model_name = "LSTM"
    method_name = get_method_name(args.method)
    if args.gru:
        model_name = "GRU"

    
    plot_file_directory = 'validation'

    # Directories
    if args.num_of_data is 0:
        plot_file_directory = 'test'

    # creation of paths
    save_plot_directory = os.path.join(f_prefix, 'plot',method_name, model_name,'plots/')
    plot_directory = os.path.join(f_prefix, 'plot', method_name, model_name, plot_file_directory)
    video_directory = os.path.join(f_prefix, 'plot',method_name, model_name,'videos/')
    plot_file_name = get_all_file_names(plot_directory)
    num_of_data = np.clip(args.num_of_data, 0, len(plot_file_name))
    plot_file_name = random.sample(plot_file_name, num_of_data)

    
    for file_index in range(len(plot_file_name)):
        file_name = plot_file_name[file_index]
        folder_name = remove_file_extention(file_name)
        print("Now processing: ", file_name)

        file_path = os.path.join(plot_directory, file_name)
        video_save_directory = os.path.join(video_directory, folder_name)
        figure_save_directory = os.path.join(save_plot_directory, folder_name)

        # remove existed plots
        clear_folder(video_save_directory)
        clear_folder(figure_save_directory)


        if not os.path.exists(video_save_directory):
            os.makedirs(video_save_directory)
        if not os.path.exists(figure_save_directory):
            os.makedirs(figure_save_directory)
        

        try:
            f = open(file_path, 'rb')
        except FileNotFoundError:
            print("File not found: %s"%file_path)
            continue


        results = pickle.load(f)
        result_arr = np.array(results)
        true_trajectories = np.array(result_arr[:,0])
        pred_trajectories = np.array(result_arr[:,1])
        frames = np.array(result_arr[:, 4])

        target_id_trajs = []
        args.max_target_ped = np.clip(args.max_target_ped, 0, len(results)-1)
        
        min_r = -10
        max_r = 10
        plot_offset = 1

        for i in range(len(results)):
            print("##########################################################################################")
            name = 'sequence' + str(i).zfill(5)
            print("Now processing seq: ",name)

            if args.num_of_data is 0: #test data visualization
                target_traj = plot_trajectories(results[i][0], results[i][1], results[i][2], results[i][3], results[i][4], name, figure_save_directory,  args.min_traj ,args.max_ped_ratio, results[i][5], [min_r, max_r, plot_offset], results[i][6])
            else:
                target_traj =  plot_trajectories(results[i][0], results[i][1], results[i][2], results[i][3],results[i][4], name, figure_save_directory, args.min_traj ,args.max_ped_ratio, results[i][5], [min_r, max_r, plot_offset], 20)
            target_traj.append(results[i][2])#pedlist
            target_traj.append(results[i][3])#lookup
            target_id_trajs.append(target_traj)

        
        save_video(figure_save_directory, video_save_directory, plot_file_name[file_index], args.frame)
        plot_target_trajs(target_id_trajs, figure_save_directory, args.max_target_ped, plot_offset)
Ejemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser()

    # frame rate of video
    parser.add_argument('--frame',
                        type=int,
                        default=1,
                        help='Frame of video created from plots')
    # gru model
    parser.add_argument('--gru',
                        action="store_true",
                        default=False,
                        help='Visualization of GRU model')
    # number of validation dataset
    parser.add_argument(
        '--num_of_data',
        type=int,
        default=0,
        help=
        'Number of validation data will be visualized (If 0 is given, will work on test data mode)'
    )
    # drive support
    parser.add_argument('--drive',
                        action="store_true",
                        default=False,
                        help='Use Google drive or not')
    # minimum lenght of trajectory
    parser.add_argument(
        '--min_traj',
        type=int,
        default=3,
        help='Min. treshold of number of frame to be removed from a sequence')
    # percentage of peds will be taken for each frame
    parser.add_argument(
        '--max_ped_ratio',
        type=float,
        default=0.8,
        help=
        'Percentage of pedestrian will be illustrated in a plot for a sequence'
    )
    # maximum ped numbers
    parser.add_argument('--max_target_ped',
                        type=int,
                        default=20,
                        help='Maximum number of peds in final plot')
    # method to be visualized
    parser.add_argument(
        '--method',
        type=int,
        default=1,
        help=
        'Method of lstm will be used (1 = social lstm, 2 = obstacle lstm, 3 = vanilla lstm)'
    )
    # Parse the parameters
    args = parser.parse_args()

    prefix = ''
    f_prefix = '.'

    method_name = "VANILLALSTM"
    model_name = "LSTM"
    if args.gru:
        model_name = "GRU"

    plot_file_directory = 'validation'

    # Directories
    if args.num_of_data is 0:
        plot_file_directory = 'test'

    # creation of paths
    save_plot_directory = os.path.join(f_prefix, 'plot', method_name,
                                       model_name, 'plots/')
    plot_directory = os.path.join(f_prefix, 'plot', method_name, model_name,
                                  plot_file_directory)
    video_directory = os.path.join(f_prefix, 'plot', method_name, model_name,
                                   'videos/')
    plot_file_name = get_all_file_names(plot_directory)

    print(plot_file_name)
    for file_index in range(len(plot_file_name)):
        file_name = plot_file_name[file_index]
        print("Now processing: ", file_name)

        file_path = os.path.join(plot_directory, file_name)

        try:
            f = open(file_path, 'rb')
        except FileNotFoundError:
            print("File not found: %s" % file_path)
            continue

        results = pickle.load(f)
        obs_length = np.array(results[0][1])
        pred_length = np.array(results[0][0])
        enthalpy_max = [408, 430, 251]
        enthalpy_min = [404, 422.5, 239]
        enthalpy_label = [
            'evaporator outlet enthalpy', 'compressor outlet enthalpy',
            'condenser outlet enthalpy'
        ]
        '''
        draw enthalpy prediction diagram
        '''
        expected_enthalpy_arr = np.array(results[0][2])
        predicted_enthalpy_arr = np.array(results[0][3])
        error_enthalpy = np.zeros((expected_enthalpy_arr.shape[0], 3))
        plt.figure(figsize=(10, 5))

        for i in range(expected_enthalpy_arr.shape[0]):
            for idx in range(3):
                expected_enthalpy = expected_enthalpy_arr[i, :, idx:idx + 1]
                predicted_enthalpy = predicted_enthalpy_arr[i, :, idx:idx + 1]
                # predicted_enthalpy[obs_length:] = filter(predicted_enthalpy[obs_length:])
                mean_obs_enthalpy = np.mean(expected_enthalpy[:obs_length])
                mean_expected_enthalpy = np.mean(
                    expected_enthalpy[obs_length:])
                mean_predicted_enthalpy = np.mean(
                    predicted_enthalpy[obs_length:])

                # draw plot
                plt.ylim(enthalpy_min[idx], enthalpy_max[idx])
                plt.plot(np.arange(0, obs_length * 2, 2),
                         expected_enthalpy[:obs_length],
                         color='green',
                         label="Observation data",
                         linestyle='-',
                         marker='.')
                plt.plot(np.arange(obs_length * 2,
                                   expected_enthalpy.shape[0] * 2, 2),
                         expected_enthalpy[obs_length:],
                         label="Expected " + enthalpy_label[idx],
                         linestyle='-',
                         marker='.')
                plt.plot(np.arange(obs_length * 2,
                                   expected_enthalpy.shape[0] * 2, 2),
                         predicted_enthalpy[obs_length:],
                         label="Predictive " + enthalpy_label[idx],
                         linestyle='-',
                         marker='+')
                plt.plot([0, obs_length * 2],
                         [mean_obs_enthalpy, mean_obs_enthalpy],
                         color='black',
                         label="Observation length mean " +
                         enthalpy_label[idx])
                plt.plot([obs_length * 2, expected_enthalpy.shape[0] * 2],
                         [mean_expected_enthalpy, mean_expected_enthalpy],
                         color='gray',
                         label="Expected mean " + enthalpy_label[idx])
                plt.plot([obs_length * 2, expected_enthalpy.shape[0] * 2],
                         [mean_predicted_enthalpy, mean_predicted_enthalpy],
                         color='red',
                         label="Predictive mean " + enthalpy_label[idx])

                plt.xlabel('Time(minutes)', fontsize=12)
                plt.ylabel('Enthalpy(kJ/kg)', fontsize=12)
                plt.xticks(fontsize=12)
                plt.yticks(fontsize=12)
                plt.legend()
                plt.savefig(plot_directory + "/" + str(i) + "H" +
                            str(idx + 1) + ".png")
                plt.clf()
                # plt.show()

                # compute error
                # sc = MinMaxScaler()
                # fit_data = np.concatenate((expected_enthalpy, predicted_enthalpy), axis=0)
                # fit_data = sc.fit_transform(fit_data)

                # expected_enthalpy = fit_data[:expected_enthalpy.shape[0]]
                # predicted_enthalpy = fit_data[expected_enthalpy.shape[0]:]

                # error = np.sum(np.abs(expected_enthalpy[obs_length:]-predicted_enthalpy[obs_length:]))/expected_enthalpy[obs_length:].shape[0]
                error = np.abs(mean_expected_enthalpy -
                               mean_predicted_enthalpy)
                error = np.around(error, decimals=4)
                error_enthalpy[i, idx] = error

        new_df = pd.DataFrame({
            'h1 err': error_enthalpy[:, 0],
            'h2 err': error_enthalpy[:, 1],
            'h3 err': error_enthalpy[:, 2]
        })
        new_df.to_csv(plot_directory + "/" + "enthalpy_error_minutes" + ".csv",
                      index=False)
        '''
        draw cop prediction diagram (minutes)
        '''
        error_cop = np.zeros((expected_enthalpy_arr.shape[0], 1))
        for i in range(expected_enthalpy_arr.shape[0]):
            expected_cop_arr = (expected_enthalpy_arr[i, :, 0:1] -
                                expected_enthalpy_arr[i, :, 2:3]) / (
                                    expected_enthalpy_arr[i, :, 1:2] -
                                    expected_enthalpy_arr[i, :, 0:1])
            predicted_cop_arr = (predicted_enthalpy_arr[i, :, 0:1] -
                                 predicted_enthalpy_arr[i, :, 2:3]) / (
                                     predicted_enthalpy_arr[i, :, 1:2] -
                                     predicted_enthalpy_arr[i, :, 0:1])
            # predicted_cop_arr[obs_length:] = filter(predicted_cop_arr[obs_length:])
            mean_obs_cop = np.mean(expected_cop_arr[:obs_length])
            mean_expected_cop = np.mean(expected_cop_arr[obs_length:])
            mean_predicted_cop = np.mean(predicted_cop_arr[obs_length:])

            plt.ylim(6, 10)
            plt.plot(np.arange(0, obs_length * 2, 2),
                     expected_cop_arr[:obs_length],
                     color='green',
                     label="Observation data",
                     linestyle='-',
                     marker='.')
            plt.plot(np.arange(obs_length * 2, expected_cop_arr.shape[0] * 2,
                               2),
                     expected_cop_arr[obs_length:],
                     label="Expected COP",
                     linestyle='-',
                     marker='.')
            plt.plot(np.arange(obs_length * 2, expected_cop_arr.shape[0] * 2,
                               2),
                     predicted_cop_arr[obs_length:],
                     label="Predictive COP",
                     linestyle='-',
                     marker='+')
            plt.plot([0, obs_length * 2], [mean_obs_cop, mean_obs_cop],
                     color='black',
                     label="Observation length mean COP")
            plt.plot([obs_length * 2, expected_cop_arr.shape[0] * 2],
                     [mean_expected_cop, mean_expected_cop],
                     color='gray',
                     label="Expected mean COP")
            plt.plot([obs_length * 2, expected_cop_arr.shape[0] * 2],
                     [mean_predicted_cop, mean_predicted_cop],
                     color='red',
                     label="Predictive mean COP")
            plt.xlabel('Time(minutes)', fontsize=12)
            plt.ylabel('COP', fontsize=12)
            plt.xticks(fontsize=12)
            plt.yticks(fontsize=12)
            plt.legend()

            plt.savefig(plot_directory + "/test" + str(i) + "_COP minutes.png")
            plt.clf()
            # plt.show()

            # compute error
            # sc = MinMaxScaler()
            # fit_data = np.concatenate((expected_cop_arr, predicted_cop_arr), axis=0)
            # fit_data = sc.fit_transform(fit_data)
            # expected_cop_arr = fit_data[:expected_cop_arr.shape[0]]
            # predicted_cop_arr = fit_data[expected_cop_arr.shape[0]:]
            # print(expected_cop_arr.shape, predicted_cop_arr.shape)
            # error = np.sum(np.abs(expected_cop_arr[obs_length:]-predicted_cop_arr[obs_length:]))/expected_cop_arr[obs_length:].shape[0]
            error = np.abs(mean_expected_cop - mean_predicted_cop)
            error = np.around(error, decimals=4)
            error_cop[i, 0] = error

        new_df = pd.DataFrame({'minutes err': error_cop[:, 0]})
        new_df.to_csv(plot_directory + "/" + "COP_error_minutes.csv",
                      index=False)
        '''
        hours
        '''
        expected_cop_day_arr = []
        predicted_cop_day_arr = []
        for i in range(expected_enthalpy_arr.shape[0]):
            expected_cop_arr = (expected_enthalpy_arr[i, :, 0:1] -
                                expected_enthalpy_arr[i, :, 2:3]) / (
                                    expected_enthalpy_arr[i, :, 1:2] -
                                    expected_enthalpy_arr[i, :, 0:1])
            predicted_cop_arr = (predicted_enthalpy_arr[i, :, 0:1] -
                                 predicted_enthalpy_arr[i, :, 2:3]) / (
                                     predicted_enthalpy_arr[i, :, 1:2] -
                                     predicted_enthalpy_arr[i, :, 0:1])
            # predicted_cop_arr[obs_length:] = filter(predicted_cop_arr[obs_length:])

            expected_cop_day = expected_cop_arr[obs_length:]
            predicted_cop_day = predicted_cop_arr[obs_length:]
            expected_cop_day = np.mean(expected_cop_day)
            predicted_cop_day = np.mean(predicted_cop_day)
            expected_cop_day_arr.append(expected_cop_day)
            predicted_cop_day_arr.append(predicted_cop_day)

        plt.ylim(6.5, 9)
        hour = pred_length / 30
        inveral = 7
        expected_cop_day_arr = np.array(expected_cop_day_arr)
        predicted_cop_day_arr = np.array(predicted_cop_day_arr)
        expected_cop_day_arr = np.reshape(expected_cop_day_arr,
                                          (expected_cop_day_arr.shape[0], 1))
        predicted_cop_day_arr = np.reshape(predicted_cop_day_arr,
                                           (predicted_cop_day_arr.shape[0], 1))
        plt.xticks(np.arange(0, expected_cop_day_arr.shape[0] * hour, hour))

        plt.plot(np.arange(0, expected_cop_day_arr.shape[0] * hour, hour),
                 expected_cop_day_arr,
                 label="Expected COP",
                 linestyle='--',
                 marker='+')
        plt.plot(np.arange(0, expected_cop_day_arr.shape[0] * hour, hour),
                 predicted_cop_day_arr,
                 label="Predictive COP",
                 linestyle='--',
                 marker='^')
        plt.xlabel('Time(hours)', fontsize=12)
        plt.ylabel('COP', fontsize=12)
        plt.xticks(fontsize=12)
        plt.yticks(fontsize=12)
        plt.legend()
        plt.savefig(plot_directory + "/" + str(hour) + "hours_COP" + ".png")
        plt.clf()
        # plt.show()

        # compute error
        # sc = MinMaxScaler()
        # fit_data = np.concatenate((expected_cop_day_arr, predicted_cop_day_arr), axis=0)
        # fit_data = sc.fit_transform(fit_data)
        # expected = fit_data[:expected_cop_day_arr.shape[0]]
        # predicted = fit_data[expected_cop_day_arr.shape[0]:]

        error = np.abs(expected_cop_day_arr - predicted_cop_day_arr)
        error = np.around(error, decimals=4)
        print(expected_cop_day_arr.shape, predicted_cop_day_arr.shape,
              error.shape)

        new_df = pd.DataFrame({
            'real COP': expected_cop_day_arr[:, 0],
            'predict COP': predicted_cop_day_arr[:, 0],
            'err': error[:, 0]
        })
        new_df.to_csv(plot_directory + "/" + "COP_error_hours.csv",
                      index=False)
def main():
    parser = argparse.ArgumentParser()

    # gru model
    parser.add_argument('--gru',
                        action="store_true",
                        default=True,
                        help='Visualization of GRU model')
    # Parse the parameters
    args = parser.parse_args()

    prefix = ''
    f_prefix = '.'

    method_name = "VANILLALSTM"
    model_name = "LSTM"
    if args.gru:
        model_name = "GRU"

    plot_file_directory = 'test'

    # creation of paths
    plot_directory = os.path.join(f_prefix, 'plot', method_name, model_name,
                                  plot_file_directory)
    plot_file_name = get_all_file_names(plot_directory)

    print(plot_file_name)
    for file_index in range(len(plot_file_name)):
        file_name = plot_file_name[file_index]
        print("Now processing: ", file_name)

        file_path = os.path.join(plot_directory, file_name)

        try:
            f = open(file_path, 'rb')
        except FileNotFoundError:
            print("File not found: %s" % file_path)
            continue

        results = pickle.load(f)
        obs_length = np.array(results[0][1])
        pred_length = np.array(results[0][0])
        enthalpy_max = [408, 430, 251]
        enthalpy_min = [404, 422.5, 239]
        enthalpy_label = [
            'evaporator outlet enthalpy', 'compressor outlet enthalpy',
            'condenser outlet enthalpy'
        ]
        '''
        draw enthalpy prediction diagram
        '''
        expected_enthalpy_arr = np.array(results[0][2])
        predicted_enthalpy_arr = np.array(results[0][3])
        error_enthalpy = np.zeros((expected_enthalpy_arr.shape[0], 3))
        plt.figure(figsize=(10, 5))

        for i in range(expected_enthalpy_arr.shape[0]):
            for idx in range(3):
                expected_enthalpy = expected_enthalpy_arr[i, :, idx:idx + 1]
                predicted_enthalpy = predicted_enthalpy_arr[i, :, idx:idx + 1]
                # predicted_enthalpy[obs_length:] = filter(predicted_enthalpy[obs_length:])
                mean_obs_enthalpy = np.mean(expected_enthalpy[:obs_length])
                mean_expected_enthalpy = np.mean(
                    expected_enthalpy[obs_length:])
                mean_predicted_enthalpy = np.mean(
                    predicted_enthalpy[obs_length:])

                # draw plot
                plt.ylim(enthalpy_min[idx], enthalpy_max[idx])
                plt.plot(np.arange(0, obs_length * 2, 2),
                         expected_enthalpy[:obs_length],
                         color='green',
                         label="Observation data",
                         linestyle='-',
                         marker='.')
                plt.plot(np.arange(obs_length * 2,
                                   expected_enthalpy.shape[0] * 2, 2),
                         expected_enthalpy[obs_length:],
                         label="Expected " + enthalpy_label[idx],
                         linestyle='-',
                         marker='.')
                plt.plot(np.arange(obs_length * 2,
                                   expected_enthalpy.shape[0] * 2, 2),
                         predicted_enthalpy[obs_length:],
                         label="Predictive " + enthalpy_label[idx],
                         linestyle='-',
                         marker='+')
                plt.plot([0, obs_length * 2],
                         [mean_obs_enthalpy, mean_obs_enthalpy],
                         color='black',
                         label="Observation length mean " +
                         enthalpy_label[idx])
                plt.plot([obs_length * 2, expected_enthalpy.shape[0] * 2],
                         [mean_expected_enthalpy, mean_expected_enthalpy],
                         color='gray',
                         label="Expected mean " + enthalpy_label[idx])
                plt.plot([obs_length * 2, expected_enthalpy.shape[0] * 2],
                         [mean_predicted_enthalpy, mean_predicted_enthalpy],
                         color='red',
                         label="Predictive mean " + enthalpy_label[idx])

                plt.xlabel('Time(minutes)', fontsize=12)
                plt.ylabel('Enthalpy(kJ/kg)', fontsize=12)
                plt.xticks(fontsize=12)
                plt.yticks(fontsize=12)
                plt.legend()
                plt.savefig(plot_directory + "/" + str(i) + "H" +
                            str(idx + 1) + ".png")
                plt.clf()
                # plt.show()

                # compute error
                error = np.abs(mean_expected_enthalpy -
                               mean_predicted_enthalpy)
                error = np.around(error, decimals=4)
                error_enthalpy[i, idx] = error

        new_df = pd.DataFrame({
            'h1 err': error_enthalpy[:, 0],
            'h2 err': error_enthalpy[:, 1],
            'h3 err': error_enthalpy[:, 2]
        })
        new_df.to_csv(plot_directory + "/" + "enthalpy_error_minutes" + ".csv",
                      index=False)
        '''
        draw cop prediction diagram (minutes)
        '''
        error_cop = np.zeros((expected_enthalpy_arr.shape[0], 1))
        for i in range(expected_enthalpy_arr.shape[0]):
            expected_cop_arr = (expected_enthalpy_arr[i, :, 0:1] -
                                expected_enthalpy_arr[i, :, 2:3]) / (
                                    expected_enthalpy_arr[i, :, 1:2] -
                                    expected_enthalpy_arr[i, :, 0:1])
            predicted_cop_arr = (predicted_enthalpy_arr[i, :, 0:1] -
                                 predicted_enthalpy_arr[i, :, 2:3]) / (
                                     predicted_enthalpy_arr[i, :, 1:2] -
                                     predicted_enthalpy_arr[i, :, 0:1])
            # predicted_cop_arr[obs_length:] = filter(predicted_cop_arr[obs_length:])
            mean_obs_cop = np.mean(expected_cop_arr[:obs_length])
            mean_expected_cop = np.mean(expected_cop_arr[obs_length:])
            mean_predicted_cop = np.mean(predicted_cop_arr[obs_length:])

            plt.ylim(6, 10)
            plt.plot(np.arange(0, obs_length * 2, 2),
                     expected_cop_arr[:obs_length],
                     color='green',
                     label="Observation data",
                     linestyle='-',
                     marker='.')
            plt.plot(np.arange(obs_length * 2, expected_cop_arr.shape[0] * 2,
                               2),
                     expected_cop_arr[obs_length:],
                     label="Expected COP",
                     linestyle='-',
                     marker='.')
            plt.plot(np.arange(obs_length * 2, expected_cop_arr.shape[0] * 2,
                               2),
                     predicted_cop_arr[obs_length:],
                     label="Predictive COP",
                     linestyle='-',
                     marker='+')
            plt.plot([0, obs_length * 2], [mean_obs_cop, mean_obs_cop],
                     color='black',
                     label="Observation length mean COP")
            plt.plot([obs_length * 2, expected_cop_arr.shape[0] * 2],
                     [mean_expected_cop, mean_expected_cop],
                     color='gray',
                     label="Expected mean COP")
            plt.plot([obs_length * 2, expected_cop_arr.shape[0] * 2],
                     [mean_predicted_cop, mean_predicted_cop],
                     color='red',
                     label="Predictive mean COP")
            plt.xlabel('Time(minutes)', fontsize=12)
            plt.ylabel('COP', fontsize=12)
            plt.xticks(fontsize=12)
            plt.yticks(fontsize=12)
            plt.legend()

            plt.savefig(plot_directory + "/test" + str(i) + "_COP minutes.png")
            plt.clf()
            # plt.show()

            # compute error
            error = np.abs(mean_expected_cop - mean_predicted_cop)
            error = np.around(error, decimals=4)
            error_cop[i, 0] = error

        new_df = pd.DataFrame({'minutes err': error_cop[:, 0]})
        new_df.to_csv(plot_directory + "/" + "COP_error_minutes.csv",
                      index=False)
        '''
        hours
        '''
        expected_cop_day_arr = []
        predicted_cop_day_arr = []
        for i in range(expected_enthalpy_arr.shape[0]):
            expected_cop_arr = (expected_enthalpy_arr[i, :, 0:1] -
                                expected_enthalpy_arr[i, :, 2:3]) / (
                                    expected_enthalpy_arr[i, :, 1:2] -
                                    expected_enthalpy_arr[i, :, 0:1])
            predicted_cop_arr = (predicted_enthalpy_arr[i, :, 0:1] -
                                 predicted_enthalpy_arr[i, :, 2:3]) / (
                                     predicted_enthalpy_arr[i, :, 1:2] -
                                     predicted_enthalpy_arr[i, :, 0:1])
            # predicted_cop_arr[obs_length:] = filter(predicted_cop_arr[obs_length:])

            expected_cop_day = expected_cop_arr[obs_length:]
            predicted_cop_day = predicted_cop_arr[obs_length:]
            expected_cop_day = np.mean(expected_cop_day)
            predicted_cop_day = np.mean(predicted_cop_day)
            expected_cop_day_arr.append(expected_cop_day)
            predicted_cop_day_arr.append(predicted_cop_day)

        plt.ylim(6.5, 9)
        hour = pred_length / 30
        inveral = 8
        expected_cop_day_arr = np.array(expected_cop_day_arr)
        predicted_cop_day_arr = np.array(predicted_cop_day_arr)
        expected_cop_day_arr = np.reshape(expected_cop_day_arr,
                                          (expected_cop_day_arr.shape[0], 1))
        predicted_cop_day_arr = np.reshape(predicted_cop_day_arr,
                                           (predicted_cop_day_arr.shape[0], 1))
        plt.xticks(np.arange(0, expected_cop_day_arr.shape[0] * hour, hour))

        plt.plot(np.arange(0, expected_cop_day_arr.shape[0] * hour, hour),
                 expected_cop_day_arr,
                 label="Expected COP",
                 linestyle='--',
                 marker='+')
        plt.plot(np.arange(0, expected_cop_day_arr.shape[0] * hour, hour),
                 predicted_cop_day_arr,
                 label="Predictive COP",
                 linestyle='--',
                 marker='^')
        plt.xlabel('Time(hours)', fontsize=12)
        plt.ylabel('COP', fontsize=12)
        plt.xticks(fontsize=12)
        plt.yticks(fontsize=12)
        plt.legend()
        plt.savefig(plot_directory + "/" + str(hour) + "hours_COP" + ".png")
        plt.clf()
        # plt.show()

        # compute error
        error = np.abs(expected_cop_day_arr - predicted_cop_day_arr)
        error = np.around(error, decimals=4)
        print(expected_cop_day_arr.shape, predicted_cop_day_arr.shape,
              error.shape)

        new_df = pd.DataFrame({
            'real COP': expected_cop_day_arr[:, 0],
            'predict COP': predicted_cop_day_arr[:, 0],
            'err': error[:, 0]
        })
        new_df.to_csv(plot_directory + "/" + "COP_error_hours.csv",
                      index=False)