Skip to content
Snippets Groups Projects
Commit 1dff6aea authored by Christophe Le Bourlot's avatar Christophe Le Bourlot
Browse files

update gtStatus to work with the new configuration, change the reconstruction...

update gtStatus to work with the new configuration, change the reconstruction check algo for faster one... not tested in all the different situation, but should globally work
parent 6450f246
No related branches found
No related tags found
No related merge requests found
function gtStatus(completeCheck)
function gtStatus(completeCheck, checkOAR)
% GTSTATUS Checks the status of a dataset, show progress where possible
% and tell a user where one might have a problem.
% gtStatus(completeCheck)
......@@ -19,6 +19,9 @@ function gtStatus(completeCheck)
if ~exist('completeCheck','var') || isempty(completeCheck)
completeCheck = true;
end
if ~exist('checkOAR','var') || isempty(checkOAR)
checkOAR = false;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FIRST THINGS FIRST - PARAMETERS FILE
......@@ -41,80 +44,86 @@ problem_list{1}='List of possible problems:';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% WHERE ARE WE REGARDING OAR JOBS?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if exist('oar.log','file')
fid = fopen('oar.log');
elseif exist('OAR_log/oar.log','file')
fid = fopen(fullfile('OAR_log','oar.log'));
end
if ~isempty(fid)
oarlog=textscan(fid,'%s %s %d %s %s');
fclose(fid);
% most recent function name
names=oarlog{2};
lastoar_name=names{end};
arrays=oarlog{3};
lastoar_array=arrays(end);
[~,status]=unix(sprintf('oarstat --array %d',lastoar_array));
% read job numbers from this text - assume format doesn't change!
% get exit code with gtOarGetStats
ndx=160;
job_status='';
count=0;
query{1}='exit_code'; query{2}='state';
%this will be skipped,if status is an empty array
while ndx<length(status)
count=count+1;
job=str2double(status(ndx:ndx+6));
jobstat=gtOarGetStats(job,query);
exit_code=jobstat{1}.exit_code;
state=jobstat{1}.state;
if strcmp(state,'Waiting')
job_status(count)='W';
elseif strcmp(state,'Running')
job_status(count)='R';
elseif strcmp(state,'Terminated') && strcmpi(exit_code,'0 (0,0,0)')
job_status(count)='T';
elseif strcmp(state,'Terminated')
job_status(count)='E';
else
disp('could read this oar job...')
if checkOAR
if exist('oar.log','file')
fid = fopen('oar.log');
elseif exist('OAR_log/oar.log','file')
fid = fopen(fullfile('OAR_log','oar.log'));
end
if ~isempty(fid)
oarlog=textscan(fid,'%s %s %d %s %s');
fclose(fid);
% most recent function name
names=oarlog{2};
lastoar_name=names{end};
arrays=oarlog{3};
lastoar_array=arrays(end);
[~,status]=unix(sprintf('oarstat --array %d',lastoar_array));
% read job numbers from this text - assume format doesn't change!
% get exit code with gtOarGetStats
ndx=310+160;
ndx=312;
job_status='';
count=0;
query{1}='exit_code'; query{2}='state';
%this will be skipped,if status is an empty array
while ndx<length(status)
count=count+1;
% fprintf(['!!!' status(ndx:ndx+6) '!!!'])
job=str2double(status(ndx:ndx+6));
jobstat=gtOarGetStats(job,query);
exit_code=jobstat.exit_code;
%exit_code=jobstat{1}.exit_code;
state=jobstat.state;
if strcmp(state,'Waiting')
job_status(count)='W';
elseif strcmp(state,'Running')
job_status(count)='R';
elseif strcmp(state,'Terminated') && strcmpi(exit_code,'0 (0,0,0)')
job_status(count)='T';
elseif strcmp(state,'Terminated')
job_status(count)='E';
else
disp('could read this oar job...')
end
ndx=ndx+136;
end
%status variable can be empty, concanating from oarlog
launch_time=char(strcat(oarlog{4}(end),{' '},oarlog{5}(end)));
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
fprintf('Last OAR job was %s\n (array %d launched at %s)\n',lastoar_name,lastoar_array,launch_time)
% finished?
if all(job_status=='T' | job_status=='E')
fprintf(' All these jobs have finished\n')
end
% errors?
if all(job_status=='E')
fprintf(' All of these jobs show errors\n')
elseif any(job_status=='E')
fprintf(' Some of these jobs show errors\n')
end
% still running?
if all(job_status=='R')
fprintf(' All of these jobs are still running\n')
elseif any(job_status=='R')
fprintf(' Some of these jobs are still running\n')
end
% still waiting?
if all(job_status=='W')
fprintf(' All of these jobs are still waiting\n')
elseif any(job_status=='W')
fprintf(' Some of these jobs are still waiting\n')
end
ndx=ndx+81;
end
%status variable can be empty, concanating from oarlog
launch_time=char(strcat(oarlog{4}(end),{' '},oarlog{5}(end)));
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
fprintf('Last OAR job was %s\n (array %d launched at %s)\n',lastoar_name,lastoar_array,launch_time)
% finished?
if all(job_status=='T' | job_status=='E')
fprintf(' All these jobs have finished\n')
end
% errors?
if all(job_status=='E')
fprintf(' All of these jobs show errors\n')
elseif any(job_status=='E')
fprintf(' Some of these jobs show errors\n')
end
% still running?
if all(job_status=='R')
fprintf(' All of these jobs are still running\n')
elseif any(job_status=='R')
fprintf(' Some of these jobs are still running\n')
end
% still waiting?
if all(job_status=='W')
fprintf(' All of these jobs are still waiting\n')
elseif any(job_status=='W')
fprintf(' Some of these jobs are still waiting\n')
else
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
fprintf('No oar.log file found... \n')
fprintf(' Possible OAR problem? \n')
end
else
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
fprintf('No oar.log file found... \n')
fprintf(' Possible OAR problem? \n')
fprintf('OAR jobs bot checked!\n')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% WHAT IMAGES ARE PRESENT?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -467,7 +476,13 @@ end
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
for ii = 1 : nphases
pxsize = (parameters.labgeo.pixelsizeu+parameters.labgeo.pixelsizev)/2;
d=dir(sprintf('4_grains/phase_%02d/grain_*.mat',ii));
dd=dir(sprintf('4_grains/phase_%02d/grain_*.mat',ii));
d={};
for jj=1:length(dd)
if length(strfind(dd(jj).name, 'details'))<1
d{end+1}=dd(jj).name;
end
end
n_grains_mat(ii)=length(d);
if (n_grains(ii)==n_grains_mat(ii))
fprintf('Correct number (%d) of grain_%%04d.mat files found\n',n_grains_mat(ii));
......@@ -486,7 +501,8 @@ for ii = 1 : nphases
title = sprintf('Checking grain_####.mat files for phase %02d: ',ii);
gauge = GtGauge(n_grains(ii),title);
for jj = 1 : length(d)
b = load(sprintf('4_grains/phase_%02d/grain_%04d.mat',ii,jj),'center','completeness','difspotID','selected');
%b = load(sprintf('4_grains/phase_%02d/grain_%04d.mat',ii,jj),'center','completeness','difspotID','selected');
b = load(sprintf('4_grains/phase_%02d/grain_%04d.mat',ii,jj),'center','completeness','difspotID');
if all( single(b.center*pxsize) == single(phase.center(jj,:)*pxsize) )
check(1,jj) = true;
end
......@@ -536,10 +552,10 @@ for ii = 1 : nphases
disp(' ')
end
if any(~fsim_ok)
sfQuit(problem_list);
return
end
%if any(~fsim_ok)
% sfQuit(problem_list);
% return
%end
for ii = 1 : nphases
fprintf('Check forward simulation using gtFsimCheckMissingGrains for phase %02d:\n',ii)
......@@ -572,64 +588,77 @@ end % end for phaseid
% RECONSTRUCTION STATUS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for ii = 1 : nphases
title = sprintf('Check grain reconstructions for phase %02d: ',ii);
gauge = GtGauge(n_grains(ii),title);
check = true(n_grains(ii),2);
warning('off','all') % hide warning messages
d=dir(sprintf('4_grains/phase_%02d/grain*.mat',ii));
for jj = 1 : n_grains(ii)
gauge.incrementAndDisplay();
b=load(sprintf('4_grains/phase_%02d/%s',ii,d(jj).name),'vol','seg');
if ~isfield(b,'vol') || isempty(b.vol) || all(isequal(size(b.vol), [1 1]))
check(jj,1)=false;
end
if ~isfield(b,'seg') || isempty(b.seg) || all(isequal(size(b.seg), [1 1]))
check(jj,2)=false;
end
end
gauge.delete();
fprintf(' Reconstructed %d grains out of %d\n',sum(check(:,1)),n_grains(ii))
fprintf(' Segmented %d grains out of %d\n',sum(check(:,2)),n_grains(ii))
if any(~check(:,1))
disp(' Missing grain_####.mat:vol for ID(s):')
disp(find(~check(:,1))')
if length(find(~check(:,1))) == n_grains(ii)
problem_list{end+1}='Maybe reconstruction was not run yet...';
end
end
if any(~check(:,2))
disp(' Missing grain_####.mat:seg for ID(s):')
disp(find(~check(:,2))')
if length(find(~check(:,2))) == n_grains(ii)
problem_list{end+1}='Maybe grain segmentation was not run yet...';
end
end
if any(~check(:,[1 2]))
problem_list{end+1}=' Suggestion: run again gtSetupReconstruction() on a GPU machine';
rec_ok(ii) = false;
else
rec_ok(ii) = true;
end
% dates on these files
filedates=zeros(1,length(d));
for jj = 1 : length(d)
filedates(jj)=d(jj).datenum;
end
[~,min_ndx]=min(filedates);
[~,max_ndx]=max(filedates);
fprintf(' Earliest grain.mat file dates from %s\n',d(min_ndx).date)
fprintf(' Latest grain.mat file dates from %s\n',d(max_ndx).date)
warning('on','all') % hide warning messages
end
gtCheckAllReconstructedGrains;
% for ii = 1 : nphases
% title = sprintf('Check grain reconstructions for phase %02d: ',ii);
% gauge = GtGauge(n_grains(ii),title);
% check = true(n_grains(ii),3);
% warning('off','all') % hide warning messages
% d=dir(sprintf('4_grains/phase_%02d/grain_details_*.mat',ii));
% for jj = 1 : n_grains(ii)
% gauge.incrementAndDisplay();
% b=load(sprintf('4_grains/phase_%02d/%s',ii,d(jj).name),'VOL3D','SEG','ODF6D');
% if ~isfield(b,'VOL3D') || isempty(b.VOL3D) || all(isequal(size(b.VOL3D.intensity), [1 1]))
% check(jj,1)=false;
% end
% if ~isfield(b,'SEG') || isempty(b.SEG) || all(isequal(size(b.SEG.seg), [1 1]))
% check(jj,2)=false;
% end
% if ~isfield(b,'ODF6D') || isempty(b.ODF6D) || all(isequal(size(b.ODF6D.intensity), [1 1]))
% check(jj,3)=false;
% end
% end
% gauge.delete();
% fprintf(' Reconstructed VOL3D %d grains out of %d\n',sum(check(:,1)),n_grains(ii))
% fprintf(' Reconstructed ODF6D %d grains out of %d\n',sum(check(:,1)),n_grains(ii))
% fprintf(' Segmented %d grains out of %d\n',sum(check(:,2)),n_grains(ii))
% if any(~check(:,1))
% disp(' Missing grain_####.mat:VOL3D for ID(s):')
% disp(find(~check(:,1))')
% if length(find(~check(:,1))) == n_grains(ii)
% problem_list{end+1}='Maybe reconstruction was not run yet...';
% end
% end
% if any(~check(:,3))
% disp(' Missing grain_####.mat:ODF6D for ID(s):')
% disp(find(~check(:,3))')
% if length(find(~check(:,1))) == n_grains(ii)
% problem_list{end+1}='Maybe reconstruction was not run yet...';
% end
% end
% if any(~check(:,2))
% disp(' Missing grain_####.mat:SEG for ID(s):')
% disp(find(~check(:,2))')
% if length(find(~check(:,2))) == n_grains(ii)
% problem_list{end+1}='Maybe grain segmentation was not run yet...';
% end
% end
% if any(~check(:,[1 2 3]))
% problem_list{end+1}=' Suggestion: run again gtSetupReconstruction() on a GPU machine';
% rec_ok(ii) = false;
% else
% rec_ok(ii) = true;
% end
%
% % dates on these files
% filedates=zeros(1,length(d));
% for jj = 1 : length(d)
% filedates(jj)=d(jj).datenum;
% end
% [~,min_ndx]=min(filedates);
% [~,max_ndx]=max(filedates);
% fprintf(' Earliest grain.mat file dates from %s\n',d(min_ndx).date)
% fprintf(' Latest grain.mat file dates from %s\n',d(max_ndx).date)
%
% warning('on','all') % hide warning messages
% end
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
if any(~rec_ok)
sfQuit(problem_list);
return
end
%if any(~rec_ok)
% sfQuit(problem_list);
% return
%end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ASSEMBLED VOLUMES
......@@ -694,3 +723,98 @@ function sfQuit(problem_list)
end
end
end
function [reconstructed] = gtReconstructedGrains(algo, phase)
if (~exist('algo', 'var'))
algo = 'ODF6D';
end
if (~exist('phase', 'var'))
phase = 1;
end
if (~strcmp(algo,'ODF6D') && ~strcmp(algo,'VOL3D') && ~strcmp(algo,'SEG'))
algo = 'ODF6D';
end
sample = GtSample.loadFromFile();
num_grains = sample.phases{1}.getNumberOfGrains();
reconstructed = false(num_grains, 1);
title = sprintf(' - check: phase %02d, reconstructions (% 5s) -> ', phase, algo);
gauge = GtGauge(num_grains, title);
for ii = 1:num_grains
gauge.incrementAndDisplay();
fid = matfile(sprintf('4_grains/phase_%02d/grain_details_%04d.mat', phase, ii));
reconstructed(ii) = length( who(fid, algo));
end
gauge.delete();
end
function gtCheckAllReconstructedGrains(wd)
currentDir = pwd;
if (exist('wd', 'var'))
cd(wd)
end
pluriel = {'s', ''};
sample = GtSample.loadFromFile();
parameters = gtLoadParameters();
ech_name = parameters.acq.name;
num_phases = length(sample.phases);
for i=1:num_phases
phases_names{i} = sample.phases{i}.phaseName;
phases_nbgrains{i} = sample.phases{i}.getNumberOfGrains();
end
fprintf('DCT sample %s ', ech_name)
fprintf('(%d phase%s)\n', num_phases, pluriel{2-(num_phases>1)});
for i=1:num_phases
phases_names{i} = sample.phases{i}.phaseName;
phases_nbgrains{i} = sample.phases{i}.getNumberOfGrains();
phases_reconstructed_VOL3D{i} = sum(gtReconstructedGrains('VOL3D', i));
phases_reconstructed_ODF6D{i} = sum(gtReconstructedGrains('ODF6D', i));
phases_reconstructed_SEG{i} = sum(gtReconstructedGrains('SEG', i));
fprintf(' * %s : %d grains \n', phases_names{i}, phases_nbgrains{i})
fprintf(' reconstruction\n')
fprintf(' 3D % 4d/% 4d grains \n', phases_reconstructed_VOL3D{i}, phases_nbgrains{i})
fprintf(' 6D % 4d/% 4d grains \n', phases_reconstructed_ODF6D{i}, phases_nbgrains{i})
fprintf(' SEG % 4d/% 4d grains \n', phases_reconstructed_SEG{i}, phases_nbgrains{i})
if any(~phases_reconstructed_VOL3D{i})
disp(' Missing grain_####.mat:VOL3D for ID(s):')
disp(find(~phases_reconstructed_VOL3D{i})')
if length(find(~phases_reconstructed_VOL3D{i})) == phase_nbgrains{i}
disp('Maybe reconstruction was not run yet...');
end
end
if any(~phases_reconstructed_ODF6D{i})
disp(' Missing grain_####.mat:ODF6D for ID(s):')
disp(find(~phases_reconstructed_ODF6D{i})')
if length(find(~phases_reconstructed_ODF6D{i})) == phase_nbgrains{i}
disp('Maybe reconstruction was not run yet...');
end
end
if any(~phases_reconstructed_SEG{i})
disp(' Missing grain_####.mat:SEG for ID(s):')
disp(find(~phases_reconstructed_SEG{i})')
if length(find(~phases_reconstructed_SEG{i})) == phase_nbgrains{i}
disp('Maybe reconstruction was not run yet...');
end
end
end
cd(currentDir);
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment