forked from mikebianco/locally-sparse-tomography
-
Notifications
You must be signed in to change notification settings - Fork 0
/
station_setup.m
168 lines (129 loc) · 4.32 KB
/
station_setup.m
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
%============================================================
% Code for configuring sensor array, and calculating rays and travel times
% between sensors (straight-ray code) for locally sparse travel time
% tomography (LST) algorithm simulation. The methods implemented here are
% the same as described in:
% 1. M.J. Bianco and P. Gerstoft, "Travel time tomography with adaptive
% dictionaries," IEEE Trans. on Computational Imaging, Vol. 4, No. 4, 2018.
%
% If you find this code useful in your research, please cite the above
% reference (1).
%
% LST version 1.0
% Michael J. Bianco, December 11th, 2018.
% email: mbianco@ucsd.edu
%============================================================
nStations = 64; % number of stations
% generating random array locations
rng(0)
stas = randn(nStations,2);
stas = sign(stas).*abs(stas).^(7/8); % make center less dense
staRatio = 49./max(abs(stas));
xSta = stas(:,1)*staRatio(1)+49;
ySta = stas(:,2)*staRatio(2)+49;
staPerms = nchoosek(1:nStations,2)';
lenStaPerms = length(staPerms);
staPermsVec = staPerms(:);
xStaChoose = xSta(staPermsVec);
yStaChoose = ySta(staPermsVec);
xStaResh = reshape(xStaChoose,[2,lenStaPerms]);
yStaResh = reshape(yStaChoose,[2,lenStaPerms]);
X1 = [xStaResh(1,:);yStaResh(1,:)]';
X2 = [xStaResh(2,:);yStaResh(2,:)]';
%% determining valid(sampled) region
% bps = ginput;
bps= [ 7.7189 39.5190;
16.2442 21.4140;
31.6820 14.0671;
45.7373 11.7055;
70.8525 16.6910;
91.3594 22.9883;
97.8111 44.2420;
88.1336 66.5452;
70.8525 77.5656;
36.5207 97.7697;
28.6866 89.6356];
vb = roipoly(100,100,bps(:,1),bps(:,2)); % valid bounds corresponding to outermost ray paths
se = strel('square',9);
vb2 = imdilate(vb,se); % valid bounds for LST
%% calculating rays and travel travel time and sensing matrix
display('Solving for ray paths and travel time...')
mult = 100; % ensuring enough resolution for ray steps (can increase this number to improve accuracy)
sc=size(sTrue);
lc=length(sTrue(:));
steps = ceil(1.5*max(sc)); % step size for ray propagation
av=single([]);
ii=single([]);
jj=single([]);
for m = 1:length(X1)
src = X1(m,:)';
rec = X2(m,:)';
% finding ray trajectory
v0 = rec-src;
vn = norm(v0);
v = v0/vn; %ray vector (normalized)
% tracing ray
points = src+v*linspace(0,steps,steps*mult); %stepping through ray trajectory, number of points should be large, includes endpoints
pcheck = sum((points-rec).^2); % finding intersection of ray with pixel
[u,i]=min(pcheck);
inds = floor(points(:,2:i)); % starts @ 2 since ray travels from source to receiver
npoints=length(inds);
xs=inds(1,:);
ys=inds(2,:);
ds_int = (vn/npoints); % length of ray/#points
indA = sub2ind(sc,ys',xs');
a0=zeros(1,lc);
for k = 1:length(xs)
a0(indA(k))=a0(indA(k))+ds_int; % one tomo matrix row
end
colInds=unique(indA);
av=[av;a0(colInds)']; % tomo mtx vector, much faster than indexing array
ii=[ii;m*ones(length(colInds),1)];
jj=[jj;colInds];
end
A=sparse(double(ii),double(jj),double(av),length(X1),length(sTrue(:)));
A=full(A);
Tarr = A*sTrue(:);
%% plotting slowness map and rays
figure(1)
clf % edge gap vertical horizontal
ha=tight_subplot(1,3,[0.01 0.02],[.22 .22],[.095 .05]);
axes(ha(1))
a = ha(1);
pos = get(a,'Position');
imagesc(sTrue,[0.3 0.5])
h=colorbar('northoutside');
set(a,'Position',pos) % fixing image size from colorbar addition
xlabel(h,'Slowness (s/km)')
xlabel('Range (km)')
ylabel('Range (km)')
set(gca,'Xtick',[1,20:20:100])
set(gca,'Ytick',[20:20:100])
axes(ha(2))
set(gca,'Ydir','reverse')
hold on
for m =1:length(X1)
plot([X1(m,1),X2(m,1)],[X1(m,2),X2(m,2)],'k')
end
plot(xSta,ySta,'rx','markersize',10,'linewidth',3)
axis([1 100 1 100])
hold off
set(gca,'Xticklabel',[])
set(gca,'Yticklabel',[])
box on
raysPerPix=reshape(sum(A~=0),size(sTrue));% calculating ray density
axes(ha(3))
a=ha(3);
pos = get(a,'Position');
imagesc(log10(raysPerPix))
h=colorbar('northoutside');
set(a,'Position',pos) % fixing image size from colorbar addition
xlabel(h,'Rays per pixel, log_{10} ')
axis([1 100 1 100])
hold off
set(gca,'Xticklabel',[])
set(gca,'Yticklabel',[])
box on
bigTitle=['Slowness map, stations and rays, ray density'];
axes(ha(1))
text(80,-30,bigTitle,'fontsize',16,'interpreter','latex')