Basic Meteorological Variables, the Equation of State, and Time Series
Total Page:16
File Type:pdf, Size:1020Kb
SO 254 Spring 2017
SO254 Lab 1 Basic meteorological variables, the equation of state, and time series
Objectives: The objectives of this lab are to: 1. Familiarize yourself with common meteorological variables (air temperature, pressure, dew point temperature, wind speed) 2. Access NWS data online maintained at the National Centers for Environmental Information (NCEI) and get that data into MATLAB 3. Calculate air density using the equation of state 4. Plot basic atmospheric variables using MATLAB 5. Interpret time series plots 6. Write a coherent description of your lab activity
Overview: The basic state variables for the atmosphere are air temperature, air pressure, and air density, and these three variables are related to each other in the equation of state.
After Hurricane Isabel in 2003, USNA partnered with the NOAA National Weather Service to install an Automated Weather Observing Station (AWOS) on Hospital Point on the grounds of the Academy. The station was given identifier KNAK and has been operational since mid-2005. At that weather station, the following variables are recorded: air temperature, air dew point temperature, air pressure, wind speed, wind direction, visibility, cloud levels and coverage, and present weather.
In this lab, we are interested in the state variables (temperature, pressure, density) along with moisture variable (dew point temperature) and wind speed. Four of the five variables are measured directly at KNAK. The fifth, density, you must calculate using the equation of state.
Tasks:
1) Visit the National Centers for Environmental Information web site for land-based station data, https://www.ncdc.noaa.gov/data-access/land-based-station-data. Download available data for the month of January 2017 from KNAK in comma-delimited (separated) format (also known as CSV) by selecting “Datasets and Products”, “Quality Controlled Local Climatological Data” (select that option twice), then select Maryland, and finally Annapolis (station 13752/NAK). Choose the entire month (E) of January 2017, and download Hourly (10A) data in ASCII/CSV1 format.
Observe what data come to you on the subsequent page. Notice the formatting, the regularity, the column headers, etc.
1 ASCII stands for American Standard Code for Information Interchange. Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as 'a' or '@' or an action of some sort. Data in ASCII format is just 'plain' text with no formatting such as tabs, bold or underscoring - the raw format that any computer can understand. Utilizing ASCII format makes files easily importable into most applications without issues. (www.asciitable.com)
- 1 - SO 254 Spring 2017
2) MATLAB is very picky about what data it will accept as a variable. We thus need to clean up this CSV data provided by NOAA, to get it in a format usable by MATLAB. We choose to go through this somewhat tedious task, instead of simply making plots in Excel or a similar program, so that we can write scripts2 in MATLAB to reproduce our analysis. The scripting abilities in MATLAB, coupled with its incredibly powerful analysis tools, make it far superior to a low-level software package like Excel.
Copy the data that NOAA provided to you on its web page and paste the data into an Excel workbook (while lousy at calculations and scripting, Excel is quite good at textual data manipulation). Take a look at how the data look in Excel. The first few rows (1-7) are metadata3. Row 8 is a header. Rows 9 to the end contain the actual meteorological data. We do not want the metadata in MATLAB. Thus, delete those rows. Don’t just delete the text in them; delete the rows themselves. Row 1 should now be the header info. Now, use the text-to-columns feature in Excel, with a comma as the delimiter, to separate the data that is currently only in Column A into different columns. Once you’ve successfully done this, you should have data in columns A to AR.
Save this workbook as “KNAK_data_Jan2017.xlsx”, and put it in your MATLAB directory4.
3) Open MATLAB. Verify the MATLAB working directory is the same directory in which you just saved your Excel file (you may need to re-save your Excel file in a different directory. My working directory is indicated in the figure below).
Open a new script. Add an appropriate header (as comments) to the first lines of the script (see printed code).
Q1) What does the percent sign (%) mean in MATLAB?
Save your script with the filename you put on the first line in the header comments. Then, begin a new section of your script with lines to clear all variables and close all open figure windows. Note that although these two lines are not required, they are great coding practice. The "clear
2 Script m-files or “scripts” are a common, yet powerful computer programming feature. They are often favored over typing commands into the Command Window in MATLAB manually because script files: a) execute faster than if each command was entered one-by-one, b) provide a record of the commands used to produce the result, c) can be edited to correct mistakes, d) can be modified for additional use, and e) can be shared with other users for collaborative work. (SO287 Intro to MATLAB notes) 3 Data about other data 4 The Oceanography Department has a standardized directory structure for students: C:\Users\[alpha #]\Documents\Oceanography\Lastname_1stInitial\SO[class#]\Lab[#]
- 2 - SO 254 Spring 2017 variables" command clears all variables5 from MATLAB memory and “close all” closes any open figure windows.
Using xlsread, bring the data you saved in Excel (KNAK_data_Jan2017.xlsx) into MATLAB, and store it in a variable called knak_obs
Q2) What does the command “xlsread” do in MATLAB? Q3) What is the effect of including a semicolon at the end of the variable definition line?
After defining the variable, press “run” (green arrow) in the script editor window. Notice that the newly defined variable now appears in the “workspace” panel of the MATLAB desktop environment.
Double-click on the variable knak_obs to examine the data. What shows up in Column 1? What in Column 2? What about columns 5 and 6? Why are those data entries NaN?
Q4) What does NaN stand for?
Why is Row 1 in your MATLAB variable data, while Row 1 in Excel the header? What did MATLAB do with Row 1 from the Excel variable?
4) Now that you have the data imported, you can move ahead with the tasks. There are several tasks you need to do:
a) Calculate air density using the equation of state b) Plot time series (figures) of density, air temperature, dew point temperature, and pressure c) Analyze and interpret the figures a) First, use MATLAB to calculate air density. Recall from the equation of state
Therefore, .
Which column of data corresponds to pressure? (If you’re not sure, look in Excel, because the header row is retained there). What units are those pressure data given in? If you want the air density value to have units of kg m-3, you need pressure to be in Pascals (Pa) (SI units). For temperature, you’ll use the column entitled “DryBulbCelsius” and you’ll need to express temperature in degrees Kelvin (K).
In the process of the calculation, you’re entering a line of code that begins with “density = …”
Q5) What are you creating in MATLAB by typing “density = …”? Q6) Note the syntax knak_obs(:,31)and knak_obs(:,13) in the line of code. What does the “31” and “13” correspond to? What does the colon (:) mean?
5 A variable is an array or matrix. In this case, the entire dataset downloaded from NCEI will be a single variable.
- 3 - SO 254 Spring 2017
Q7) What are the 3386.39 and 273.15 numerical factors doing in the line of code? Q8) What is the significance of the dot in front of the division sign in the line of code?
Once you’ve entered the full line of code, press “run” again in the script editor window. Notice where “density” appears now in the MATLAB desktop environment. b) Now that you’ve calculated density, you’ll want to plot it using the next six lines of provided code. Note that: figure(1) tells MATLAB to open (or, if already open, to make active) figure #1 clf tells MATLAB to wipe clean whatever might have been in the figure 1 window title adds a title to the figure xlabel adds a label to the x-axis ylabel adds a label to the y-axis
After entering the code and running the updated script, you should get a figure that looks similar to the one above. Note that the x-axis goes from 0 to 400. We would like, instead, for each x coordinate to be associated with a date and time. The way to do that is to use the MATLAB function “datenum”, which assigns a number for each day, with day 1 being 01 Jan 0000 (of the year 0). January 1, 2017 has datenum 736696 (as in, there have been 736,696 days since 01 Jan 0000). At midnight, the datenum is a whole number. Each hour is a fraction. Thus, noon on Jan 1, 2017 would have datenum 736696.5
The datenum function requires the following syntax: date_number = datenum( yyyy,mm,dd,hh,mm,ss ), where you replace yyyy with the year, mm with the month, dd with the day, hh with the hour, mm with the minute, and ss with the second.
In the data from NOAA, we have the year, month, and day of each weather observation provided in column 2 and the hour and minute provided in column 3. We want to calculate the datenum of
- 4 - SO 254 Spring 2017 each weather observation using those values. It is somewhat tricky, given the data formats, but here is how it is done: date_number = datenum(2017,01,knak_obs(:,2)-20170100,(knak_obs(:,3)- mod(knak_obs(:,3),100))/100,mod(knak_obs(:,3),100),0);
Interpretation: the year is 2017 and the month is 01 (January), so those two are hard-coded here. The day changes in the data, so to isolate whether the day is 01, 02, etc., subtract 20170100 from the data in column 2 (which is what “knak_obs(:,2)-20170100” does). The hour and minutes were fairly tricky to isolate. The first observation, 0054, occurred at hour 0 and minute 54. To isolate those two values, we first subtract the modulus or “remainder” (54) from the full value (0054) and divide by 100 (which is what “,(knak_obs(:,3)- mod(knak_obs(:,3),100))/100” does). That gave hour 00 for the first observation. The minutes then were calculated by calculating the modulus of 0054 with 100 (which is what “mod(knak_obs(:,3),100)” does). Finally, all observations occurred at seconds = 0.
So to “fix” your figure and have it plot dates/times instead of 0 to 400 on the x-axis, go back in your script and define the variable date_number using the syntax above. You’ll want to make this definition prior to the point in the script where you’re asking MATLAB to plot the figure. Also, in the line for the plot command, you’ll want to change the syntax from plot(density) to plot(date_number,density)
Finally, you will also want to add one line of code after ylabel to ensure the correct dates are plotted and to specify the format to display the dates. The syntax for this line is as follows: set(gca,’xtick’,736696:1:736704,’xticklabel’,datestr(736696:1:73 6704,19)) which says in the current figure gca, make tick marks on the x-axis starting at 736696, at intervals of 1, out to 736704. Label those x tick marks using the datestr syntax.
With the above changes made, run the script again. Notice that the displayed dates range only from 01/01 to 09/01 (January 1st through 9th). Make an appropriate change to the code to display dates for the entire range (through January 17th) and make sure also that your x-axis is labeled appropriately (i.e., what is 01/01? It’s not a “time”, which is what the original xlabel indicated…)
Now repeat step b) to create figures for air temperature, dew point temperature, and pressure [in millibars (mb)]. (Make sure to include an appropriate conversion in the code to create the figure for pressure so that it displays in mb.) It might be helpful to create each figure in a separate window (1, 2, 3, etc…)
Save each figure as a PNG file type, and include each figure in your Lab writeup. c) The final task of this lab is to analyze the results. (What do the figures show?) Write a few short paragraphs addressing the following questions. Be thoughtful in your analysis. Refer to
- 5 - SO 254 Spring 2017 each figure appropriately: do not say: “Figure 1 shows a strong drop in temperature on 04 Jan.” The figures cannot do/make/show/indicate anything. You, the writer, must do that. So instead, refer to Figure 1 like this: “A 13°C drop in temperature occurred on 04 Jan 2017 (Fig. 1).” Points will be deducted for spelling and grammar errors.
In the temperature figure, a pronounced change in temperature occurred during 04 Jan, when temperature dropped from 13°C to nearly 0°C in just a few hours. What was the likely cause of that drastic change? Address what other fluctuations you observe in the temperature data and offer explanations as appropriate.
The dew point temperature is a measure of the amount of water vapor present in the air and represents the temperature at which the air would be completely saturated with respect to water vapor (i.e., the relative humidity would be 100 percent). Discuss what trends you observe in the dew point temperature over the time period. Do these trends seem coupled to trends observed in the other variables?
Discuss the variability you observe in air pressure over the time period and whether changes in air pressure seem to be related to changes in the other variables.
Lastly, discuss the variability you observe in air density over the time period. Specifically, address the changes you observe to changes in the other variables vis-à-vis their relationships in the equation of state.
- 6 -