-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvecupderivative.m
151 lines (131 loc) · 3.95 KB
/
vecupderivative.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
function varargout=vecupderivative(coefin,rnew,rold,Lmax,inv,Lrange)
% coefout=vecupderivative(coefin,rsat,rEarth,Lmax,inv,Lrange)
%
% Upward continue calculate derivative of scalar spherical harmonic
% expansion then expressed in coefficients of Elm:
% calculate cnew_{lm} = -cold_{lm}*sqrt((l+1)*(2*l+1))*rold^(-1)*(rnew/rold)^(-l-2)
%
% INPUT:
%
% coefin spherical harmonic coefficient vector or Matrix of point
% evaluations or matrix of coefficients in either addmout or
% addmon ordering for degrees 0 to Lmax. The lm cycling must be
% in the columns.
% These are the coefficients or point values for the scalar
% potential at altitude rold
% rsat Satellite radius for coefficients of radial field
% rEarth Earth radius for coeficients of potential field
% Lmax maximum degree
% inv up (0) or down (1)? (Handbook: A->0 , A^{-1}->1 )
% up also means derivative, down means integral
% Lrange all the L that are used if not all l,m combinations between 0
% and Lmax are included in the matrix (for example in sdwcapup)
% WARNING: Use correct Ls. Otherwise you seriously mess things
% up.
%
% OUTPUT:
%
% coefout spherical harmonic coefficient vector for Elm field at
% altitude rnew. Same format as coefin
%
% See also: RAD2POTINVERSION
%
% Last modified by plattner-at-alumni.ethz.ch, 04/28/2015
defval('Lrange',[])
defval('inv',0)
if ~ischar(coefin)
if ~isempty(Lrange)
%disp('WARNING: Using provided L range in vecupderivative')
bigl=Lrange(:);
else
[~,~,~,~,~,~,~,bigl]=addmon(Lmax);
end
if inv
% Actually we build B^(-1)
B=-rold*(rnew/rold).^(bigl+2)./sqrt((bigl+1).*(2*bigl+1));
else
B=-sqrt((bigl+1).*(2*bigl+1)).*(rold/rnew).^(bigl+2)/rold;
end
coefout=nan(size(coefin));
if (size(coefin,1)==length(bigl))
for i=1:size(coefin,2)
coefout(:,i)=B.*coefin(:,i);
end
else
error('Wrong number of entries or not column vector')
end
varns={coefout};
varargout=varns(1:nargout);
elseif strcmp(coefin,'demo1')
% Upward continuation and gradient for a Slepian function
index=2;
dom='africa';%30
Lmax=30;
rad_E=6371;
a=3000;
res=1;
plottype=2;
% Get the Slepian coefficients
[H,S]=gradvecglmalpha(dom,Lmax);
if ~isstr(dom)
[S,isrt]=sort(S,2);
S=fliplr(S);
H=H(:,fliplr(isrt));
end
% And transform the spherical harmonic sequence into the ADDMON format
H=out2on(H,Lmax);
GVSfcoef=H(:,index);
upGVSfcoef=vecupderivative(GVSfcoef,rad_E+a,rad_E,Lmax,0);
% Now evaluate on regular grid
lon=(0:res:360)*pi/180;%(-180:res:180)*pi/180;
lat=(1:res:180-1)*pi/180;
lonp=lon;
latp=lat;
[lon,lat]=meshgrid(lonp,latp);
lo=lon(:);
la=lat(:);
[E,theta,phi]=elm(Lmax,la,lo-pi,1);
E{1}=out2on(E{1},Lmax);
E{2}=out2on(E{2},Lmax);
E{3}=out2on(E{3},Lmax);
fvals{1}=reshape(E{1}'*GVSfcoef,length(latp),length(lonp));% rad
fvals{2}=reshape(E{2}'*GVSfcoef,length(latp),length(lonp));% th
fvals{3}=reshape(E{3}'*GVSfcoef,length(latp),length(lonp));% ph
fvalsup{1}=reshape(E{1}'*upGVSfcoef,length(latp),length(lonp));% rad
fvalsup{2}=reshape(E{2}'*upGVSfcoef,length(latp),length(lonp));% th
fvalsup{3}=reshape(E{3}'*upGVSfcoef,length(latp),length(lonp));% ph
% plot:
% Eplot=reshape(E{1}(10,:),length(latp),length(lonp));
% plotplm(Eplot,lonp,pi/2-latp,2)
% Plot the upward continued on top of the Earth surface functions
subplot(2,3,1)
plotplm(fvalsup{1},lonp,pi/2-latp,plottype)
kelicol(1)
ax=max(abs(caxis));
caxis([-ax ax]);
subplot(2,3,2)
plotplm(fvalsup{2},lonp,pi/2-latp,plottype)
kelicol(1)
ax=max(abs(caxis));
caxis([-ax ax]);
subplot(2,3,3)
plotplm(fvalsup{3},lonp,pi/2-latp,plottype)
kelicol(1)
ax=max(abs(caxis));
caxis([-ax ax]);
subplot(2,3,4)
plotplm(fvals{1},lonp,pi/2-latp,plottype)
kelicol(1)
ax=max(abs(caxis));
caxis([-ax ax]);
subplot(2,3,5)
plotplm(fvals{2},lonp,pi/2-latp,plottype)
kelicol(1)
ax=max(abs(caxis));
caxis([-ax ax]);
subplot(2,3,6)
plotplm(fvals{3},lonp,pi/2-latp,plottype)
kelicol(1)
ax=max(abs(caxis));
caxis([-ax ax]);
end