Skip to content
Snippets Groups Projects
Commit 1f17e496 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Re-introduced Wolfgang's last feature for launching clusters on OAR (to-be-tested)

parent 969bb255
No related branches found
No related tags found
No related merge requests found
function cluster = gtLoadCluster(phase_id, grain_ids, varargin)
% GTLOADCLUSTER load the projection input of a grain cluster
% cl = function cluster = gtLoadCluster(phase_id, cl_or_gr_ids, varargin)
% INPUT:
% phaseID = <int> phase ID
% grain_ids = <int> either the cluster_id (->sample) or
% list of grain_ids composing the
% cluster
%
% OPTIONAL INPUT (p/v pairs):
% fields = <string> only load specific fields from
% cluster structure ('ODF6D', 'SEG')
% parameters = <struct> for security (make sure to load from right directory)
%
conf = struct('fields', {{}}, 'parameters', {[]});
conf = parse_pv_pairs(conf, varargin);
......
function cluster_rec = gtLoadClusterRec(phase_id, grain_ids, varargin)
% GTLOADCLUSTERREC load the 6D reconstruction output of a grain cluster
% cl = function cluster_rec = gtLoadClusterRec(phase_id, cl_or_gr_ids, varargin)
% INPUT:
% phaseID = <int> phase ID
% grain_ids = <int> either the cluster_id (->sample) or
% list of grain_ids composing the
% cluster
%
% OPTIONAL INPUT (p/v pairs):
% fields = <string> only load specific fields from
% cluster structure ('ODF6D', 'SEG')
% parameters = <struct> for security (make sure to load from right directory)
%
conf = struct('fields', {{}}, 'parameters', {[]});
conf = parse_pv_pairs(conf, varargin);
......
function gtReconstructClusters(first, last, workingdirectory, phase_id, parameters, varargin)
% gtReconstructClusters 6D cluster reconstructions on a GPU machine
% gtReconstructClusters(first, last, workingdirectory, phaseID, [parameters], varargin)
% -------------------------------------------------------
if (~gtCheckGpu())
error([mfilename ':no_GPU'], ...
'You should submit this job on a GPU machine ! Exiting...');
end
currentDir = pwd;
cd(workingdirectory);
if (isdeployed)
global GT_DB %#ok<NUSED,TLEV>
global GT_MATLAB_HOME %#ok<NUSED,TLEV>
load('workspaceGlobal.mat');
first = str2double(first);
last = str2double(last);
phase_id = str2double(phase_id);
end
if (~exist('parameters','var') || isempty(parameters))
parameters = gtLoadParameters();
end
samplefile = fullfile(parameters.acq.dir, '4_grains', 'sample.mat');
sample = GtSample.loadFromFile(samplefile);
conf = struct( ...
'list', [], ...
'ospace_resolution', [] );
if (isempty(conf.list))
cluster_list = first:last;
else
cluster_list = conf.list;
% in case the code is deployed, we have to convert to strings
if (ischar(cluster_list))
cluster_list = sscanf(cluster_list, '%d');
end
end
num_clusters = numel(cluster_list);
for ii_cl = 1:num_clusters
cl_id = cluster_list(ii_cl);
cl_info = sample.phases{phase_id}.clusters(cl_id);
if (~cl_info.active)
warning([mfilename ':wrong_cluster'], ...
'Cluster from phase %d, and grain ids:%s, will be reconstructed but it is not active', ...
phase_id, sprintf(' %d', cl_info.included_ids))
end
cl = gtLoadCluster(phase_id, cl_info.included_ids);
gtReconstructGrainCluster(cl, phase_id, parameters, ...
'ospace_resolution', conf.ospace_resolution);
end
cd(currentDir);
end
function gtSetupReconstruction(phaseID, list)
function gtSetupReconstruction(phase_id, varargin)
% GTSETUPRECONSTRUCTION Simple helper function to launch reconstruction and segmentation of
% absorption volume - as well as reconstruction and segmentation of grain volumes
%
% gtSetupReconstruction(phaseID, list)
% gtSetupReconstruction(phaseID, varargin)
% ------------------------------
%
% INPUT:
% phaseID = number of the phase <double> {1}
% list = vector of grainids, default value is {[1: num_grains]}
%
% OPTIONAL INPUT:
% grain_ids = vector of grain_ids, default value is {[1: num_grains]}
% cluster_ids = vector of cluster_ids, default value is {[1: num_clusters]}
% 'is_cluster
% Version 005 12-10-2016 by W. Ludwig
% Add possibility to launch grain-cluster reconstructions
% Version 004 25-05-2016 by W. Ludwig
% Add possibility to specify a list of grainids - which will be
% handled by OAR
......@@ -24,22 +29,25 @@ function gtSetupReconstruction(phaseID, list)
GPU_OK = gtCheckGpu();
conf = struct('grain_ids', [], 'cluster_ids', []);
conf = parse_pv_pairs(conf, varargin);
if (~GPU_OK)
disp('Not on a GPU machine, you won''t be able to reconstruct localy!');
disp('from rnice: oarsub -I -l "walltime=hh:mm:ss" -q gpu');
fprintf('\nSubmitting to OAR.\n')
end
if ~exist('phaseID','var') || isempty(phaseID)
phaseID = 1;
if (~exist('phaseID','var') || isempty(phase_id))
phase_id = 1;
end
check = inputwdefault('Do you want to recompile the function ''gtChangeThreshold3D''? [y/n]', 'n');
if strcmpi(check,'y')
if (strcmpi(check,'y'))
gtExternalCompileFunctions('gtChangeThreshold3D');
end
check = inputwdefault('Do you want to recompile the function ''gtReconstructGrains''? [y/n]', 'n');
if strcmpi(check,'y')
if (strcmpi(check,'y'))
gtExternalCompileFunctions('gtReconstructGrains');
end
......@@ -57,12 +65,12 @@ gtSaveParameters(parameters);
nof_phases = numel(parameters.cryst);
if (nof_phases > 1)
phaseID = inputwdefaultnumeric('Enter phaseID', num2str(1));
if (nof_phases > 1) && isempty(phase_id)
phase_id = inputwdefaultnumeric('Enter phaseID', num2str(1));
end
phaseID_str = sprintf('%02d', phaseID);
phaseID_str = sprintf('%02d', phase_id);
disp(['Setting up Reconstruction for phase ' phaseID_str ' (' parameters.cryst(phaseID).name ')']);
disp(['Setting up Reconstruction for phase ' phaseID_str ' (' parameters.cryst(phase_id).name ')']);
samplefile = fullfile(parameters.acq.dir, '4_grains', 'sample.mat');
if exist(samplefile, 'file')
......@@ -83,11 +91,11 @@ end
% add the possibility to redo abs reconstruction, even if existing
absorption_volume = fullfile(parameters.acq.dir, '5_reconstruction', 'volume_absorption.mat');
if ~exist(absorption_volume,'file')
if (~exist(absorption_volume,'file'))
check = inputwdefault([ ...
'Can not find absorption volume. Would you like to launch ' ...
'reconstruction of absorption volume? [y/n]'] , 'y');
if strcmpi(check, 'y')
if (strcmpi(check, 'y'))
abs = gtAstraAbsorptionVolume(parameters);
save(absorption_volume, 'abs', '-v7.3');
sample.absVolFile = fullfile('5_reconstruction', 'volume_absorption.mat');
......@@ -95,7 +103,7 @@ if ~exist(absorption_volume,'file')
end
else
check = inputwdefault('Absorption volume found - would you like to overwrite it? [y/n]', 'n');
if strcmpi(check, 'y')
if (strcmpi(check, 'y'))
abs = gtAstraAbsorptionVolume(parameters);
save(absorption_volume, 'abs', '-v7.3');
sample.absVolFile = fullfile('5_reconstruction', 'volume_absorption.mat');
......@@ -105,9 +113,9 @@ end
% add the possibility to redo volume threshold, even if existing
absorption_mask = fullfile(parameters.acq.dir, '5_reconstruction', 'volume_mask.mat');
if ~exist(absorption_mask,'file')
if (~exist(absorption_mask,'file'))
check = inputwdefault('Can not find absorption mask. Would you like to segment absorption volume? [y/n]', 'y');
if strcmpi(check, 'y')
if (strcmpi(check, 'y'))
if (~exist('abs', 'var'))
abs = load(absorption_volume, 'abs');
abs = abs.abs;
......@@ -118,7 +126,7 @@ if ~exist(absorption_mask,'file')
end
else
check = inputwdefault('Absorption mask found - would you like to overwrite it? [y/n]', 'n');
if strcmpi(check, 'y')
if (strcmpi(check, 'y'))
if (~exist('abs', 'var'))
abs = load(absorption_volume, 'abs');
abs = abs.abs;
......@@ -128,49 +136,73 @@ else
end
end
% If input parameter list is empty, we will use all grains by default
first = 1;
last = sample.phases{phaseID}.getNumberOfGrains();
% If input parameters grain_ids and cluster_ids are both empty, we will
% reconstruct all grains by default
if (~exist('list', 'var') || isempty(list))
list = [first : last];
if (isempty(conf.grain_ids) && isempty(conf.cluster_ids))
first = 1;
last = sample.phases{phase_id}.getNumberOfGrains();
conf.grain_ids = first:last;
end
check = inputwdefault('Launch reconstruction? [y/n]', 'y');
rec_on_OAR = false;
if strcmpi(check, 'y')
if (GPU_OK)
check2 = inputwdefault('Launch grain reconstruction via OAR? [y/n]', 'y');
rec_on_OAR = strcmpi(check2, 'y');
else
rec_on_OAR = true;
if (~isempty(conf.grain_ids))
check = inputwdefault('Launch grain reconstruction? [y/n]', 'y');
rec_on_OAR = false;
if strcmpi(check, 'y')
if (GPU_OK)
check2 = inputwdefault('Launch grain reconstruction via OAR? [y/n]', 'y');
rec_on_OAR = strcmpi(check2, 'y');
else
rec_on_OAR = true;
end
if (rec_on_OAR)
launch_on_OAR('gtReconstructGrains', first, last, phaseID_str, ...
parameters, 'njobs', 8, 'walltime', 3600 * 16, ...
'gpu', true, 'distribute', true, 'list', conf.grain_ids);
else
gtReconstructGrains(first, last, parameters.acq.dir, phase_id, ...
parameters, 'list', conf.grain_ids);
end
end
if (rec_on_OAR)
launch_on_OAR('gtReconstructGrains', first, last, phaseID_str, ...
parameters, 'njobs', 8, 'walltime', 3600 * 16, ...
'gpu', true, 'distribute', true, 'list', list);
else
gtReconstructGrains(first, last, parameters.acq.dir, phaseID, parameters, 'list', list);
if (~rec_on_OAR)
check = inputwdefault('Launch grain segmentation? [y/n]', 'y');
if strcmpi(check, 'y')
check = inputwdefault('Use existing parameters for grain segmentation? [y/n]', 'y');
if ~strcmpi(check, 'y')
info_list = build_list_v2();
parameters.rec = gtModifyStructure(parameters.rec, ...
info_list.rec, 2, 'Grain segmentation parameters:');
gtSaveParameters(parameters);
end
check = inputwdefault('Launch grain segmentation via OAR? [y/n]', 'y');
if (strcmpi(check, 'y'))
launch_on_OAR('gtChangeThreshold3D', first, last, ...
phaseID_str, parameters, 'core', 4, 'distribute', false);
else
gtChangeThreshold3D(first, last, [], phase_id);
end
end
end
end
if (~rec_on_OAR)
check = inputwdefault('Launch grain segmentation? [y/n]', 'y');
if (~isempty(conf.cluster_ids))
check = inputwdefault('Launch cluster reconstruction? [y/n]', 'y');
if strcmpi(check, 'y')
check = inputwdefault('Use existing parameters for grain segmentation? [y/n]', 'y');
if ~strcmpi(check, 'y')
list = build_list_v2();
parameters.rec = gtModifyStructure(parameters.rec, list.rec, 2, 'Grain segmentation parameters:');
save(parameters_savefile,'parameters');
if (GPU_OK)
check2 = inputwdefault('Launch grain reconstruction via OAR? [y/n]', 'y');
rec_on_OAR = strcmpi(check2, 'y');
else
rec_on_OAR = true;
end
check = inputwdefault('Launch grain segmentation via OAR? [y/n]', 'y');
if (strcmpi(check, 'y'))
launch_on_OAR('gtChangeThreshold3D', first, last, ...
phaseID_str, parameters, 'core', 4, 'distribute', false);
if (rec_on_OAR)
launch_on_OAR('gtReconstructClusters', first, last, phaseID_str, ...
parameters, 'njobs', 8, 'walltime', 3600 * 16, ...
'gpu', true, 'distribute', true, 'list', conf.cluster_ids);
else
gtChangeThreshold3D(first, last, [], phaseID);
gtReconstructClusters(first, last, parameters.acq.dir, ...
phase_id, parameters, 'list', conf.cluster_ids);
end
end
end
......
......@@ -47,6 +47,9 @@
<function name="gtReconstructGrains">
<path absolute="false">5_reconstruction/gtReconstructGrains.m</path>
</function>
<function name="gtReconstructClusters">
<path absolute="false">5_reconstruction/gtReconstructClusters.m</path>
</function>
<function name="gtForwardSimulate_v2">
<path absolute="false">zUtil_ForwardSim/gtForwardSimulate_v2.m</path>
</function>
......
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