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

Topotomo import: updated parameters import function

parent 89a4f0c8
No related branches found
No related tags found
No related merge requests found
function p = gtGrainTopotomoUpdateParameters(scan_xml, range_basetilt, nproj_basetilt, p, detgeo_tt, pl_ind, gr)
function p = gtGrainTopotomoUpdateParameters(scan_xml, range_basetilt, nproj_basetilt, p, detgeo_tt, pl_ind, gr, varargin)
conf = struct('check_flips', false, 'verbose', true);
conf = parse_pv_pairs(conf, varargin);
if (~exist('p', 'var') || isempty(p))
p = gtLoadParameters();
end
o = GtConditionalOutput(conf.verbose);
[tt_scan_dir, ~, ~] = fileparts(scan_xml);
fprintf('Importing Topotomo acquisition into current DCT parameters:\n')
fprintf(' - Path of Topotomo scan: %s\n', tt_scan_dir)
fprintf(' - Path of DCT scan: %s\n', p.acq(1).dir)
o.fprintf('Importing Topotomo acquisition into current DCT parameters:\n')
o.fprintf(' - Path of Topotomo scan: %s\n', tt_scan_dir)
o.fprintf(' - Path of DCT scan: %s\n', p.acq(1).dir)
if (~isfield(p.acq(1), 'motors'))
fprintf(' - Reading DCT motor positions..')
o.fprintf(' - Reading DCT motor positions..')
c = tic();
xmlfname = fullfile(p.acq.dir, '0_rawdata', 'Orig', [p.acq.name '.xml']);
acq_xml = gtLoadAcquisitionXML(xmlfname, false, false);
......@@ -21,19 +26,20 @@ function p = gtGrainTopotomoUpdateParameters(scan_xml, range_basetilt, nproj_bas
new_acq(ii_a) = gtAddMatFile(base_acq, p.acq(ii_a), true);
end
p.acq = new_acq;
fprintf('\b\b: Done in %g seconds.\n', toc(c))
o.fprintf('\b\b: Done in %g seconds.\n', toc(c))
end
acq_tt = p.acq(1);
fprintf(' - Reading Topotomo acquisition parameters..')
o.fprintf(' - Reading Topotomo acquisition parameters..')
c = tic();
topotomo_xml = gtLoadAcquisitionXML(scan_xml, false, false);
acq_tt = gtAddMatFile(acq_tt, topotomo_xml, true, false, false);
acq_tt.type = 'topotomo'; % The XML tends to set it to 360degree
acq_tt = gtAcqDefaultParameters(acq_tt);
acq_tt.collection_dir = tt_scan_dir;
fprintf('\b\b: Done in %g seconds.\n', toc(c))
o.fprintf('\b\b: Done in %g seconds.\n', toc(c))
if (acq_tt.energy < 0)
disp(' ')
warning('Energy reported by the XML file is: %d, parsing info file...', acq_tt.energy)
......@@ -46,37 +52,42 @@ function p = gtGrainTopotomoUpdateParameters(scan_xml, range_basetilt, nproj_bas
disp(' ')
end
% % Check for flips:
% cfg_file = fullfile(tt_scan_dir, [acq_tt.name '.cfg']);
% fid = fopen(cfg_file);
% valid = true;
% file_content = {};
% while (valid)
% file_content{end+1} = fgets(fid); %#ok<AGROW>
% valid = file_content{end} ~= -1;
% end
% fclose(fid);
% file_content = [file_content{:}];
% horz_flip = regexp(file_content, 'ccd_flip_horz\s*(?<value>\d+)', 'names', 'once');
% vert_flip = regexp(file_content, 'ccd_flip_vert\s*(?<value>\d+)', 'names', 'once');
% if (str2double(horz_flip.value))
% acq_tt.detroi_u_off = acq_tt.true_detsizeu - acq_tt.detroi_u_off;
% end
% if (str2double(vert_flip.value))
% acq_tt.detroi_v_off = acq_tt.true_detsizev - acq_tt.detroi_v_off;
% end
% Automatically checking for flips:
if (conf.check_flips)
o.fprintf(' - Checking topotomo image flips..')
c = tic();
cfg_file = fullfile(tt_scan_dir, [acq_tt.name '.cfg']);
fid = fopen(cfg_file);
valid = true;
file_content = {};
while (valid)
file_content{end+1} = fgets(fid); %#ok<AGROW>
valid = file_content{end} ~= -1;
end
fclose(fid);
file_content = [file_content{:}];
horz_flip = regexp(file_content, 'ccd_flip_horz\s*(?<value>\d+)', 'names', 'once');
vert_flip = regexp(file_content, 'ccd_flip_vert\s*(?<value>\d+)', 'names', 'once');
if (str2double(horz_flip.value))
acq_tt.detroi_u_off = acq_tt.true_detsizeu - acq_tt.detroi_u_off;
end
if (str2double(vert_flip.value))
acq_tt.detroi_v_off = acq_tt.true_detsizev - acq_tt.detroi_v_off;
end
o.fprintf('\b\b: Done in %g seconds.\n', toc(c))
end
dct_samt = [p.acq(1).motors.samtx, p.acq(1).motors.samty, p.acq(1).motors.samtz];
tt_samt = [acq_tt.motors.samtx, acq_tt.motors.samty, acq_tt.motors.samtz];
% samr X and Y reversed, because the first on the right is the one
% applied first when doing SAM->LAB
dct_samr = [p.acq(1).motors.samry, p.acq(1).motors.samrx];
tt_samr = [acq_tt.motors.samry, acq_tt.motors.samrx];
dct_diffrz_start = p.acq(1).motors.diffrz;
% Translations should be handled a bit differently, especially if there
% were some initial tilts in the DCT acquisition
acq_tt.sample_shifts = tt_samt - dct_samt;
% samr X and Y reversed, because the first on the right is the one
% applied first when doing SAM->LAB
acq_tt.sample_tilts = tt_samr - dct_samr;
acq_tt.range_basetilt = range_basetilt;
......@@ -87,18 +98,21 @@ function p = gtGrainTopotomoUpdateParameters(scan_xml, range_basetilt, nproj_bas
p.acq(end+1) = acq_tt;
det_ind = numel(p.acq);
p.diffractometer(det_ind) = gtGeoDiffractometerDefinition('esrf_id11', ...
'axes_rotation_offset', p.acq(1).motors.diffrz, ...
'shifts_sam_stage', acq_tt.sample_shifts );
p.detgeo(det_ind) = detgeo_tt;
% It might be that the Detector definition ha to be shifted as well!!
% p.detgeo(det_ind).detrefpos = p.detgeo(det_ind).detrefpos + p.diffractometer(det_ind).shifts_sam_stage;
p.recgeo(det_ind) = p.recgeo(1);
p.recgeo(det_ind).voxsize = mean([detgeo_tt.pixelsizeu, detgeo_tt.pixelsizev]) * [1, 1, 1];
if (isempty(pl_ind))
fprintf(' - Guessing Topotomo pl_ind, with respect to DCT (for the range: [%g, %g])..', range_basetilt)
o.fprintf(' - Guessing Topotomo pl_ind, with respect to DCT (for the range: [%g, %g])..', range_basetilt)
c = tic();
% Trying to detect the tilts
p.diffractometer(det_ind) = gtGeoDiffractometerDefinition('esrf_id11', ...
'axes_rotation_offset', dct_diffrz_start, ...
'shifts_sam_stage', acq_tt.sample_shifts);
diff = p.diffractometer(det_ind);
tilts = p.acq(det_ind).sample_tilts;
t = gtGeoDiffractometerTensor(diff, 'sam2lab', 'angles_sam_tilt', tilts);
......@@ -107,9 +121,9 @@ function p = gtGrainTopotomoUpdateParameters(scan_xml, range_basetilt, nproj_bas
pl_labd = gtGeoSam2Lab(pl_samd_sign, t, p.labgeo, p.samgeo, true);
angle = gtMathsVectorsAnglesDeg(diff.axes_rotation, pl_labd, false);
fprintf('\b\b: Done in %g seconds.\n', toc(c))
o.fprintf('\b\b: Done in %g seconds.\n', toc(c))
[~, pl_ind] = min(angle);
fprintf(' + Chosen pl_ind: %d (%g deg)\n', pl_ind, angle(pl_ind))
o.fprintf(' + Chosen pl_ind: %d (%g deg)\n', pl_ind, angle(pl_ind))
end
p.acq(det_ind).pl_ind = pl_ind;
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