Subversion Repositories lagranto.wrf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 michaesp 1
% ----------------------------------------------------------------------
2
% Plotting of a set of trajectory, coloring with additional field
3
% ----------------------------------------------------------------------
4
 
5
function plot = plot_trajectory (tra,varargin)
6
 
7
% Set plotting mode
8
mode=3;
9
 
10
% Handle the input arguments
11
if ( length(varargin) == 0 ) 
12
    col.name = 'none';
13
    pts      = [];
14
elseif ( length(varargin) == 1 )
15
    col      = varargin{1};
16
    pts      = [];
17
elseif ( length(varargin) == 2 )
18
    col      = varargin{1};
19
    pts      = varargin{2};
20
else
21
    error('Invalid call to plot_trajectory...');
22
end
23
 
24
% Set the selection of the trajectories
25
fn = fieldnames(tra);
26
if ( any ( strcmp(fn,'select') ) )
27
    tralist = tra.select;
28
else
29
    tralist = (1:tra.ntra)';
30
end
31
 
32
% Set some default parameters
33
fn = fieldnames(col);
34
if ( ~ any ( strcmp(fn,'shift') ) )
35
    col.shift = 47;
36
end
37
if ( ~ any ( strcmp(fn,'name') ) )
38
    col.name = 'col_table.txt';
39
end
40
if ( ~ any ( strcmp(fn,'orientation') ) )
41
    col.orientation = 'vert';
42
end
43
if ( ~ any ( strcmp(fn,'field') ) )
44
    col.field = 'p';
45
end
46
if ( ~ any ( strcmp(fn,'spacing') ) )
47
    fld = tra.(char(col.field));
48
    col.spacing = round(linspace(min(fld(:)),max(fld(:)),10));
49
end
50
 
51
% Get the orientation (order of values) of the colormap
52
n    = length(col.spacing);
53
diff = col.spacing(1:n-1)-col.spacing(2:n);
54
if ( all(diff >= 0) )
55
    order = 'reverse';
56
elseif ( all(diff <= 0) )
57
    order = 'normal';
58
else
59
    error('Invalid color spacing...');
60
end
61
 
62
% Set colormap
63
if ( ~ strcmp(col.name,'none') ) 
64
     c_map = col_scale(col.spacing,col.spacing);
65
     col_load(col.name,c_map.xtick,col.shift);
66
     c_map.colors = colormap;
67
     c_map.ncol = length(c_map.colors)
68
end
69
 
70
% ------- Plotting mode 1 -----------------------------------------------------------
71
if ( mode == 1) 
72
 
73
  for j=tralist'
74
 
75
  % Extract a single trajectory  
76
  tim = tra.time              (tra.label==j);
77
  lat = tra.lat               (tra.label==j);
78
  lon = tra.lon               (tra.label==j);
79
  fld = tra.(char(col.field)) (tra.label==j);
80
 
81
  % Draw the trajectory (either as a black line or colored with a field)
82
  for k=2:tra.ntime
83
    if ( abs(lon(k-1)-lon(k)) < 180 ) 
84
 
85
      if ( strcmp(col.name,'none') ) 
86
         [h]=linem([ lat(k-1) lat(k) ],[ lon(k-1) lon(k) ],'k','Linewidth',  1.0);
87
      else
88
         [h]=linem([ lat(k-1) lat(k) ],[ lon(k-1) lon(k) ],'k','Linewidth',  1.0);
89
         if ( strcmp(order,'normal') ) 
90
     	    icol=sum( 0.5*(fld(k-1)+fld(k)) > col.spacing );
91
         else
92
            icol=sum( 0.5*(fld(k-1)+fld(k)) < col.spacing );
93
         end
94
         if ( (icol>=1) & (icol <= c_map.ncol) )
95
	        set(h,'color',[c_map.colors(icol,1) c_map.colors(icol,2) c_map.colors(icol,3)]);
96
         else
97
            set(h,'color','k');
98
            set(h,'Linestyle',':');
99
         end
100
      end
101
 
102
    end
103
  end
104
 
105
  % Set time markers
106
  for k=1:length(pts)
107
     mask = (tim == pts(k) );
108
     if ( any(mask) ) 
109
        linem([ lat(mask) ],[ lon(mask) ],'marker','o', ...
110
              'markersize',5,'color','k','MarkerEdgeColor',[.4 .4 .4], ...
111
	          'MarkerFaceColor','k');
112
     end
113
  end
114
 
115
  end
116
 
117
end
118
 
119
% ------- Plotting mode 2 -----------------------------------------------------------
120
if ( mode == 2) 
121
 
122
  for j=tralist'
123
 
124
  % Extract a single trajectory  
125
  tim = tra.time              (tra.label==j);
126
  lat = tra.lat               (tra.label==j);
127
  lon = tra.lon               (tra.label==j);
128
  fld = tra.(char(col.field)) (tra.label==j);
129
 
130
  % Extract coordinates 
131
  lat1 = lat(2:tra.ntime);
132
  lat2 = lat(1:(tra.ntime-1));
133
  lon1 = lon(2:tra.ntime);
134
  lon2 = lon(1:(tra.ntime-1));
135
 
136
  % Get the color code for the line segments
137
  if ( strcmp(col.name,'none') ) 
138
    icol = zeros(size(fld1));
139
  else
140
    fld1 = fld(2:tra.ntime);
141
    fld2 = fld(1:(tra.ntime-1));
142
    ccol = kron(col.spacing,ones(size(fld1)));
143
    cfld = kron(0.5*(fld1+fld2),ones(size(col.spacing)));
144
    if ( strcmp(order,'normal') ) 
145
       icol = sum( cfld > ccol, 2);
146
    else
147
       icol = sum( cfld < ccol, 2);
148
    end
