generated from jtr13/quarto-edav-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch10.qmd
177 lines (108 loc) · 8.62 KB
/
ch10.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
title-block-banner: true
bibliography: references.bib
editor:
markdown:
wrap: sentence
---
# Practice Exercises
## Flash Cards
![](images/clipboard-1173129154.png){width="600"}
![](images/clipboard-3124773382.png){width="600"}
![](images/clipboard-430065762.png){width="600"}
![](images/clipboard-136714138.png){width="629"}
```{r child="ch4.qmd", message = FALSE, warning = FALSE}
```
## Exercise #2
Use the raster files in *SampleData-master/SMAPL4_rasters* folder, and perform the tasks as listed below:
- Task 1: Write a user-defined function to count the number of pixels within the range \[0.3, 0.4\] for 20211213.
Use `global` to implement your function.
Pass the specified range as an input argument to the function.
- Task 2: Compared to 20211213, what is the percentage change in 20211215 for the pixels within the \[0.3, 0.4\] range?
- Task 3: Make a multivariate plot (2 or more variables on the same axis) comparing the density distribution of soil moisture for 20211213 and 20211215?
```{r child="ch6_b.qmd", message = FALSE, warning = FALSE}
```
## Exercise #4
Imagine that a federal agency is interested in understanding the impacts of land conservation practices to improve carbon sequestration in the soil.
The agency has selected two potential Carbon Sequestration Testbed (CST) sites across Louisiana.
Using the observations of hydrometeorological, land practice, and vegetation datasets collected from these locations, the agency is interested in developing a physics-based ecohydrology model to mimic the interactions between soil, plants, and atmosphere at these test beds.
This will help develop predictive models to estimate the effects of various management practices on the carbon sequestration potential in soil.
```{r 4a, message = FALSE, warning = FALSE}
library(terra)
library(mapview)
# Import vector for Louisiana
LAvct=vect(spData::us_states[spData::us_states$NAME=="Louisiana",])
# Spatial attributes of the test polygons
lon = c(-89.9, -90.2, -90.2,-93,-92.8, -93.1)
lat = c(30.8, 30.8, 30.5,32, 32.2, 32.4)
id=c(1, 1, 1, 2, 2, 2)
# Combine attributes by columns
lonlat = cbind(id, lon, lat)
# Create polygons using the point locations as vertices
#~~~ CRS of the LA vect is assigned to the new vector
CSTpoly = vect(lonlat, type="polygons",crs=crs(LAvct))
# Add polygon id to the vector geometry
CSTpoly$CST=c(1,2)
# Plot map of Louisiana with overlaying CST polygons
mapview(LAvct, alpha.regions = 0.1) +
mapview(CSTpoly, zcol ="CST", col.regions = c("blue", "red"))
```
------------------------------------------------------------------------
To develop these ecohydrology models, the agency needs your assistance in collecting high-resolution soil texture dataset for the Louisiana CSTs.
You know from Ch 6 that soil texture data is available through POLARIS at \[30m X 30m\] spatial resolution for 6 soil depths (0-5 cm, 5-15 cm, 15-30 cm, 30-60 cm, 60-100 cm and 100-200 cm. So, for this exercise, you will generate the maps of mean percent clay content for 0-100 cm soil profile for the two CSTs by taking the arithmetic average of the clay percent in each layer between 0-100 cm depth. Access the mean clay content data from: <http://hydrology.cee.duke.edu/POLARIS/PROPERTIES/v1.0/clay/mean/>.
For each CST, follow the following steps:
1. \(10\) Use R code to download the *.tif* files for the areal domain encompassing the polygon for 0-5 cm soil profile.
2. \(15\) Combine the rasters using the mosaic function.
3. \(15\) Crop and mask the mosaic raster to the polygon extent and shape.
4. \(20\) Repeat for other soil profiles.
5. \(20\) Take cell-wise arithmetic average of the mean soil percentage for the layers.
6. \(10\) Plot the raster (mean soil percentage for 0-100 cm) for the CST.
7. \(10\) Export the raster.
## Exercise #5
Soil moisture is an important hydrological variable with strong linkages to crop health and yield.
Satellites such as NASA's SMAP and ESA's SMOS provide soil moisture information for the surface profile (0-5 cm).
However, temporal variability in the surface soil moisture gets attenuated and dampened as water infiltrates through the soil layers.
This is followed by evapotranspirative losses to the atmosphere from the rootzone.
The time delay in surface soil moisture and evapotranspiration variability indicates several critical aspects of ecosystem functioning, terrestrial water and energy balance and soil hydraulic processes.
In this exercise, we will simulate the attenuation and dampening effect on the surface soil moisture using a *moving average filter* and study how increasing smoothing of surface soil moisture correlates with the variability in evapotranspiration.
We will use simulated gridded surface soil moisture and evapotranspiration from VIC land surface model for the year 2011.
------------------------------------------------------------------------
1. Download CONUS-wide daily simulated soil moisture (`soilmoist.2011.nc`) and evapotranspiration (`et.2011.nc`) for the year 2011 from NOAA-PSL's servers.
using the following file location:
`sm_path = "https://downloads.psl.noaa.gov//Datasets/livneh/fluxvars/soilmoist.2011.nc"`
`et_path = "https://downloads.psl.noaa.gov//Datasets/livneh/fluxvars/et.2011.nc"`
<!-- -->
2. Import the downloaded netCDFs to workspace as spatRasters. Print the time stamp and variable names of the two spatRasters using `terra::time()` and `terra::names()` functions. You will notice that `et.2011.nc` has one raster layer for each day. `soilmoist.2011.nc` contains three raster layers (one for each soil profile level) per day.
<!-- -->
3. Create a new multilayer spatRaster for raster layers for soil profile level 1. (Hint: using `substr()` on the layer `names()` from `soilmoist.2011.nc`, subset the layers with lev= "1" in their name)
<!-- -->
4. Create a polygon with with extent: `xmin=255, xmax=265, ymin=40, ymax=48`.
a\) Plot a map of level 1 soil moisture for day 10 and overlay the polygon on the map.
b\) Crop evapotranspiration and soil moisture spatRasters to the spatial polygon.
c\) Plot the raster layers for day 10 from the cropped evapotranspiration and soil moisture SpatRasters.
![](images/clipboard-4251555621.png){fig-align="center" width="450"}
5. If *smTS* is the soil moisture time series, and *Tagg* is the time-period of moving average, the function generates a right aligned rolling mean (moving average) of the time series.
NA is used as fill values for the first *Tagg*-1 cells of the output.
`zoo::rollmean(smTS, Tagg, fill=NA, align = "right")`
Create and report a custom function for applying the moving average on a time series with the following components:
a\) Two input arguments:
*i) `minSamp`* (minimum number of samples in a time series)
*ii) `Tagg`* (time period of aggregation)
b\) Error exception using trycatch, where the function returns NA series for the pixel where error occurs.
6. For a point of interest at Lon=260, Lat=45:
a) Extract a sample time series from level 1 soil moisture
b) Apply the custom function made in the previous step to the sample time series.
c) Generate soil moisture moving average for the selected location with for four *Tagg* values, 7, 15, 30 and 45 days. Keep *minSamp* fixed at 100.
d) Plot the extracted level 1 soil moisture time series for the point of interest. Overlay aggregated time series at *Tagg*=7, 15, 30, 45 on the same x-axis. Comment on the relationship between *Tagg* and time series smoothing.
![](images/clipboard-713405122.png){fig-align="center" width="450"}
7. Apply the custom moving average function in parallel on each grid of the cropped multilayer soil moisture SpatRaster (from step 4) with *Tagg*=7, 15, 30, 45.
Keep *minSamp* fixed at 100.
Use all-but-one available system cores for parallel computing.
8. If x and y are two time series, then the following operation gives the Pearson's correlation between the two datasets:
`cor(x, y, use = "pairwise.complete.obs")`
Using a custom function, calculate cell-wise correlation between evapotranspiration and moving averaged level 1 soil moisture for *Tagg*=7, 15, 30 and 45.
(Hint: ?terra::xapp)
9. Create a multilayer raster by concatenating the output rasters from Step 8.
a) Plot the multilayer rasters of grid-wise correlation between evapotranspiration and level 1 soil moisture with *Tagg* =7, 15, 30 and 45. Fix legend range as (0,1).
b) Using `global()` function on the concatenated rasters, calculate and report the layer-wise median correlation between evapotranspiration and moving averaged level 1 soil moisture for the areal domain.
![](images/clipboard-3789126346.png){fig-align="center" width="550"}