1 |
function ncep2cubeWind |
2 |
% Interpolates NCEP data onto cubed sphere |
3 |
% for wind speed on tracer points. |
4 |
% Edit this script with path of NCEP data. |
5 |
|
6 |
% Location of NCEP monthly climatology files |
7 |
archivedir='/u/u2/cheisey/stephd/ncep'; |
8 |
disp(['Reading NCEP data from ',archivedir]); |
9 |
|
10 |
% data path for grids |
11 |
path='./'; |
12 |
|
13 |
% Load grids |
14 |
load FMT.mat |
15 |
load HGRID.mat nxc nyc lon_lo lon_hi lat_lo lat_hi xc yc zA GRID yg |
16 |
load MASKS |
17 |
if ndims(msk)==4 |
18 |
msk=msk(:,:,:,1); |
19 |
else |
20 |
msk=msk(:,:,1); |
21 |
end |
22 |
|
23 |
load TUV |
24 |
|
25 |
|
26 |
flist={'ncep_uwind_monthly.cdf','ncep_vwind_monthly.cdf'}; |
27 |
|
28 |
|
29 |
|
30 |
% load data |
31 |
ncepPath=fullfile(archivedir,flist{1}); |
32 |
ncload(ncepPath ); |
33 |
ncepPath=fullfile(archivedir,flist{2}); |
34 |
ncload(ncepPath ); |
35 |
|
36 |
|
37 |
|
38 |
% Rotate data in x so that it goes from -180 to 180 |
39 |
% instead of 0 to 360 |
40 |
xs=X-X(97); |
41 |
ys=Y; |
42 |
U = permute(sq(u),[3 2 1]); |
43 |
V = permute(sq(v),[3 2 1]); |
44 |
Ushift(97:192,:,:)=U(1:96, :,:); |
45 |
Ushift(1:96, :,:)=U(97:192, :,:); |
46 |
Vshift(97:192,:,:)=V(1:96, :,:); |
47 |
Vshift(1:96, :,:)=V(97:192, :,:); |
48 |
|
49 |
|
50 |
%Wrap one bin around |
51 |
Vshift(end+1, :,:) = Vshift(1,:,:); |
52 |
Ushift(end+1, :,:) = Ushift(1,:,:); |
53 |
xs(end+1)=(xs(end)-xs(end-1))+xs(end); |
54 |
|
55 |
|
56 |
% month to plot for sanity check |
57 |
imo=1; |
58 |
|
59 |
figure(1) |
60 |
imagesc(xs,ys,Ushift(:,:,imo)') |
61 |
set(gca,'yDir','normal'); |
62 |
colorbar('horiz') |
63 |
title(['X Wind speed (m/s) at trancer points for month ',num2str(imo)]) |
64 |
figure(2) |
65 |
imagesc(xs,ys, Vshift(:,:,imo)') |
66 |
set(gca,'yDir','normal'); |
67 |
title(['Y Wind speed (m/s) at trancer points for month ',num2str(imo)]) |
68 |
colorbar('horiz') |
69 |
|
70 |
|
71 |
|
72 |
% interpolate winds on the tracer points |
73 |
tx=redo(Ushift, xs,ys,yc,xc,msk); |
74 |
ty=redo(Vshift, xs,ys,yc,xc,msk); |
75 |
|
76 |
% Compute windspeed |
77 |
for jj=1:12, |
78 |
windSpeed(:,:,:,jj) = sqrt( tx(:,:,:,jj).^2 + ty(:,:,:,jj).^2); |
79 |
end |
80 |
|
81 |
|
82 |
|
83 |
% Rotate coordinates as necessary for each cubed-sphere tile |
84 |
for jj=1:12, |
85 |
|
86 |
Tx(:,:,:,jj)= TVv.*tx(:,:,:,jj)-TUv.*ty(:,:,:,jj); |
87 |
Ty(:,:,:,jj)=-TVu.*tx(:,:,:,jj)+TUu.*ty(:,:,:,jj); |
88 |
|
89 |
end |
90 |
|
91 |
% Permute indcies for cubed sphere 32x32x6x12 becomes 32x6x32x12 |
92 |
Ty=permute(Ty,[1 3 2 4 5]); |
93 |
Tx=permute(Tx,[1 3 2 4 5]); |
94 |
windSpeed=permute(windSpeed,[1 3 2 4 5]); |
95 |
|
96 |
|
97 |
fout=['ncep_uwind_cubed.bin']; |
98 |
wrda(fout,Ty,1,fmt,Ieee); |
99 |
stats(Tx) |
100 |
|
101 |
fout=['ncep_vwind_cubed.bin']; |
102 |
wrda(fout,Ty,1,fmt,Ieee); |
103 |
stats(Ty) |
104 |
|
105 |
fout=['ncep_windspeed_cubed.bin']; |
106 |
wrda(fout,windSpeed,1,fmt,Ieee); |
107 |
stats(windSpeed) |
108 |
|
109 |
figure(5) |
110 |
displaytiles( tiles( sq( reshape( windSpeed(:,:,:,imo),[32*6 32]) ) ,1:6)) |
111 |
title(['Wind sp (m/s), month ',num2str(imo)]) |
112 |
title(['Wind speed (m/s) at trancer points for month ',num2str(imo)]) |
113 |
|
114 |
|
115 |
|
116 |
figure(3) |
117 |
displaytiles( tiles( sq( reshape( Tx(:,:,:,imo),[32*6 32]) ) ,1:6)) |
118 |
title(['X Wind sp (m/s), month ',num2str(imo)]) |
119 |
figure(4) |
120 |
displaytiles( tiles( sq( reshape( Ty(:,:,:,imo),[32*6 32]) ) ,1:6)) |
121 |
title(['Y Wind sp (m/s), month ',num2str(imo)]) |
122 |
return |
123 |
|
124 |
|
125 |
|
126 |
function Q=redo(Qshi, xs,ys,yc,xc,msk) |
127 |
|
128 |
|
129 |
for jj=1:12, |
130 |
for t=1:size(xc,3); |
131 |
Q(:,:,t,jj)=interp2(ys,xs,sq(Qshi(:,:,jj)),yc(:,:,t),xc(:,:,t)) .*msk(:,:,t); |
132 |
end |
133 |
end |
134 |
Q( isnan(Q) )=0; |
135 |
|
136 |
return |
137 |
|
138 |
|
139 |
|