149
    icol( (icol<1) | (icol>c_map.ncol) ) = -1;
150
  end    
151
 
152
  % Draw colored line segments (loop through all colors)
153
  for i=1:c_map.ncol
154
     mask = (icol == i);
155
     if ( any(mask) ) 
156
  %      [h]=linem( [ lat1(mask) lat2(mask) ],[ lon1(mask) lon2(mask) ],'k','Linewidth',  1.0);
157
        [h]=linem( [ lat1(mask) lat2(mask) ]',[ lon1(mask) lon2(mask) ]','k','Linewidth',  1.0);
158
        set(h,'color',[c_map.colors(i,1) c_map.colors(i,2) c_map.colors(i,3)])
159
     end
160
  end
161
 
162
  % Draw line sgements outside the color range
163
  mask = (icol == -1);
164
  if ( any(mask) ) 
165
      [h]=linem([ lat1(mask) lat2(mask) ]',[ lon1(mask) lon2(mask) ]','k','Linewidth',  1.0);
166
      set(h,'color','r');
167
      set(h,'Linestyle','-');
168
  end
169
 
170
  % Draw black line segments (if no color is needed)
171
  mask = (icol == 0);
172
  if ( any(mask) ) 
173
      [h]=linem([ lat1(mask) lat2(mask) ]',[ lon1(mask) lon2(mask) ]','k','Linewidth',  1.0);
174
  end
175
 
176
  % Set time markers
177
  for k=1:length(pts)
178
     mask = (tim == pts(k) );
179
     if ( any(mask) ) 
180
        linem([ lat(mask) ],[ lon(mask) ],'marker','o', ...
181
              'markersize',5,'color','k','MarkerEdgeColor',[.4 .4 .4], ...
182
	          'MarkerFaceColor','k');
183
     end
184
  end
185
 
186
  end 
187
end
188
 
189
% ------- Plotting mode 2 -----------------------------------------------------------
190
if ( mode == 3 ) 
191
 
192
  % Set the total number of coordinates
193
  n = tra.ntime * tra.ntra;  
194
 
195
  % Extract trajectories  
196
  tim = tra.time;
197
  lat = tra.lat;
198
  lon = tra.lon;
199
  fld = tra.(char(col.field));
200
 
201
  % Mark different trajectories
202
  gaps = (1:tra.ntra) * tra.ntime;
203
  lat( gaps ) = NaN;
204
  lon( gaps ) = NaN;
205
 
206
  % Extract coordinates 
207
  lat1 = lat(2:n);
208
  lat2 = lat(1:(n-1));
209
  lon1 = lon(2:n);
210
  lon2 = lon(1:(n-1));
211
 
212
  % Get the color code for the line segments
213
  if ( strcmp(col.name,'none') ) 
214
    icol = zeros(size(fld1));
215
  else
216
    fld1 = fld(2:n);
217
    fld2 = fld(1:(n-1));
218
    ccol = kron(col.spacing,ones(size(fld1)));
219
    cfld = kron(0.5*(fld1+fld2),ones(size(col.spacing)));
220
    if ( strcmp(order,'normal') ) 
221
       icol = sum( cfld > ccol, 2);
222
    else
223
       icol = sum( cfld < ccol, 2);
224
    end
225
    icol( (icol<1) | (icol>c_map.ncol) ) = -1;
226
  end    
227
 
228
  % Draw colored line segments (loop through all colors)
229
  for i=1:c_map.ncol
230
     mask = (icol == i);
231
     if ( any(mask) ) 
232
        [h]=linem( [ lat1(mask) lat2(mask) ]',[ lon1(mask) lon2(mask) ]','k','Linewidth',  1.0);
233
        set(h,'color',[c_map.colors(i,1) c_map.colors(i,2) c_map.colors(i,3)])
234
     end
235
  end
236
 
237
  % Draw line sgements outside the color range
238
  mask = (icol == -1);
239
  if ( any(mask) ) 
240
      [h]=linem([ lat1(mask) lat2(mask) ]',[ lon1(mask) lon2(mask) ]','k','Linewidth',  1.0);
241
      set(h,'color','r');
242
      set(h,'Linestyle','-');
243
  end
244
 
245
  % Draw black line segments (if no color is needed)
246
  mask = (icol == 0);
247
  if ( any(mask) ) 
248
      [h]=linem([ lat1(mask) lat2(mask) ]',[ lon1(mask) lon2(mask) ]','k','Linewidth',  1.0);
249
  end
250
 
251
  % Set time markers
252
  for k=1:length(pts)
253
     mask = (tim == pts(k) );
254
     if ( any(mask) ) 
255
        n = length(lat(mask));
256
        lat3( 1:(2*n) ) = NaN; lat3( 1:2:(2*n) ) = lat(mask);
257
        lon3( 1:(2*n) ) = NaN; lon3( 1:2:(2*n) ) = lon(mask);
258
        linem([ lat3 ],[ lon3 ],'marker','o', ...
259
              'markersize',5,'color','k','MarkerEdgeColor',[.4 .4 .4], ...%
260
	          'MarkerFaceColor','k');
261
     end
262
  end
263
end
264
 
265
% ------- Plotting colorbar -----------------------------------------------------------
266
 
267
if ( ~ strcmp(col.name,'none') ) 
268
   caxis(c_map.caxis);
269
   if ( strcmp(col.orientation,'hori') ) 
270
      q=colorbar('hori');
271
      set(q,'xtick',c_map.xtick,'XTickLabel',c_map.label);
272
   elseif ( strcmp(col.orientation,'vert') ) 
273
      q=colorbar('vert');
274
      set(q,'ytick',c_map.xtick,'YTickLabel',c_map.label);
275
   end
276
end
277
 
278
% Return status
279
plot = 1;