NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/DPWavesProc/trunk/DPWavesProc/adcp_matlab/radialwaveplot.m

Revision 215 (checked in by gdusek, 16 years ago)

--

Line 
1 function [E_radial_WI,I_radial_WI,fig5,fig6]=radialwaveplot(radialE,radialI,spec,sysinfo)
2
3 %make sure to load the EMEP, IMLM and wavesmon samples
4 %EMEP=load('emep'), IMLM=load('imlm'), spec=load('wavesmon')
5 %rangeE=load('EMEP_range'), rangeI=load('IMLM_range')
6
7 %set up the wavesmon data in a structure
8
9 %what is the magnetic variation to nearest degree
10 magvar=10;
11
12 %first change to m^2/Hz/deg
13 wmon.S=spec/(360*1000*1000);
14
15 %what is the start angle
16 heading=sysinfo(18,:);
17 heading=heading/100;
18 sangle=heading+magvar;
19
20 %what is the frequency and dir resolution for those generated in DIWASP
21 freqres=0.01;
22 freqs=[0.01:0.01:.4];
23 dirres=2;
24 dirs=[-180:2:180];
25
26 %set up the directions
27 adj_angle=90-sangle+360+180;
28 wmon.dirs=[adj_angle:-4:-(356-adj_angle)];
29 wmondirres=4;
30 wmon.xaxisdir=90;
31 wmon.freqs=[0.00781250:0.00781250:1];
32 wmonfreqres=0.00781250;
33
34 % plot the spectrum generated through DIWASP
35 scrsz = get(0,'ScreenSize');
36 fig5=figure('Position',[scrsz]);
37 subplot(2,3,1);
38 subplotspec(radialE,4);
39 title('EMEP radial vel');
40
41 subplot(2,3,2);
42 subplotspec(radialI,4);
43 title('IMLM radial vel');
44
45 subplot(2,3,3);
46 subplotspec(wmon,4);
47 title('Wavesmon output');
48
49
50 %calculate just the dir energy spectrum on a single graph
51
52 EMEPdir=sum(radialE.S)*freqres;
53 IMLMdir=sum(real(radialI.S))*freqres;
54 wmondir=sum(wmon.S)*wmonfreqres;
55
56 %calculate just the frequency energy spectrum
57 EMEPfreq=sum(radialE.S')*dirres;
58 IMLMfreq=sum(real(radialI.S)')*dirres;
59 wmonfreq=sum(wmon.S')*wmondirres;
60
61 %Compute the coefficient for the upper and lower error bounds for the
62 %frequency
63 %spectrum assuming 95% confidence.  Added on 9/17/08
64 degF=radialE.degF;
65 chiUp=chi2inv(.975,degF);
66 chiLow=chi2inv(.025,degF);
67 coeffUp=degF/chiLow;
68 coeffLow=degF/chiUp;
69
70 %calculate the conf limits throughout the frequency spectrum
71 EMEPfreqUP=EMEPfreq*coeffUp;
72 EMEPfreqLOW=EMEPfreq*coeffLow;
73
74 %Find the maximum for the directional spectrum so we can set up the proper
75 %x-axis
76 [maxvalue,maxindex] = max(EMEPdir);
77 maxdir=dirs(maxindex);
78 % set up the x-axis for all of the spectra depending on the max
79 if ((100 < maxdir) | (maxdir < -100));
80     %for diwasp spectra
81     index1=find(dirs < 0);
82     index2=find(dirs > -1);
83     dirs(index1)=dirs(index1) +360;
84     %for wavesmon
85     Aindex=find(wmon.dirs < 0);               
86     Bindex=find((-1 < wmon.dirs) & (wmon.dirs < 361));
87     Bindex2=find(wmon.dirs > 360);
88     wmon.dirs(Bindex2)=wmon.dirs(Bindex2)-360;
89     wmon.dirs(Aindex)=wmon.dirs(Aindex)+360;
90     %plot the directional energy spectrum
91     fig6=figure('Position',[scrsz]);
92     subplot(1,2,1);
93     h1 = plot(dirs(index2),EMEPdir(index2),'b');
94     hold on
95     h1a= plot(dirs(index1),EMEPdir(index1),'b');
96     %plot the wavesmon data
97     h2 = plot(wmon.dirs(Bindex2),wmondir(Bindex2),'k');
98     h2a = plot(wmon.dirs(Bindex),wmondir(Bindex),'k');
99     h2b= plot(wmon.dirs(Aindex),wmondir(Aindex),'k');
100     axis(axis);
101     %h5 = plot(dirs(index2),IMLMdir(index2),'c');
102     %h5a= plot(dirs(index1),IMLMdir(index1),'c');
103
104 else
105     %for diwasp spectra do nothing
106    
107     %for wavesmon
108     Aindex=find(wmon.dirs > 180);
109     Bindex=find(wmon.dirs < 181);
110     wmon.dirs(Aindex)=wmon.dirs(Aindex)-360;
111     %plot the directional energy spectrum
112     fig6=figure('Position',[scrsz]);
113     subplot(1,2,1);
114     h1 = plot(dirs,EMEPdir,'b');
115     hold on
116     %plot the wavesmon data
117     h2 = plot(wmon.dirs(Aindex),wmondir(Aindex),'k');
118     h2a = plot(wmon.dirs(Bindex),wmondir(Bindex),'k');
119     axis(axis);
120     %h5 = plot(dirs,IMLMdir,'c');
121 end
122
123 legend([h1, h2], 'EMEP radial vel','wavesmon','location','best');
124 title('directional wave spectrum integrated over frequency');
125 xlabel('axis angle (degrees true)');
126 ylabel('m^2 / deg');
127
128 %plot the frequency energy spectrum
129 subplot(1,2,2);
130 h1 = plot(freqs,EMEPfreq,'b');
131 hold on
132 h2 = plot(freqs,EMEPfreqLOW,'b--');
133 h3 = plot(freqs,EMEPfreqUP,'b--');
134 h4 = plot(wmon.freqs,wmonfreq,'k');
135 axis(axis);
136 %h5 = plot(freqs,IMLMfreq,'c');
137 legend([h1,h2,h4],'EMEP radial vel','EMEP radial 95% conf limits', 'wavesmon','location','best');
138 title('directional wave spectrum integrated over direction');
139 xlabel('frequency in Hz');
140 ylabel('m^2 / Hz');
141
142 % ______Calculate and display the wave parameters SigH, Tp, Dp,DTp_______
143
144 %For EMEP radial
145
146 %calculate the 0,1,2 moments
147 m0=sum(EMEPfreq*freqres);                             
148 m1=sum(freqs.*EMEPfreq*freqres);
149 m2=sum((freqs.^2).*EMEPfreq*freqres);
150 % Calculate the Sig wave height
151 EMEP_radial_Hsig=4*sqrt(m0);
152 %Use the function HsigConf.m to calculate the sigH confidence limits
153 EMEP_HsConf=HsigConf(radialE);
154
155 % Calculate the peak period Tp
156 [P,I]=max(EMEPfreq);
157 EMEP_radial_Tp=1/(freqs(I));
158
159 %Calculate the Direction of the peak period DTp
160 [P,I]=max(real(radialE.S(I,:)));
161 EMEP_radial_DTp=dirs(I);
162
163 %Calculate the Dominant Direction Dp
164 [P,I]=max(EMEPdir);
165 EMEP_radial_Dp=dirs(I);
166
167 %Display on the screen the SigH,Tp,Dp,DTp
168 disp(['EMEP radial vel']);
169 disp(['SigH (meters): ' num2str(EMEP_radial_Hsig)]);
170 disp(['SigH 95% confidence limits: ' num2str(EMEP_HsConf)]);
171 disp(['peak period (seconds): ' num2str(EMEP_radial_Tp)]);
172 disp(['Dir of peak period: ' num2str(compangle(EMEP_radial_DTp, radialE.xaxisdir))]);
173 disp(['Dominant Direction: ' num2str(compangle(EMEP_radial_Dp, radialE.xaxisdir))]);
174 disp(['  ']);
175
176 E_radial_WI.hsig=EMEP_radial_Hsig;
177 E_radial_WI.hconf=EMEP_HsConf;
178 E_radial_WI.tp=EMEP_radial_Tp;
179 E_radial_WI.dtp=compangle(EMEP_radial_DTp, radialE.xaxisdir);
180 E_radial_WI.dp=compangle(EMEP_radial_Dp, radialE.xaxisdir);
181
182 % For IMLM r
183
184 %calculate the 0,1,2 moments
185 m0=sum(IMLMfreq*freqres);                             
186 m1=sum(freqs.*IMLMfreq*freqres);
187 m2=sum((freqs.^2).*IMLMfreq*freqres);
188 % Calculate the Sig wave height
189 IMLM_radial_Hsig=4*sqrt(m0);
190 %Use the function HsigConf.m to calculate the sigH confidence limits
191 IMLM_HsConf=HsigConf(radialI);
192
193 % Calculate the peak period Tp
194 [P,I]=max(IMLMfreq);
195 IMLM_radial_Tp=1/(freqs(I));
196
197 %Calculate the Direction of the peak period DTp
198 [P,I]=max(real(radialI.S(I,:)));
199 IMLM_radial_DTp=dirs(I);
200
201 %Calculate the Dominant Direction Dp
202 [P,I]=max(IMLMdir);
203 IMLM_radial_Dp=dirs(I);
204
205 %Display on the screen the SigH,Tp,Dp,DTp
206 disp(['IMLM radial vel']);
207 disp(['SigH (meters): ' num2str(IMLM_radial_Hsig)]);
208 disp(['SigH 95% confidence limits: ' num2str(IMLM_HsConf)]);
209 disp(['peak period (seconds): ' num2str(IMLM_radial_Tp)]);
210 disp(['Dir of peak period: ' num2str(compangle(IMLM_radial_DTp, radialI.xaxisdir))]);
211 disp(['Dominant Direction: ' num2str(compangle(IMLM_radial_Dp, radialI.xaxisdir))]);
212 disp(['  ']);
213
214 I_radial_WI.hsig=IMLM_radial_Hsig;
215 I_radial_WI.hconf=IMLM_HsConf;
216 I_radial_WI.tp=IMLM_radial_Tp;
217 I_radial_WI.dtp=compangle(IMLM_radial_DTp, radialI.xaxisdir);
218 I_radial_WI.dp=compangle(IMLM_radial_Dp, radialI.xaxisdir);
219
220 % for wavesmon
221
222 %calculate the 0,1,2 moments
223 m0=sum(wmonfreq*wmonfreqres);                             
224 m1=sum(wmon.freqs.*wmonfreq*wmonfreqres);
225 m2=sum((wmon.freqs.^2).*wmonfreq*wmonfreqres);
226 % Calculate the Sig wave height
227 Hsig=4*sqrt(m0);
228
229 % Calculate the peak period Tp
230 [P,I]=max(wmonfreq);
231 Tp=1/(wmon.freqs(I));
232
233 %Calculate the Direction of the peak period DTp
234 [P,I]=max(real(wmon.S(I,:)));
235 DTp=wmon.dirs(I);
236
237 %Calculate the Dominant Direction Dp
238 [P,I]=max(wmondir);
239 Dp=wmon.dirs(I);
240
241 %Display on the screen the SigH,Tp,Dp,DTp
242 disp(['Wavesmon output']);
243 disp(['SigH (meters): ' num2str(Hsig)]);
244 disp(['peak period (seconds): ' num2str(Tp)]);
245 disp(['Dir of peak period: ' num2str(compangle(DTp, wmon.xaxisdir))]);
246 disp(['Dominant Direction: ' num2str(compangle(Dp, wmon.xaxisdir))]);
247 disp(['  ']);
248
249
250 %function to change from axis angles to compass bearings
251
252 function angle=compangle(angle,xaxisdir)
253 angle=xaxisdir*ones(size(angle))-angle;
254 angle=angle+360*(angle<0);
255 angle=angle-360*(angle>360);
256
257
258
259
260
Note: See TracBrowser for help on using the browser.