Skip to content

Commit

Permalink
Merge branch 'master' into eurostag_filter_invalid_contingencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvlecl committed Nov 16, 2018
2 parents e072e93 + ac721e3 commit 95a991f
Show file tree
Hide file tree
Showing 19 changed files with 7,220 additions and 7,220 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
----------------------
README
----------------------
I. Version
----------
Version V0
II. File list
-------------
MAIN_Import_PostCont.m Main file, which should be executed.
READ_VARIABLES.m Function to filter the branches
READ_WORKFLOW_STATES_SN.m Function to read the post-contingency load-flow FO states
READ_WORKFLOW_STATES_FO.m Function to read the post-contingency load-flow SN states
README This file
III. Steps to execute the MATLAB script
--------------------------------------
To execute the Matlab script, the following steps must be performed:
1. Open the MATLAB file “MAIN_Import_PostCont.m”
2. Inside the code, the following configuration must be specified:
• Path for the FO folder (in “path_FO =”);
• Path for the SN folder (in “path_SN =”);
• Path for the CE folder with the “lienPostesCE.csv” CE file (in “CE_path=”).
• Path for the output data (in “out_path =”), where the output files are going to be stored.
• The “transmission area” (in “CE =“) to only include the transmission line records with the specified “transmission area”. If not specified, this filter is not performed and therefore all the line records are considered.
• The nominal voltage (in “Voltage = “) to only include the transmission line records with the specified nominal voltages. If not specified, no voltage filter is performed.
----------------------
README
----------------------

I. Version
----------
Version V0


II. File list
-------------

MAIN_Import_PostCont.m Main file, which should be executed.
READ_VARIABLES.m Function to filter the branches
READ_WORKFLOW_STATES_SN.m Function to read the post-contingency load-flow FO states
READ_WORKFLOW_STATES_FO.m Function to read the post-contingency load-flow SN states
README This file

III. Steps to execute the MATLAB script
--------------------------------------

