We will work with the meteorological data presented in lecture. Recall the dataset consists of weather station readings in the continental US.
The objective of the lab is to find the weather station with the highest elevation and look at patterns in the time series of its wind speed and temperature.
First download and then read in with data.table:fread()
download.file(
"https://raw.githubusercontent.com/JSC370/jsc370-2023/main/labs/lab03/met_all.gz",
destfile = "met_all.gz",
method = "curl",
timeout = 60
)
met <- data.table::fread("met_all.gz")
str(met)
## Classes 'data.table' and 'data.frame': 2377343 obs. of 30 variables:
## $ USAFID : int 690150 690150 690150 690150 690150 690150 690150 690150 690150 690150 ...
## $ WBAN : int 93121 93121 93121 93121 93121 93121 93121 93121 93121 93121 ...
## $ year : int 2019 2019 2019 2019 2019 2019 2019 2019 2019 2019 ...
## $ month : int 8 8 8 8 8 8 8 8 8 8 ...
## $ day : int 1 1 1 1 1 1 1 1 1 1 ...
## $ hour : int 0 1 2 3 4 5 6 7 8 9 ...
## $ min : int 56 56 56 56 56 56 56 56 56 56 ...
## $ lat : num 34.3 34.3 34.3 34.3 34.3 34.3 34.3 34.3 34.3 34.3 ...
## $ lon : num -116 -116 -116 -116 -116 ...
## $ elev : int 696 696 696 696 696 696 696 696 696 696 ...
## $ wind.dir : int 220 230 230 210 120 NA 320 10 320 350 ...
## $ wind.dir.qc : chr "5" "5" "5" "5" ...
## $ wind.type.code : chr "N" "N" "N" "N" ...
## $ wind.sp : num 5.7 8.2 6.7 5.1 2.1 0 1.5 2.1 2.6 1.5 ...
## $ wind.sp.qc : chr "5" "5" "5" "5" ...
## $ ceiling.ht : int 22000 22000 22000 22000 22000 22000 22000 22000 22000 22000 ...
## $ ceiling.ht.qc : int 5 5 5 5 5 5 5 5 5 5 ...
## $ ceiling.ht.method: chr "9" "9" "9" "9" ...
## $ sky.cond : chr "N" "N" "N" "N" ...
## $ vis.dist : int 16093 16093 16093 16093 16093 16093 16093 16093 16093 16093 ...
## $ vis.dist.qc : chr "5" "5" "5" "5" ...
## $ vis.var : chr "N" "N" "N" "N" ...
## $ vis.var.qc : chr "5" "5" "5" "5" ...
## $ temp : num 37.2 35.6 34.4 33.3 32.8 31.1 29.4 28.9 27.2 26.7 ...
## $ temp.qc : chr "5" "5" "5" "5" ...
## $ dew.point : num 10.6 10.6 7.2 5 5 5.6 6.1 6.7 7.8 7.8 ...
## $ dew.point.qc : chr "5" "5" "5" "5" ...
## $ atm.press : num 1010 1010 1011 1012 1013 ...
## $ atm.press.qc : int 5 5 5 5 5 5 5 5 5 5 ...
## $ rh : num 19.9 21.8 18.5 16.9 17.4 ...
## - attr(*, ".internal.selfref")=<externalptr>
table(met$year)
##
## 2019
## 2377343
table(met$day)
##
## 1 2 3 4 5 6 7 8 9 10 11 12 13
## 75975 75923 76915 76594 76332 76734 77677 77766 75366 75450 76187 75052 76906
## 14 15 16 17 18 19 20 21 22 23 24 25 26
## 77852 76217 78015 78219 79191 76709 75527 75786 78312 77413 76965 76806 79114
## 27 28 29 30 31
## 79789 77059 71712 74931 74849
table(met$hour)
##
## 0 1 2 3 4 5 6 7 8 9 10
## 99434 93482 93770 96703 110504 112128 106235 101985 100310 102915 101880
## 11 12 13 14 15 16 17 18 19 20 21
## 100470 103605 97004 96507 97635 94942 94184 100179 94604 94928 96070
## 22 23
## 94046 93823
summary(met$temp)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## -40.00 19.60 23.50 23.59 27.80 56.00 60089
summary(met$elev)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -13.0 101.0 252.0 415.8 400.0 9999.0
summary(met$wind.sp)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 0.00 0.00 2.10 2.46 3.60 36.00 79693
It looks like the elevation variable has observations with 9999.0, which is probably an indicator for missing. We should take a deeper look at the data dictionary to confirm. The wind speed variable is ok but there are a lot of missing data.
After checking the data we should make the appropriate modifications.
Replace elevations with 9999 as NA
.
# <place your code here>
At what elevation is the highest weather station?
We also have the issue of the minimum temperature being -40C, so we should remove those observations.
# <place your code here>
We should check the suspicious temperature value (where is it located?) and validate that the range of elevations make sense (-13 m to 4113 m).
Google is your friend here.
Fix any problems that arise in your checks.
# <place your code here>
Remember to keep the initial question in mind. We want to pick out the weather station with maximum elevation and examine its wind speed and temperature.
Some ideas: 1. select the weather station with maximum elevation; 2. look at the correlation between temperature and wind speed; and 3. look at the correlation between temperature and wind speed with hour and day of the month.
# <place your code here>
We should look at the distributions of all of the key variables (elevation, temp, wind speed) to make sure there are no remaining issues with the data.
# <place your code here>
One thing we should consider for later analyses is to log transform wind speed and elevation as the are very skewed.
Look at where the weather station with highest elevation is located (i.e. make a map!)
# <place your code here>
# hint: make use of leaflet
Look at the time series of temperature and wind speed at this location. For this we will need to create a date-time variable for the x-axis.
library(lubridate)
# <place your code here>
With the date-time variable we can plot the time series of temperature and wind speed.
# <place your code here>
Summarize any trends that you see in these time series plots.