8 Oceanography & Global Tree Cover

This week we’ll use a different dataset from the GOES-16 satellite to explore new coding practices. We’ll take what we have learned from the example and apply it to a global tree cover dataset. First, let’s cover an important skill - understanding the paste0() function.

8.1 Paste0()

Last week we covered the for loop which is an essential programming skill. We also touched on the paste0() function, but this is incredibly useful and should be expanded upon. paste0() is the sister function of paste(), who’s cousin is sprintf() . It depends on preference, but most coders I know gravitate towards paste0(). Let’s check out all 3.

## [1] "file number 32"
## [1] "file_number_32"
## [1] "filenumber32"
## [1] "file number 32"
## On 2021-01-25 I realized Grover was...
## flying by the street
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [[1]]
## [1] "~/Documents/0813/filename1"
## 
## [[2]]
## [1] "~/Documents/0814/filename2"
## 
## [[3]]
## [1] "~/Documents/0815/filename3"
## 
## [[4]]
## [1] "~/Documents/0816/filename4"
## [1] "~/Documents/0813/filename1"
## [1] "~/Documents/0813/filename1" "~/Documents/0814/filename2"
## [3] "~/Documents/0815/filename3" "~/Documents/0816/filename4"
## [1] "~/Documents/0813/filename1"

Debug and fix the following code:

The final pathList[[1]] should look like this…

"~/Documents/0912/sstData20190912"

8.2 Rasters

Rasters offer us a 2 dimensional dataset (matrix) of data with geospatial coordinates. Rasters can come in a variety of filetypes including netCDF, GeoTIFF, CSV (if they come in CSV, they’ll be massive - this is an inefficient datatype), etc. We’ll be looking at the GOES-16 Rolling 1 Day average datafile - GOES_R_ROLLING_1DAY_20190814.nc. The GOES-16 Satellite records sea surface temperatures every hour. A rolling 1 day is an average of the previous 24 hours of record of sea surface temperature (and this dataset is created by CEMA here at UD).

## class      : RasterLayer 
## dimensions : 1989, 2778, 5525442  (nrow, ncol, ncell)
## resolution : 0.0003599712, 0.0005027652  (x, y)
## extent     : 0, 1, 0, 1  (xmin, xmax, ymin, ymax)
## crs        : NA 
## source     : memory
## names      : layer 
## values     : 5.344696, 34.9397  (min, max)
## class      : RasterLayer 
## dimensions : 1989, 2778, 5525442  (nrow, ncol, ncell)
## resolution : 0.01799352, 0.0180909  (x, y)
## extent     : -99.99015, -50.00415, 16.00283, 51.98563  (xmin, xmax, ymin, ymax)
## crs        : +proj=longlat +datum=WGS84 +no_defs 
## source     : memory
## names      : layer 
## values     : 5.344696, 34.9397  (min, max)

## OGR data source with driver: ESRI Shapefile 
## Source: "/Users/james/Documents/Github/geog473-673/datasets/world_shpfiles/world.shp", layer: "world"
## with 252 features
## It has 2 fields

8.3 Assignment

  1. Download treecov.nc from the datasets folder

  2. Open tree cover % as a variable, remove bad values (i.e. percentages outside of 0 and 100).

  3. Plot tree cover variable using a green theme. Be sure to add coastlines via your choice of underlying dataset. Ensure correct latitude/longitudes are displayed. Add title.

  4. Submit resulting image to Canvas assignment 4

## OGR data source with driver: ESRI Shapefile 
## Source: "/Users/james/Documents/Github/geog473-673/datasets/world_shpfiles/world.shp", layer: "world"
## with 252 features
## It has 2 fields