Commit b8a496e5 authored by Luis Fernandez Ruiz's avatar Luis Fernandez Ruiz
Browse files

Add comments to:

- create_img_param_general.m
- create_suggested_images.m
- save_sim_sphere_coresphere.m
parent 4b7d32f9
......@@ -6,9 +6,14 @@ function create_img_param_general(save_img_path, scat_model, varargin)
scattered model of the particles (Sphere, Core-Shell Sphere,...), this
script generate an image and save it in the path specified in 'save_img_path'
Example of input variables declaration:
- save_img_path = '/home/dpt/fernandez-ruiz/sim/sim_data/';
- scat_model = 'Sphere' or 'Core-Shell Sphere';
- varargin = ['dist', dist_value, 'col', col_value, 'wav', wav_value, ...]
------------------------------------------------------
Author: FERNANDEZ RUIZ Luis
Based on code of ILL: save_sim_sphere.m
Modify by: FERNANDEZ RUIZ Luis
Last modified: 10/07/2019
File: create_img_param.m
......@@ -16,7 +21,7 @@ function create_img_param_general(save_img_path, scat_model, varargin)
%}
% Define the scattered model
scatter_model = scat_model; %'Sphere';
scatter_model = scat_model; %'Sphere' or 'Core-Shell Sphere';
% Initialize variables with values by default. After, we will modify some of
% them with values contain in varargin (input parameter)
......@@ -59,9 +64,9 @@ end
% the structure of data inputted in varargin is: ['dist', dist_value, 'col', col_value, 'wav', wav_value, ...]
if nargin >=1 %i.e. varagin exists
params = fieldnames(params_scatter);
for n = 1:length(params) % we search between all the params by default (defined above)
% if we find them (e.g. 'col') we look for the next element in the
% array (col_value) and pass it to the algorithm to generate
for n = 1:length(params) % we search between all the params by default (e.g. params_scatter.col)
% if we find them in varargin (e.g. 'col') we look for the next element in the
% varargin array (col_value) and pass it to the algorithm to generate
% scattered images
idx=find(cellfun(@(varargin) any(strcmp(varargin,params{n})),varargin));
if not(isempty(idx))
......@@ -174,20 +179,13 @@ if isempty(output)
end
if strcmp(scatter_model, 'Sphere')
%filename = ['./sim_data/Sphere/scatter_image/Sphere' background_model '_col' num2str(collimation) '_dist' num2str(distance) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_contrast' num2str(params_scatter.contrast) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.bg) '_wav' num2str(wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.txt'];
filename2 = [save_img_path '/Sphere' background_model '_col' num2str(params_scatter.col) '_dist' num2str(params_scatter.dist) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_contrast' num2str(params_scatter.contrast) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.bg) '_wav' num2str(params_scatter.wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.jpg'];
%filename3 = ['./sim_data/Sphere/params/Sphere' background_model '_col' num2str(collimation) '_dist' num2str(distance) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_contrast' num2str(params_scatter.contrast) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.bg) '_wav' num2str(wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.txt'];
elseif strcmp(scatter_model, 'Core-Shell Sphere')
%filename = ['./sim_data/CoreShellSphere/scatter_image/Sphere' background_model '_col' num2str(collimation) '_dist' num2str(distance) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_contrast' num2str(params_scatter.contrast) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.bg) '_wav' num2str(wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.txt'];
filename2 = [save_img_path '/CoreShellSphere' background_model '_col' num2str(params_scatter.col) '_dist' num2str(params_scatter.dist) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_shell' num2str(params_scatter.shell) '_rhocore' num2str(params_scatter.rhocore) '_rhoshell' num2str(params_scatter.rhoshell) '_rhomatrix' num2str(params_scatter.rhomatrix) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.bg) '_wav' num2str(params_scatter.wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.jpg'];
%filename3 = ['./sim_data/CoreShellSphere/params/Sphere' background_model '_col' num2str(collimation) '_dist' num2str(distance) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_contrast' num2str(params_scatter.contrast) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.bg) '_wav' num2str(wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.txt'];
end
data = abs(output.data1(:,:,1));
%fid = fopen(filename,'w');
%fid3 = fopen(filename3,'w');
%Plot results, just for fun
frames = size(output.data1,3);
for n = 1:frames
......@@ -198,8 +196,6 @@ for n = 1:frames
ax = gca;
set(ax,'YTick',[],'XTick',[])
fig = gcf;%s\t%f\t
%csvwrite(filename, data);
%csvwrite(filename3, params);
[imageData, alpha] = export_fig;
imwrite(imageData,filename2);
end
......
function create_suggested_images(save_img_path, suggest_path, scatter_model_type) % save_img_path, suggest_path, scatter_model_type
%save_img_path = '/home/dpt/fernandez-ruiz/sim/sim_data/Sphere/log_image/test_set/';
%suggest_path = '/home/dpt/fernandez-ruiz/sim/sim_data/Sphere/log_image/test_set/suggest_improved_guinier (copy 1).csv';
%scatter_model_type = 'Sphere';
function create_suggested_images(save_img_path, suggest_path, scat_model) % save_img_path, suggest_path, scat_model
%{
/*********************************************************************************************
given a suggest.csv file (suggest_path), this script generates the images specified
into it. It works for 'Sphere' and 'Core-Shell Sphere' scattered models that the user
has to specified in 'scat_model'. It saves the images in save_img_path
Example of input variables declaration:
- save_img_path = '/home/dpt/fernandez-ruiz/sim/sim_data/';
- suggest_path = '/home/dpt/fernandez-ruiz/sim/sim_data/suggest.csv';
- scat_model = 'Sphere' or 'Core-Shell Sphere';
------------------------------------------------------
Based on code of ILL: save_sim_sphere.m
Modify by: FERNANDEZ RUIZ Luis
Last modified: 15/07/2019
File: create_suggested_images.m
*********************************************************************************************
%}
% Read suggest.csv file. The structure of this file is a dataframe with the
% following columns (in this order):
% dist, col, wav, bg, CNN prediction, sample parameters, error in sample
% parameters
df = readtable(suggest_path);
[nrows, ncols] = size(df);
var_names = df.Properties.VariableNames;
%df = csvread(suggest_path, 1, 0);
[nrows, ncols] = size(df); % count cols and rows
var_names = df.Properties.VariableNames; % get names of columns
% select the columns of the instr parameters...
dist_array = df.dist;
col_array = df.col;
wav_array = df.wav;
bg_array = num2str(df.bg);
% ... and the prediction of the CNN
prediction_array = num2str(df.predicted);
%dist_array = df(:,1);
%col_array = df(:,2);
%wav_array = df(:,3);
%bg_array = num2str(df(:,4));
%if (real_rad == false) % create images with predicted radius (real radius - error between real and prediction)
% radius_array = df(:,6) - df(:,7);
%else
% radius_array = df(:,6);
%end
%prediction_array = num2str(df(:,5));
%distance = 18; % D22, distance 1-18m
% initialize variables
mono_tof = 'mono';
delta_wav = 10; %percentage
instrument = 'd22';
......@@ -34,72 +44,85 @@ sample_size = [10e-3 10e-3];
attenuator = 1;
thickness = 0.1;
%Prepare scattering model parameter structure
scatter_model = scatter_model_type;
scatter_model = scat_model;
params_scatter.poly_fwhm = 0;
params_scatter.scale = 0.01;
background_model = 'Empty Cell'; %Empty Cell,Cryostat Ox7T
horiz_beam_centre_params = [0 -randi([15 35])];
horiz_beam_centre = horiz_beam_centre_params(1);
%sample
% sample parameters that depends of the model
if strcmp(scatter_model, 'Sphere')
params_scatter.radius = 100;
params_scatter.contrast = 6e-6;
% we fill an array of sample parameters with zeros. If in suggest.csv
% there is a column of radius or contrast, we will fill it after with
% the values in the file...
array_params_scatter.radius = zeros(nrows,1);
array_params_scatter.contrast = zeros(nrows,1);
elseif strcmp(scatter_model, 'Core-Shell Sphere')
% ... if there is not column of one of them, it will have always the
% following default value
params_scatter.radius = 100;
params_scatter.shell = 100;
params_scatter.rhocore = 7e-07;
params_scatter.rhoshell = 1.6e-06;
params_scatter.rhomatrix = 3.5e-06;
params_scatter.contrast = 6e-6;
elseif strcmp(scatter_model, 'Core-Shell Sphere')
% we fill an array of sample parameters with zeros. If in suggest.csv
% there is a column of radius, shell..., we will fill it after with
% the values in the file...
array_params_scatter.radius = zeros(nrows,1);
array_params_scatter.shell = zeros(nrows,1);
array_params_scatter.rhocore = zeros(nrows,1);
array_params_scatter.rhoshell = zeros(nrows,1);
array_params_scatter.rhomatrix = zeros(nrows,1);
% ... if there is not column of one of them, it will have always the
% following default value
params_scatter.radius = 100;
params_scatter.shell = 100;
params_scatter.rhocore = 7e-07;
params_scatter.rhoshell = 1.6e-06;
params_scatter.rhomatrix = 3.5e-06;
end
% We replace values by default for those that are in suggest.csv file.
params = fieldnames(array_params_scatter);
for n = 1:length(params) % we search between all the params by default (defined above)
% if we find them between the headers in suggest.csv file we copy that
% column to our array_param_scatter
for n = 1:length(params) % we search between all the sample params by default
% (e.g. array_params_scatter.radius). If we find any of them (e.g. radius)
% between the headers in suggest.csv file we copy that column to the
% appropiate array_param_scatter.radius
idx=find(cellfun(@(var_names) any(strcmp(var_names,params{n})),var_names));
if not(isempty(idx))
array_params_scatter.(params{n}) = table2array(df(:,idx));
end
end
for a = 1:nrows
fprintf('%i%s%i\n', a, '/', nrows);
distance = dist_array(a);
collimation = col_array(a);
wav = wav_array(a);
params_scatter.background = bg_array(a);
former_predict = prediction_array(a);
% Iterate over all the rows in suggest.csv file (each row is an image)
for i = 1:nrows
fprintf('%i%s%i\n', i, '/', nrows);
% define instrument parameters of the images
distance = dist_array(i);
collimation = col_array(i);
wav = wav_array(i);
params_scatter.background = bg_array(i);
former_predict = prediction_array(i);
% Fill sample parameters if it is in suggest.csv file. Array not empty
if strcmp(scatter_model, 'Sphere')
if any(array_params_scatter.radius~=0)
params_scatter.radius = array_params_scatter.radius(a);
params_scatter.radius = array_params_scatter.radius(i);
end
elseif strcmp(scatter_model, 'Core-Shell Sphere')
if any(array_params_scatter.radius~=0)
params_scatter.radius = array_params_scatter.radius(a);
params_scatter.radius = array_params_scatter.radius(i);
end
if any(array_params_scatter.shell~=0)
params_scatter.shell = array_params_scatter.shell(a);
params_scatter.shell = array_params_scatter.shell(i);
end
if any(array_params_scatter.rhocore~=0)
params_scatter.rhocore = array_params_scatter.rhocore(a);
params_scatter.rhocore = array_params_scatter.rhocore(i);
end
if any(array_params_scatter.rhoshell~=0)
params_scatter.rhoshell = array_params_scatter.rhoshell(a);
params_scatter.rhoshell = array_params_scatter.rhoshell(i);
end
if any(array_params_scatter.rhomatrix~=0)
params_scatter.rhomatrix = array_params_scatter.rhomatrix(a);
params_scatter.rhomatrix = array_params_scatter.rhomatrix(i);
end
end
......@@ -200,7 +223,7 @@ for a = 1:nrows
'bx',0,'by',0,'attenuator',attenuator,'thickness',thickness,....
'scatter_model',scatter_model,'scatter_model_params',params_scatter,....
'background_model',background_model,'background_model_params',[],....
'blocked_model','Blocked Beam','blocked_model_params',[], 'horiz_beam_centre', horiz_beam_centre);%[45e-3,55e-3]
'blocked_model','Blocked Beam','blocked_model_params',[], 'horiz_beam_centre', horiz_beam_centre);
if isempty(output)
......@@ -208,19 +231,12 @@ for a = 1:nrows
end
if strcmp(scatter_model, 'Sphere')
%filename = ['./sim_data/Sphere/scatter_image/Sphere' background_model '_col' num2str(collimation) '_dist' num2str(distance) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_contrast' num2str(params_scatter.contrast) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.bg) '_wav' num2str(wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.txt'];
filename2 = [save_img_path '/Sphere' background_model '_col' num2str(collimation) '_dist' num2str(distance) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_contrast' num2str(params_scatter.contrast) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.background) '_wav' num2str(wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.jpg'];
%filename3 = ['./sim_data/Sphere/params/Sphere' background_model '_col' num2str(collimation) '_dist' num2str(distance) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_contrast' num2str(params_scatter.contrast) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.bg) '_wav' num2str(wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.txt'];
elseif strcmp(scatter_model, 'Core-Shell Sphere')
%filename = ['./sim_data/CoreShellSphere/scatter_image/Sphere' background_model '_col' num2str(collimation) '_dist' num2str(distance) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_contrast' num2str(params_scatter.contrast) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.bg) '_wav' num2str(wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.txt'];
filename2 = [save_img_path '/CoreShellSphere' background_model '_col' num2str(collimation) '_dist' num2str(distance) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_shell' num2str(params_scatter.shell) '_rhocore' num2str(params_scatter.rhocore) '_rhoshell' num2str(params_scatter.rhoshell) '_rhomatrix' num2str(params_scatter.rhomatrix) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.background) '_wav' num2str(wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.jpg'];
%filename3 = ['./sim_data/CoreShellSphere/params/Sphere' background_model '_col' num2str(collimation) '_dist' num2str(distance) '_radius' num2str(params_scatter.radius) '_poly' num2str(params_scatter.poly_fwhm) '_contrast' num2str(params_scatter.contrast) '_scale' num2str(params_scatter.scale) '_bg' num2str(params_scatter.bg) '_wav' num2str(wav) '_thickness' num2str(thickness) '_beamcenter' num2str(horiz_beam_centre) '.txt'];
end
data = abs(output.data1(:,:,1));
%fid = fopen(filename,'w');
%fid3 = fopen(filename3,'w');
%Plot results, just for fun
frames = size(output.data1,3);
for n = 1:frames
......@@ -231,13 +247,9 @@ for a = 1:nrows
ax = gca;
set(ax,'YTick',[],'XTick',[])
fig = gcf;%s\t%f\t
%csvwrite(filename, data);
%csvwrite(filename3, params);
[imageData, alpha] = export_fig;
imwrite(imageData,filename2);
end
%fclose(fid);
%fclose(fid3);
if strcmp(scatter_model, 'Sphere')
fprintf('%s\t%f\t%s\t%f\t%s\t%f\t%s\t%f\t%s\t%f\t%s\t%f\t%s\t%f\t%s\t%f\t%s\t%f\t%s\t%f\n','col',collimation,'dist', distance, 'radius',params_scatter.radius, 'poly', params_scatter.poly_fwhm, 'contrast',params_scatter.contrast, 'scale',params_scatter.scale,'bg',params_scatter.background, 'wav', wav, 'thickness', thickness, 'beam center', horiz_beam_centre)
elseif strcmp(scatter_model, 'Core-Shell Sphere')
......
function save_sim_sphere_coresphere(save_img_path, scat_model) %save_img_path, scat_model
%save_img_path = '/home/dpt/fernandez-ruiz/sim/sim_data/CoreShellSphere';
%scat_model = 'Core-Shell Sphere'; %'Sphere' 'Core-Shell Sphere'
%{
/*********************************************************************************************
this scripts generates images following the scattered model of the particles
(Sphere and Core-Shell Sphere) specified in scat_model. It saves them in
the path specified in 'save_img_path'
Example of input variables declaration:
- save_img_path = '/home/dpt/fernandez-ruiz/sim/sim_data/';
- scat_model = 'Sphere' or 'Core-Shell Sphere';
------------------------------------------------------
Based on code of ILL: save_sim_sphere.m
Modify by: FERNANDEZ RUIZ Luis
Last modified: 17/07/2019
File: save_sim_sphere_coresphere.m
*********************************************************************************************
%}
col_params = [2 2.8 4 5.6 8 11.2 14.4 17.6]; %D22
dist_params = [1.4 2.8 4 5.6 8 11.2 14.4 17.6];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment