
IMPORTANT: Please Do not distribute this code.

Requirements: 
import os 
import sys 
import numpy as np 
import cv2 
import matplotlib.pyplot as plt
import GPy
from copy import deepcopy
from scipy.io import loadmat
import pickle
import time 
import pdb

torch version 1.6.0 - to run the FNO code 

#######################################################################################################################################
Our Models: 

To run experiments with our model first cd into the folder "src/new_src/ipython_notebooks". 
From this folder run the python command "python multiple_tests.py"
Running this command uses our method to train our model using a specified part of the video sequence and then predict on another part of that same sequence. 

Modifiable Parameters: Change these parameters if desired in the section labeled "Modifiable Parameters"
	- num_predictions: the number of video sequences to predict on 
	- prediction_steps: the number of steps to predict into the future
	- num_training_imgs: the number of images to use for training data 
	- start_point = 0 # Part of the sequence to evaluate for training and testing - keep as 0 
	
	- nvstokes_filename: change this to the name of the file containing the dataset, options include: 
		- "../../../fourier_neural_operator_paper/dataset/ns_data_32by32_visc1e-3_1e-4dt_200T_50samples_2.mat"
		- "../../../fourier_neural_operator_paper/dataset/ns_data_32by32_visc1e-3_1e-4dt_200T_50samples.mat"
	- multiple_seq_in_file = True # boolean: if True: indicates that there are multiple sequences stored within a single file, if False: indicates each file only stores one data sequence

	- start_prediction_seq = 0: of the sequences in the file which sequence to start predictions on  
	- save_dirname = "50_comparison_10train_trainstride(2,2)_WAYLATER" # name of the directory to create and store all the results in 
	- save_filename_suffix_start = "10train_32by32batchtest_visc1e-3_50test_WAYLATER"#"32by32batchtest_visc1e-3_50test" # starting suffix for all the files to be saved

	
	start_test_after_train = True # boolean: when true you start the test sequence right after the training sequence when false you have to specify the index that the test sequence starts at. 
	if not start_test_after_train: 
	    - test_start_img_num = 75 #  index of the sequence that will be the first image predicted in the predictive rollout 

Method parameters: present right below the section for modifiable parameters - can be used to test our method with different parameters
	# patchify parameters
	- img_dim = (32, 32) : dimension of the image
	- patch_dim = (15, 15): (p,p) dimension of the patches
	- patch_border = (7,7): (b,b) patch border
	- img_padlen = (0, 0): indicates that you don't pad the image
	- img_padtype = 'wrap': handle the edge patches using the wrapping method
	- stride = (2,2): stride in x and y dimensions with which to sample the training data. 


What running the above does: 
This file takes the dataset in 'nvstokes_filename'. The dataset files have multiple video sequences in them. We use our method to perform video prediction on these 
video sequences. We predict on 'num_predictions' video sequences starting at the video sequence indexed 'start_prediction_seq'. For each video sequence we use the 
first 'num_training_imgs' to train our model and then predict 'prediction_steps' timesteps in the future. This prediction is started right after the last training 
image if 'start_test_after_train' is set to True. If it is set to False you need to specify 'test_start_img_num' which denotes the index of the first image that 
will be predicted by our model. All the results are stored in the file structure discussed in the outputs section below. 

Outputs: 
Running this code creates the following folder structure: 
	- multiple_errors: empty directory 
	- multiple_gifs: directory containing: 
		- gifs showing the video predictions for each predicted sequence
		- .png files showing the relative error of each video prediction 
	- multiple_img_npys: 
		- .npy files containing the mean predictions for each predicted sequence
		- .npy files containing the variance predictions for each predicted sequence
	- multiple_mean_stds: empty directory 
	- all_parameters.pkl: pickle file containing dictionary of the used parameters
	- all_parameters.txt: readable text version of the parameters that are used. 

	Terminal output: progress bars and print outs show each prediction and its progress


The above parameters can be modified to run the experiments shown in the paper. The outputted data can be displayed to show the results generated 
in the paper. The only images saved directly is a gif of the predicted mean image, predicted variance image, corresponding ground truth, difference
image, mean standard deviations off and relative error graph. and a separate image of the relative error graph. 


#######################################################################################################################################
#######################################################################################################################################
FNO-2D-Time: 

We made modifications to the code presented in the paper "FOURIER NEURAL OPERATOR FOR PARAMETRIC PARTIAL DIFFERENTIAL EQUATIONS". 
This is done to train the model on a similar number of data points to our code using the method discussed in the appendix of the paper. 

To run this code cd into "cd fourier_neural_operator_paper/prediction_src/src/"
Then run the python command "python multiple_tests_FNO_2d_time.py"

