-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquivpolcaps.m
84 lines (77 loc) · 2.31 KB
/
quivpolcaps.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
function varargout=quivpolcaps(data,del,renorm,lon,lat)
% [X,Y,Zx,Zy]=quivpolcaps(data,del,renorm,lon,lat)
%
% Quiver plot for polar cap regions transforms vectors using the
% transformation corresponding to PLOTPLM method 5
%
% INPUT:
%
% data data(:,:,1) is a 2d array containing the values of the vector
% field in longitudinal direction,(phi)
% data(:,:,2) is a 2d array containing the values of the vector
% field in latitudinal direction (theta)
% del do not plot all vectors with length below del*(max abs value)
% [default 0.05]
% renorm scale to maximum value (0) or multiply with the given value (if
% not zero)
% lon,lat positions, in radians
%
% OUTPUT:
%
% X X Positions of the vectors in the XY coordinates looking from above
% down to the polar cap
% Y Y Positions of the vectors
% Zx Vector value in x-direction
% Zy Vector value in y-direction
%
% See also DSPH2DCART, CAPVECTORSLEPIAN
%
% Last modified by plattner-at-alumni.ethz.ch, 05/09/2017
defval('lon',linspace(0,2*pi,size(data,2)));
defval('lat',linspace(pi/2,0,floor(size(data,1)/2)));% Only takes top half
defval('del',0.05)
defval('renorm',[]);
[LON,LAT]=meshgrid(lon,lat);
% Radius from 0 to 1; longitude is azimuth
r=cos(LAT);
x=r.*cos(LON);
y=r.*sin(LON);
Xpos=linspace(-1,1,length(lat));
Ypos=linspace(1,-1,length(lat));
y(1,:)=y(2,:)/2;
x(1,:)=x(2,:)/2;
phi=griddata(x,y,data(1:length(lat),:,1),Xpos,Ypos(:));
th =griddata(x,y,data(1:length(lat),:,2),Xpos,Ypos(:));
[X,Y]=meshgrid(Xpos,Ypos);
X=X(:); Y=Y(:); dphi=phi(:); dth=th(:);
% Get PHI, TH for the new points
PHI=NaN(size(X));TH=NaN(size(Y));
for i=1:length(X)
r=sqrt(X(i)^2 + Y(i)^2);
TH(i)=acos(r);
if(Y(i)>=0)
PHI(i)=acos(X(i)/r);
else
PHI(i)=acos(-X(i)/r)+pi;
end
end
[Zx,Zy,Zz]=dsph2dcart(PHI,TH,dphi,dth,zeros(size(PHI)));
% Here, take out the small values
absdata2=sqrt(Zx.^2 + Zy.^2);
maxab=max(max(absdata2));
ind=find(absdata2<del*maxab);
indNaN=find(isnan(absdata2));
ind=[ind;indNaN];
X(ind)=[]; Y(ind)=[]; Zx(ind)=[]; Zy(ind)=[];
if isempty(renorm)
h=quiver(X,Y,Zx,Zy,'ko');
else
h=quiver(X,Y,Zx,Zy,renorm,'ko');
end
xlim([-1 1]);
ylim([-1 1]);
axis square
set(h,'LineWidth',0.5)
set(h,'MarkerSize',1.5)
varns={X,Y,Zx,Zy};
varargout=varns(1:nargout);