% define validation sets

clear all

pwd_dir=pwd;

station_list={'frn','ott','iqa',};
root = ['~/geospace_work/'];

for station = station_list
 

 cd([root char(station)])
 disp(['Processing ' char(station)])

 filename = [char(station) '_all_features.mat'];
 
 load(filename)
 T=Table_features;
 
 Time_interval=T.Time;
 
 filename = [char(station) '_geospace_CCMC.mat'];

 load(filename);
 
 [dum, ia, ib]= intersect(T_SWPC.Time, T.Time);
 
 T.("log10(maxBx-minBx)_geo")(ib)=T_SWPC.("log10(maxBx-minBx)_geo")(ia);
 T.("log10(maxBy-minBy)_geo")(ib)=T_SWPC.("log10(maxBy-minBy)_geo")(ia);
 T.("maxdBdt_geo")(ib)=T_SWPC.("maxdBdt_geo")(ia);
 feat = [1 3:5 7 10 11 16];

 T=T(:,feat);
 T_train=[];T_test=[];
 
 [i,j]=find(isnan(table2array(T(:,2:end))));T(i,:)=[];
 
 f=find(T.Time.Year==2003);
 T_train=[T_train;T(f,:)]; T(f,:)=[];
 f=find(T.Time.Year==2001);
 T_train=[T_train;T(f,:)]; T(f,:)=[];
 f=find(T.Time.Year==2005);
 T_train=[T_train;T(f,:)]; T(f,:)=[];
 f=find(T.Time>='2019-01-01');
 T_train=[T_train;T(f,:)]; T(f,:)=[];
 
 [i,j]=find(isinf(table2array(T_train(:,2:end))));T_train(i,:)=[];

 
 T_test=T; clear T
 [i,j]=find(isinf(table2array(T_test(:,2:end))));T_test(i,:)=[];
 
 T_test_geo=[T_test(:,1) T_test(:,4) T_test(:,end)];
 T_test.maxdBdt_geo=[];
 T_train.maxdBdt_geo=[];
 
 filename = [char(station) '_train_test_sets.mat']
 save(filename,'T_train','T_test','T_test_geo');

clearvars  -except station station_list root pwd_dir

end

cd(pwd_dir)