Lab 4

advertisement
Name __________________________
Oceanographic & Meteorological Quantitative Methods – SO335 Lab 4 – (100 pts)
*All code written for this lab should be contained in an appropriately commented script file that
is handed in upon completion of the lab.
Objectives:
At the conclusion of this lab, you should be able to:
(1) Better understand the application of the del operator  to the concept of advection
(2) Calculate, plot, and interpret streamlines, streamfunction, and velocity potential.
(3) Use MATLAB to accomplish objectives (1) and (2).
I. Temperature advection
1. Before we calculate and plot temperature advection, let’s first become more familiar with
temperature and wind fields on 21 September 2014. Raw (gridded) data are available on the
course web site in the data file lab4.mat. Use the contourf function to plot color-filled contours of
850 hPa temperature, with 20 color contours. Overlay the vector wind field at 850 hPa (black
arrows, scaled by 2). Add the coastline (coastline.mat on the course web site, if you don’t want
to re-load lab1.mat), set the color range from 220 K to 300 K, add a colorbar, and add
appropriate titles and axis labels.
2. Now, plot filled contours of temperature advection at 850 hPa for 21 September 2014. Recall
that advection  u T . It may help you to work out the dot product of temperature advection
in the space provided here (use the algebraic, not the geometric, definition).
For this figure, overlay vector wind field onto temperature advection field (still for 850 hPa). Use
20 color contours, set the color range from -50 to 50, and add appropriate axis labels and a title.
Be sure to put the proper units of the color-filled contours in the title (what are the units of
advection in this case?).
Temperature advection is a somewhat noisy field, but we’re mainly interested in the non-zero
parts of advection. Thus, let’s use the colormap function in MATLAB to make the middle (zero)
colors white instead of green. The default colormap is jet(64) – 64 colors “jetting” from red
(high values) to blue (low values), with green in the middle. Let’s create a slimmed down
version by adding the following line to your script:
newcolors = jet(20);
1
Double-click on “newcolors” and look at it in MATLAB. It should be 20 rows by 3 columns. All
MATLAB colors are in “red-green-blue” (or RGB) format. We want the middle colors (which
are in rows 10 and 11 of the 20-row variable) to be white. In RGB format, white is [1 1 1] (or
100% red, 100% green, and 100% blue; black would be [0 0 0]). To make rows 10 and 11 white,
add the following to your script:
newcolors(10,1:3) = [1 1 1];
newcolors(11,1:3) = [1 1 1];
%Now make the colormap be "newcolors" instead of jet(64)
colormap(newcolors);
If you wanted to revert back to the default color map (e.g., for the rest of this lab and for other
labs), you would need to execute
colormap('default')
Re-plot Figure 2, still with 20 contours, color range from -50 to 50, but this time with the new
color map. Notice that the regions of small (close to zero) temperature advection are now
colored white. This acts to highlight the areas of larger advection (reds and blues).
Finally (for enrichment purposes mainly), notice that you ask MATLAB to make 20 contours,
but then don't give it colors for the middle-most contour. You can fix that by replacing "20" with
the actual contours you'd like to see: [-50:5:-5 5:5:50]. You can replot Figure 2 to see the
results.
Deliverables: the deliverables from this task are two color printed figures and a oneparagraph write-up analyzing the temperature advection at 850 hPa on 21 September
2014. (40 pts)
II. Streamlines
In oceanography and meteorology, streamlines are an incredibly useful way to easily identify
important features in the fluid (gyres, divergence or convergence, fast flow, etc.). For this
section, we will jump to the upper troposphere and analyze 250 hPa. MATLAB (likely to no
surprise to you) has several functions that are handy in calculating and plotting streamlines. The
first function, streamline, is actually a little clunkier than the second one, streamslice. Thus, we’ll
be using streamslice.
1. Similar to Part I, before we start plotting streamlines, we need to orient ourselves to the data.
To do that, plot color-filled contours of wind speed at 250 hPa (color range from 0 to 90 m/s),
and overlay the 250 hPa wind vectors (black, scaled by 2). Add the coastline, an appropriate title
(with units), and appropriate axis labels. Spend a moment pondering the wind field.
2. Now, let’s turn to streamlines. Use the help function (or Google) to determine the best usage
of streamslice. Suggest using streamline density of 1.5. The function streamslice is a
plotting function (just line quiver is a plotting function), so when you execute it, it will try to
2
make some lines in a figure window. First plot the 250 hPa wind vectors, black and scaled by 2.
Then the streamslice function, with “h” serving as an output handle so we can change the
color, thickness, etc of the lines. Purple is provided for you, but
http://www.tayloredmktg.com/rgb/ (and many, many other sites) have a long list of RGB color
options. Most web sites give color ranges from 0-255, but MATLAB expects fractions from 0.0
to 1.1. Suggest the following syntax for the streamslice code:
figure(3)
clf
colormap('default')
hold on
quiver(...) %make black color & scale by 2
h=streamslice(...); %line density 1.5
streamlinecolor = [132 112 255]/255; %Gives a purple color
set(h,'linewidth',2,'color',streamlinecolor) %Thickness 2, color purple
line(...) %make black color & scale by 2
axis tight %gets rid of any extra white space in the figure window
title(...,'fontsize',20)
xlabel(...,'fontsize',20)
ylabel(...,'fontsize',20)
set(gca,'fontsize',20)
The figure window looked better when maximized, so the font sizes were upped to 20 to make
the numbers more readable.
Notice the relationship between the wind field (black arrows) and streamlines (purple lines).
Deliverables: one color printed figure and a paragraph describing the 250-hPa flow and
streamlines. (30 pts).
III. Streamfunction and velocity potential
In this final section of the lab, you will be calculating and then plotting the streamfunction 
(“psi”, pronounced as “sigh”) and the velocity potential  (“phi”, pronounced as “fee”).
Unfortunately, MATLAB does not have high-quality, built-in functions to calculate either
parameter. Fortunately, Dr. Kirill Pankratov of MIT and Univ California San Diego has done the
heavy lifting for us. Go to http://www-pord.ucsd.edu/~matlab/stream.htm and look at the web
site. At the bottom, you need to create two script files, flowfun.m and cumsimp.m, by copying /
pasting the code into two new m-files. The first m-file should be saved as “flowfun.m” in your
MATLAB directory. Line 1 of it should be function [phi,psi] = flowfun(u,v,flag), and
the last line should be the “if” statement. (Do not copy/paste the “=====” symbols!). Similar for
cumsimp.m.
Look at the flowfun.m script file, and particularly look at the top part (the comments), where Dr.
Pankratov has listed the suggested uses. This one, [PHI,PSI] = FLOWFUN(U,V), seems to be the
most appropriate.
3
Use flowfun.m to calculate streamfunction and velocity potential at 250 hPa. In two separate
figures, plot color-filled contours, and overlay the wind vectors (black, scaled as 2). Add a
colorbar, coastline, appropriate title, and appropriate axis labels, to each figure. For both, suggest
20 contours.
Look at the relationship between the streamfunction contours and the wind field. In the other
figure, look at the relationship between the velocity potential contours and the wind field.
*Important: in class, we discussed that certain restrictions on the flow are critical for the
existence of both  and  . Dr. Pankratov’s code, however, does not test for those restrictions,
and instead proceeds to calculate both streamfunction and velocity potential. In your write up,
you should discuss the validity of the results of these two figures. Particularly the velocity
potential: do you see any glaring discontinuities in the data? Remember, the world is round!
Deliverables: for this section, turn in two color-printed figures (one for streamfunction, one
for velocity potential), along with a one-paragraph analysis of the relationship between
streamfunction and wind, the relationship between velocity potential and wind, and any
potential errors (and the reasons for those errors) in the figures. (30 pts)
For all lab parts, you should also turn in appropriate, commented MATLAB code.
4
Download