Modifiable Parameters: Change these parameters if desired in the section labeled "Modifiable Parameters"

	- num_predictions: the number of sequences you want to do the prediction on  
	- prediction_steps: how many steps in the future to predict
	- num_training_imgs: number of training images to use

	- nvstokes_filename: filename containing the dataset: 
		- "../../dataset/ns_data_32by32_visc1e-3_1e-4dt_200T_50samples_2.mat"
		- "../../dataset/ns_data_32by32_visc1e-3_1e-4dt_200T_50samples.mat"
	- multiple_seq_in_file = True # boolean: if True: indicates that there are multiple sequences stored within a single file, if False: indicates each file only stores one data sequence - Leave True

	# sequence to start and end predicting on 
	- start_prediction_seq = [0] : the first sequence to start prediction on 

	- save_dirname = "50_comparison_fno_2d_time_20epochs_2" # name of the directory to create and store all the results in 
	- save_filename_suffix_start = "fno2d_time_10train_32by32batchtest_visc1e-3_50test_2"#"32by32batchtest_visc1e-3_50test" # starting suffix for all the files to be saved

	- GLOBAL_EPOCHS = 20 # Number of epochs to train 

What running the above does: 
This file takes the dataset in 'nvstokes_filename'. The dataset files have multiple video sequences in them. We use our method to perform video prediction on these 
video sequences. We predict on 'num_predictions' video sequences starting at the video sequence indexed 'start_prediction_seq'. For each video sequence we use the 
first 'num_training_imgs' to train our model. We train our model for "GLOBAL_EPOCHS" number of epochs. We then predict 'prediction_steps' timesteps in the future. 
This prediction is started right after the last training image. All the results are stored in the file structure discussed in the outputs section below. 

Outputs: 
Running this code creates the following folder structure: 
	- multiple_gifs: directory containing: 
		- gifs showing the video predictions for each predicted sequence
		- .png files showing the relative error of each video prediction 
	- multiple_img_npys: 
		- .npy files containing the mean predictions for each predicted sequence
		- .npy files containing the variance predictions for each predicted sequence
	- all_parameters.pkl: pickle file containing dictionary of the used parameters
	- all_parameters.txt: readable text version of the parameters that are used. 

	Terminal output: shows the status on the training, prediction and saving 

These parameters can be modified to run different experiments like the ones shown in the paper. The outputted data can be displayed to show the results 
generated in the paper. The only images saved directly are the relative error graphs. The gif is also saved directly and displays the ground truth image
the predicted image, the error image and the relative error graph. 

#######################################################################################################################################
#######################################################################################################################################
FNO-3D:  

We made modifications to the code presented in the paper "FOURIER NEURAL OPERATOR FOR PARAMETRIC PARTIAL DIFFERENTIAL EQUATIONS". 
This is done to train the model on a similar number of data points to our code using the method discussed in the appendix of the paper. 

To run this code cd into "cd fourier_neural_operator_paper/prediction_src/src/"
Then run the python command "python multiple_tests_FNO_3d.py"

NOTE: Everything following this is the same as the FNO-2D-time example discussed above. 
Modifiable Parameters: Change these parameters if desired in the section labeled "Modifiable Parameters"

	- num_predictions: the number of sequences you want to do the prediction on  
	- prediction_steps: how many steps in the future to predict
	- num_training_imgs: number of training images to use

	- nvstokes_filename: filename containing the dataset: 
		- "../../dataset/ns_data_32by32_visc1e-3_1e-4dt_200T_50samples_2.mat"
		- "../../dataset/ns_data_32by32_visc1e-3_1e-4dt_200T_50samples.mat"
	- multiple_seq_in_file = True # boolean: if True: indicates that there are multiple sequences stored within a single file, if False: indicates each file only stores one data sequence - Leave True

	# sequence to start and end predicting on 
	- start_prediction_seq = [0] : the first sequence to start prediction on 

	- save_dirname = "50_comparison_fno_3d_20epochs_ntrain2_2" # name of the directory to create and store all the results in 
	- save_filename_suffix_start = "fno3d_10train_32by32batchtest_visc1e-3_50test_2"#"32by32batchtest_visc1e-3_50test" # starting suffix for all the files to be saved

	- GLOBAL_EPOCHS = 20 # Number of epochs to train 

What running the above does: 
This file takes the dataset in 'nvstokes_filename'. The dataset files have multiple video sequences in them. We use our method to perform video prediction on these 
video sequences. We predict on 'num_predictions' video sequences starting at the video sequence indexed 'start_prediction_seq'. For each video sequence we use the 
first 'num_training_imgs' to train our model. We train our model for "GLOBAL_EPOCHS" number of epochs. We then predict 'prediction_steps' timesteps in the future. 
This prediction is started right after the last training image. All the results are stored in the file structure discussed in the outputs section below. 

Outputs: 
Running this code creates the following folder structure: 
	- multiple_gifs: directory containing: 
		- gifs showing the video predictions for each predicted sequence
		- .png files showing the relative error of each video prediction 
	- multiple_img_npys: 
		- .npy files containing the mean predictions for each predicted sequence
		- .npy files containing the variance predictions for each predicted sequence
	- all_parameters.pkl: pickle file containing dictionary of the used parameters
	- all_parameters.txt: readable text version of the parameters that are used. 

	Terminal output: shows the status on the training, prediction and saving 

These parameters can be modified to run different experiments like the ones shown in the paper. The outputted data can be displayed to show the results 
generated in the paper. The only images saved directly are the relative error graphs. The gif is also saved directly and displays the ground truth image
the predicted image, the error image and the relative error graph. 


#######################################################################################################################################