G Exercise 05
Last updated: 2020-08-12 00:41:51
G.1 Question 1
- Recall that the
focal2functions from Section 9.4, which we used to apply a focal filter. The
focal2function excludes the first and last rows and columns (Figure G.1).
- Modify the definitions of the
focal2functions from Section 9.4, so that the first and last rows and columns are also processed, even though they have incomplete neighbornoods. This means that for focal cells in the first or last row/column, the function shoud be applied on the available values plus
NAvalues for the “missing” neighbors. For example, for the pixel in row 8 column 1 of
dem.tif, the \(3\times 3\) neighborhood consists of five non-
NAvalues plus four
NAvalues (Figure G.2).
- Apply the modified filter with the
- Plot the resulting raster, including rounded values, as shown in the right panel of (Figure G.3).
- Hint: there are (at least) two ways to solve this exercise: (1) modify the
get_neighborsfunction so that if the position is on matrix edges then the values are only extracted from intact cells, or (2) temporarily add a “buffer” of
NAvalues on all sides of the matrix with the raster values, apply the filter on the expanded matrix, then discard the buffer.
G.2 Question 2
- Read the
MOD13A3_2000_2019.tifraster, with monthly NDVI values, into a
rto UTM with
st_warp(r, crs = 32636).
- Read the Shapefile named
nafot.shp, which includes polygons of “Nafa” administrative regions in Israel, and reproject it to UTM as well.
- Subset the three polygons where
name_engis one of:
- Calculate the average NDVI for each of the three polygons for each date.
- Plot the resulting three time series, as shown in Figure G.4. Note that all values should fit into the plot ares, the x-axis should display the dates (based on
MOD13A3_2000_2019_dates.csv) and the series should be labeled with text labels.