-
Notifications
You must be signed in to change notification settings - Fork 19
/
integratebasis.m
152 lines (138 loc) · 4.31 KB
/
integratebasis.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
function varargout=integratebasis(CC,TH,J,phi,theta)
% [eigfunINT]=INTEGRATEBASIS(CC,TH,J)
%
% Accepts a Slepian basis and integrates the functions within a region.
% The integrals reported are in fractional sphere area. You may want to
% convert this to real sphere area via x(4*pi*radius^2).
%
% INPUT:
%
% CC The eigenfunctions. This can be either the G you get from
% GLMALPHA or a cell array of the functions as in LOCALIZATION.
% TH The region. Can be formatted multiple ways as in GLMALPHA
% J How many functions you want to do this for [DEFAULT: all]
% phi Longitude of the center (degrees)
% theta Colatitude of the center (degrees)
% Note: there is no omega here because a rotation of the
% polar cap functions does not affect their integration
%
% OUTPUT:
%
% eigfunINT The integrals of the eigenfunctions over the region. These
% are in real sphere area, depending on your radius.
%
%
% SEE ALSO: PLM2AVG, PLM2AVGP
%
%
% Last modified by charig-at-email.arizona.edu, 11/01/2016
defval('TH','africa')
defval('CC','[~,CC]=localization(15,TH);');
defval('phi',0)
defval('theta',0)
%%%
% Initilization
%%%
% Sort out what CC is
if isstr(CC)
% Evaluate the specified expression
eval(CC);
end
if isfloat(CC)
% We must have a G matrix from glmalpha (already sorted)
% Reorder them into a cell array
[n,m] = size(CC);
defval('J',m);
L = sqrt(n) - 1;
% This should be an integer
if (floor(L)~=L);
error('Something fishy about your L');
end
[~,~,~,lmcosi,~,~,~,~,~,ronm]=addmon(L);
% Collect the eigenvector output into a format that PLM2XYZ knows how to interpret
for j=1:J
% Create the blanks
cosi=lmcosi(:,3:4);
% Stick in the coefficients of the 1st eigentaper
cosi(ronm)=CC(:,j);
% Construct the full matrix
CC2{j} = [lmcosi(:,1:2) cosi];
end
CC = CC2;
elseif iscell(CC)
% We are all good, just get the size.
[n,m] = size(CC);
defval('J',m);
defval('L',addmup(size(CC{1},1),'r'));
else
error('What format is CC?');
end
% Now sort out what TH is
if isstr(TH) % Geographic, we just do it
% Lets check if we need to do a rotation. The function for your
% coordinates should have this functionality if it's needed.
defval('rotb',0);
try
rotb=eval(sprintf('%s(''rotated'')',TH));
end
% Now do the rotation if needed
if length(rotb)==1 && rotb
% Get the rotation parameters to rotate. Note, the region
% rotation angles that we return from the functions (lonc, latc)
% are the same regardless of if we did a buffer, as they pertain
% to the original region
[XY,lonc,latc]=eval(sprintf('%s(%i)',TH,10));
[thetap,phip,rotmats]=rottp((90-XY(:,2))*pi/180,XY(:,1)*pi/180,-lonc*pi/180,latc*pi/180,0);
lonp = phip*180/pi;
latp = 90-thetap*180/pi;
[latf,lonf] = flatearthpoly(latp,lonp);
XY=[lonf latf];
else
% No changes
XY=TH;
end
elseif iscell(TH) % Geographic + buffer
defval('buf',0);
dom=TH{1}; buf=TH{2};
defval('pars',10);
% Lets check if we need to do a rotation. The function for your
% coordinates should have this functionality if it is needed.
defval('rotb',0);
try
rotb=eval(sprintf('%s(''rotated'')',dom));
end
% Now do the rotation if needed
if length(rotb)==1 && rotb
% Return the coordinates and do the rotation
[XY,lonc,latc]=eval(sprintf('%s(%i,%f)',TH{1},10,TH{2}));
[thetap,phip,rotmats]=rottp((90-XY(:,2))*pi/180,XY(:,1)*pi/180,-lonc*pi/180,latc*pi/180,0);
lonp = phip*180/pi;
latp = 90-thetap*180/pi;
[latf,lonf] = flatearthpoly(latp,lonp);
XY=[lonf latf];
else
XY=eval(sprintf('%s(%i,%f)',dom,pars,buf));
end
elseif isfloat(TH) && length(TH)==1
% We have Polar caps
XY = [ [1:360]' repmat(90-TH,360,1) ];
[thetap,phip,rotmats]=rottp((90-XY(:,2))*pi/180,XY(:,1)*pi/180,0,-theta*pi/180,-phi*pi/180);
lonp = phip*180/pi;
latp = 90-thetap*180/pi;
XY=[lonp latp];
else
% Must be straight coordinates
XY=TH;
end
% Initilization complete
%%%
% Do it
%%%
% Run parallel is we are able
parfor h=1:J
[Int,A]=plm2avg(CC{h},XY);
eigfunINT(h) = Int;
end
% Collect output
varns={eigfunINT};
varargout=varns(1:nargout);