To execute the Matlab script, the following steps must be performed:
1. Open the MATLAB file “MAIN_Import_PostCont.m”
2. Inside the code, the following configuration must be specified:
• Path for the FO folder (in “path_FO =”);
• Path for the SN folder (in “path_SN =”);
• Path for the CE folder with the “lienPostesCE.csv” CE file (in “CE_path=”).
• Path for the output data (in “out_path =”), where the output files are going to be stored.
• The “transmission area” (in “CE =“) to only include the transmission line records with the specified “transmission area”. If not specified, this filter is not performed and therefore all the line records are considered.
• The nominal voltage (in “Voltage = “) to only include the transmission line records with the specified nominal voltages. If not specified, no voltage filter is performed.
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Copyright (c) 2018, RTE and INESC TEC (http://www.rte-france.com and %%
%% https://www.inesctec.pt) %%
%% This Source Code Form is subject to the terms of the Mozilla Public %%
%% License, v. 2.0. If a copy of the MPL was not distributed with this %%
%% file, You can obtain one at http://mozilla.org/MPL/2.0/. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Author: José Meirinhos jlmm@inesctec.pt %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [vars] = READ_VARIABLES(CE , filename)

fid = fopen( filename ) ; % the original file
new_filename = strcat( 'tmp_', filename );
fidd = fopen( new_filename, 'w' ) ; % the new file
while ~feof( fid ) % reads the original till last line
tline = fgets( fid );
if isempty( strfind( tline, 'WARNING' ) )
fprintf( fidd, tline ) ;
end
end
fclose all;
data = readtable( new_filename, 'Delimiter', ';' );

if CE ~= false % If a CE was specified
% idx = find(contains(data{:,2}, CE)); %Find CE

% R2015b version
idx = find(~cellfun(@isempty,strfind(data{:,2}, CE)));
vars = (data {idx,1}) ; % Save variables
else
% vars = [(data {:,2}) (data {:,3})] ; % Save variables
% CE_data = data;
return;
end

% vars = (data {:,1}); % Save variables

% for i=1:size(vars,1)

delete( new_filename ); % delete new file
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Copyright (c) 2018, RTE and INESC TEC (http://www.rte-france.com and %%
%% https://www.inesctec.pt) %%
%% This Source Code Form is subject to the terms of the Mozilla Public %%
%% License, v. 2.0. If a copy of the MPL was not distributed with this %%
%% file, You can obtain one at http://mozilla.org/MPL/2.0/. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Author: José Meirinhos jlmm@inesctec.pt %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [vars] = READ_VARIABLES(CE , filename)

fid = fopen( filename ) ; % the original file
new_filename = strcat( 'tmp_', filename );
fidd = fopen( new_filename, 'w' ) ; % the new file
while ~feof( fid ) % reads the original till last line
tline = fgets( fid );
if isempty( strfind( tline, 'WARNING' ) )
fprintf( fidd, tline ) ;
end
end
fclose all;
data = readtable( new_filename, 'Delimiter', ';' );

if CE ~= false % If a CE was specified
% idx = find(contains(data{:,2}, CE)); %Find CE

% R2015b version
idx = find(~cellfun(@isempty,strfind(data{:,2}, CE)));
vars = (data {idx,1}) ; % Save variables
else
% vars = [(data {:,2}) (data {:,3})] ; % Save variables
% CE_data = data;
return;
end

% vars = (data {:,1}); % Save variables

% for i=1:size(vars,1)

delete( new_filename ); % delete new file
end
Original file line number Diff line number Diff line change
@@ -1,109 +1,109 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Copyright (c) 2018, RTE and INESC TEC (http://www.rte-france.com and %%
%% https://www.inesctec.pt) %%
%% This Source Code Form is subject to the terms of the Mozilla Public %%
%% License, v. 2.0. If a copy of the MPL was not distributed with this %%
%% file, You can obtain one at http://mozilla.org/MPL/2.0/. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Author: José Meirinhos jlmm@inesctec.pt %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [ header_vars, header, data_vars ] = READ_WORKFLOW_STATES_FO(vars, filename )
% function [ header_vars, state_id, data_vars ] = READ_WORKFLOW_STATES(vars, filename )

% Read data
% filename = strcat(workflow,file); % Tel que fourni par le workflow
fid = fopen(filename);

header = fgetl(fid);
header = strsplit(header,';');
fclose(fid);

indexColumnsToRead = [];

% Find state column
indexCol_state = find(ismember(header,'state'));
indexColumnsToRead = [indexColumnsToRead indexCol_state];

% Write header to file
% fid = fopen('header.csv','w');
% fprintf(fid,'%s\n', header{1,:});
% fclose(fid);

for n = 1:numel(vars)

indexCol = find(ismember(header,vars{n}));


if indexCol > 0
indexColumnsToRead = [indexColumnsToRead indexCol];
else
disp(['Variable not found: ' vars{n}]);
end
end
indexColumnsToRead = sort(indexColumnsToRead);

% 1st aproach - faster

cellFormat = repmat({'%*s '},1,length(header));
cellFormat(indexColumnsToRead) = {'%s '};
% cellFormat(2) = {'%s '}; % column of the state ID
formatString = cell2mat(cellFormat);

fid = fopen(filename);
headerToRead = textscan(fid,formatString,1,'Delimiter',';');
dataRead = textscan(fid,formatString,'Delimiter',';','HeaderLines',1);

% headerToRead = header([2 unique(indexColumnsToRead)]);
% dataRead = textscan(fid,formatString,'Delimiter',';');
fclose(fid);

% data = cat(2, cellfun(@str2num,dataRead{1,1}), cellfun(@str2num,dataRead{1,2:end}));
% data_ordered = sortrows(data,1);
%
% state_id = data_ordered(:,1);
% data_vars = data_ordered(:,2:end);

% stateRaw = dataRead(1);
% dataRaw = dataRead(2:end);
% dataRaw = dataRead(1:end);

nbVariables = length(dataRead);
nbValues = length(dataRead{1});

data_vars=cell(nbValues,nbVariables);
%TODO : avoid for*for with cellfun/cell2mat
for k = 1:nbVariables
for ind = 1:(nbValues)
if ~isempty(dataRead{1,k}{ind,1})
data_vars{ind,k} = dataRead{1,k}{ind,1};
end
end
end

% state_id=zeros(nbValues,1);
% %TODO : avoid for*for with cellfun/cell2mat
% for ind = 1:(nbValues)
% if ~isempty(str2num(stateRaw{1,1}{ind,1}))
% state_id(ind,1) = str2num(stateRaw{1,1}{ind,1});
% end
% end

% For the Header
header_vars = cell(1, length(headerToRead));
for i = 1:length(headerToRead)
% header_vars{1,i} = headerToRead{1,i};
header_vars{1,i} = headerToRead{1,i}{1,1};
end

% 2nd aproach - slower

% tmp = readtable( filename, 'Delimiter', ';' );
% state_id = tmp{ :, 2 };
% data_vars = tmp{ :, indexColumnsToRead };

% if nbValues ~= (length(unique(data_vars(:,2))) * 50)
% fprintf('Number of states: %i\n',nbValues); % Print the number of states
% end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Copyright (c) 2018, RTE and INESC TEC (http://www.rte-france.com and %%
%% https://www.inesctec.pt) %%
%% This Source Code Form is subject to the terms of the Mozilla Public %%
%% License, v. 2.0. If a copy of the MPL was not distributed with this %%
%% file, You can obtain one at http://mozilla.org/MPL/2.0/. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Author: José Meirinhos jlmm@inesctec.pt %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [ header_vars, header, data_vars ] = READ_WORKFLOW_STATES_FO(vars, filename )
% function [ header_vars, state_id, data_vars ] = READ_WORKFLOW_STATES(vars, filename )

% Read data
% filename = strcat(workflow,file); % Tel que fourni par le workflow
fid = fopen(filename);

header = fgetl(fid);
header = strsplit(header,';');
fclose(fid);

indexColumnsToRead = [];

% Find state column
indexCol_state = find(ismember(header,'state'));
indexColumnsToRead = [indexColumnsToRead indexCol_state];

% Write header to file
% fid = fopen('header.csv','w');
% fprintf(fid,'%s\n', header{1,:});
% fclose(fid);

for n = 1:numel(vars)

indexCol = find(ismember(header,vars{n}));


if indexCol > 0
indexColumnsToRead = [indexColumnsToRead indexCol];
else
disp(['Variable not found: ' vars{n}]);
end
end
indexColumnsToRead = sort(indexColumnsToRead);

% 1st aproach - faster

cellFormat = repmat({'%*s '},1,length(header));
cellFormat(indexColumnsToRead) = {'%s '};
% cellFormat(2) = {'%s '}; % column of the state ID
formatString = cell2mat(cellFormat);

fid = fopen(filename);
headerToRead = textscan(fid,formatString,1,'Delimiter',';');
dataRead = textscan(fid,formatString,'Delimiter',';','HeaderLines',1);

% headerToRead = header([2 unique(indexColumnsToRead)]);
% dataRead = textscan(fid,formatString,'Delimiter',';');
fclose(fid);

% data = cat(2, cellfun(@str2num,dataRead{1,1}), cellfun(@str2num,dataRead{1,2:end}));
% data_ordered = sortrows(data,1);
%
% state_id = data_ordered(:,1);
% data_vars = data_ordered(:,2:end);

% stateRaw = dataRead(1);
% dataRaw = dataRead(2:end);
% dataRaw = dataRead(1:end);

nbVariables = length(dataRead);
nbValues = length(dataRead{1});

data_vars=cell(nbValues,nbVariables);
%TODO : avoid for*for with cellfun/cell2mat
for k = 1:nbVariables
for ind = 1:(nbValues)
if ~isempty(dataRead{1,k}{ind,1})
data_vars{ind,k} = dataRead{1,k}{ind,1};
end
end
end

% state_id=zeros(nbValues,1);
% %TODO : avoid for*for with cellfun/cell2mat
% for ind = 1:(nbValues)
% if ~isempty(str2num(stateRaw{1,1}{ind,1}))
% state_id(ind,1) = str2num(stateRaw{1,1}{ind,1});
% end
% end

% For the Header
header_vars = cell(1, length(headerToRead));
for i = 1:length(headerToRead)
% header_vars{1,i} = headerToRead{1,i};
header_vars{1,i} = headerToRead{1,i}{1,1};
end

% 2nd aproach - slower

% tmp = readtable( filename, 'Delimiter', ';' );
% state_id = tmp{ :, 2 };
% data_vars = tmp{ :, indexColumnsToRead };

% if nbValues ~= (length(unique(data_vars(:,2))) * 50)
% fprintf('Number of states: %i\n',nbValues); % Print the number of states
% end

end
Loading

0 comments on commit 95a991f

Please sign in to comment.