-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_script.m
More file actions
215 lines (182 loc) · 4.96 KB
/
example_script.m
File metadata and controls
215 lines (182 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
%% Example script
% Requires mGstat in path, specifically 'mps_template.m' and 'channels.m'
% https://github.com/cultpenguin/mGstat
rng(1); % Set fixed random seed;
%% LOAD DATA
load('reference3.mat')
soft_data_grid1 = SD_thirty; %Set to
%soft_data_grid2 =
soft_data = 1; %use soft data at all
soft_data_combine = 0; %if more than one soft data grid.
%Simulation Grid Size (only set if no softdata is used).
sg_x = 30;
sg_y = 30;
%% Training Image
%[d,h]=read_eas('kasted_data//TI_extended_50x50.eas');
%TI = reshape(d(:,2),632,291)';
TI = channels;
%% GENERAL OPTIONS
num_realizations = 1;
print = 1;
plots = 1;
%% Save options
make_save = 0;
save_setup = 0;
output_folder = 'realizations';
filename_prefix = 'realization';
%% IMPALA OPTIONS
% PATH
% 0: raster, 1:random, 2: random preferential, 3: dist
pathtype = 2;
I_fac = 4; % Only applies to preferential path
% Data template
template_length = 512;
template_shape = 1;
options.print = print;
% Min counts to make a cdpf, else use marginal distribution
options.threshold = 5;
% Use GPU instead of CPU for searching the list and calculating cdpf
options.GPU = 1; %Requires CUDA capable GPU
% Max number of non-colocated softdata to use (0, 1, 2, 3 ...)
% Note: Currently only works in GPU implementation
options.num_soft_nc = 5;
% Capping (Max number of conditional data to search for in the SG)
% Set to template_length or more to disable.
options.cap = 20;
% Trimming
options.trimming = 0;
options.trim_size = 5;
options.trim_trigger = 10;
options.min_size = 10;
%% Training Image
dim = length(size(TI));
cat = unique(TI(:))';
num_cat = length(cat);
fprintf("There are %i different facies. \n",num_cat);
%%Load soft data:
if soft_data
SDG = soft_data_grid1;
%If soft data grid 1 dimensional
if size(SDG,3) == 1
SDG = 1 - SDG;
SDG(:,:,2) = 1 - SDG(:,:,1);
end
end
if soft_data_combine
%Turn NaNs into flat distribution
soft_data_grid1(isnan(soft_data_grid1)) = 1/size(SDG,3);
soft_data_grid2(isnan(soft_data_grid2)) = 1/size(SDG,3);
%Combine probabilities
SDG = soft_data_grid1.*soft_data_grid2;
%Normalize
SDG = SDG./sum(SDG,3);
%Remove grid points with no informationentropy
SDG(SDG == 1/size(SDG,3)) = NaN;
%TODO: Make work for three or more categories
end
%Simulation grid size
if (sg_x == 0) || (sg_y == 0)
sg_x = size(SDG,1);
sg_y = size(SDG,2);
end
%Soft data
if (soft_data > 0)
sg_x = size(SDG,1);
sg_y = size(SDG,2);
sg_z = size(SDG,3);
else
switch dim
case 2
SDG = NaN(sg_x,sg_y,num_cat);
case 3
SDG = NaN(sg_x,sg_y,sg_z,num_cat);
end
end
switch dim
case 2
SG = NaN(sg_x,sg_y);
case 3
SG = NaN(sg_x,sg_y,sg_z);
end
if ~exist('SDG','var')
SDG = NaN([size(SG),length(cat)]);
end
%Template
tau = mps_template(template_length,dim,template_shape);
tic
%Populate pattern library (list)
list = populate_impala_list(TI, tau );
time_elapsed = toc;
if print
fprintf('Time to populate list: %8.3f seconds.\n', time_elapsed);
fprintf("List length %i \n",size(list,1));
end
%Display list if small enough
if size(list,1) < 40
print_impala_list( list );
end
SG_tot = zeros(size(SG));
if plots
fig_current = figure();
end
%% Simulation
for i = 1:num_realizations
%Generate new path
tic
switch pathtype
case 0
[path, n_u] = raster_path(SG);
case 1
[path, n_u] = rand_path(SG);
case 2
[path, n_u] = pref_path(SG, SDG, I_fac);
case 3
[path, n_u] = dist_path(SG, tau);
end
time_elapsed = toc;
if print
fprintf('Time to generate random path: %8.3f seconds.\n',...
time_elapsed);
end
%Pre-calculate random numbers
rand_pre = rand(n_u,1);
tic;
if options.GPU
[SG, tauG, stats] = impala_core_gpu_soft(...
SG, SDG, list, path, tau, rand_pre, cat, options);
else
[SG, tauG, stats] = impala_core(...
SG, SDG, list, path, tau, rand_pre, cat, options);
end
time_elapsed = toc;
if print
fprintf('Time to generate realization number %i: %8.3f seconds.\n', i, time_elapsed);
end
if make_save
saveRealization(SG,[filename_prefix num2str(i)],output_folder);
end
if plots
imagesc(gca,SG)
title(sprintf('Realization number %i',i));
axis image
axis ij
hold on;
drawnow
end
SG_tot = SG_tot + SG;
last_i = i;
SG = NaN(size(SG));
end
if save_setup
close all;
save([output_folder '//' 'setup.mat']);
end
if plots
SG_image = SG_tot./last_i;
fig_mean = figure;
imagesc(SG_image);
title(sprintf('Realizations 1 through %i',i));
axis image
axis ij
drawnow;
end