Skip to content

Commit 817f24c

Browse files
committed
#18 modified aggregation section in R: added an example of mean over all time steps
1 parent 3b801f1 commit 817f24c

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Diff for: .DS_Store

0 Bytes
Binary file not shown.

Diff for: .gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
.RData
88
.Ruserdata
99
*.Rproj
10-
10+
**/.DS_Store
1111
/.quarto/
1212
/_site/
1313
/_freeze/
1414
/python-notebooks/demonstrated data/
1515
.DS_Store
16-
.DS_Store
1716
*.nc

Diff for: tutorials/r/3-extract-satellite-data-within-boundary.qmd

+23-4
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ We will construct a data cube to compute monthly average for sea surface tempera
151151
To minimize data loading times, the first 10 results, which correspond to approximately two months
152152
of data, will be used for this exercise.
153153

154-
Select the SST results for end of January and beginning of February.
154+
Select the first 10 SST results (end of January and beginning of February).
155155
```{r}
156156
ras_all <- terra::rast(results[c(25:35)], vsi = TRUE)
157157
```
@@ -166,23 +166,42 @@ Select SST data.
166166
rc_sst <- rc_all["analysed_sst", ]
167167
```
168168

169-
Calculate monthly SST means.
169+
Calculate mean SST over the entire time series and map it
170170
```{r get_means}
171+
172+
# Compute mean over 12 time layers
173+
raster_mean <- terra::mean(rc_sst, na.rm=TRUE)
174+
175+
# Map mean SST
176+
plot(raster_mean)
177+
178+
# Map only the GFST area
179+
plot(terra::crop(raster_mean, GFST))
180+
181+
182+
```
183+
184+
185+
Calculate monthly mean SST means across raster (lat, lon).
186+
```{r get_means}
187+
171188
# Function to convert times to year-month format
172189
year_month <- function(x) {
173190
format(as.Date(time(x), format="%Y-%m-%d"), "%Y-%m")
174191
}
175192
176-
# Convert time to Year-month format for aggregation
193+
# Format time to Year-month for monthly aggregation
177194
ym <- year_month(rc_sst)
178195
179196
# Compute raster mean grouped by Year-month
180197
monthly_mean_rast <- terra::tapp(rc_sst, ym, fun = mean)
181198
182199
# Compute mean across raster grouped by Year-month
183-
monthly_means <- global(monthly_mean_rast, fun = mean, na.rm=TRUE)
200+
monthly_mean <- global(monthly_mean_rast, fun = mean, na.rm=TRUE)
201+
184202
```
185203

204+
186205
## Convert raster into data frame
187206

188207
```{r ras_to_df}

0 commit comments

Comments
 (0)