@@ -151,7 +151,7 @@ We will construct a data cube to compute monthly average for sea surface tempera
151
151
To minimize data loading times, the first 10 results, which correspond to approximately two months
152
152
of data, will be used for this exercise.
153
153
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) .
155
155
``` {r}
156
156
ras_all <- terra::rast(results[c(25:35)], vsi = TRUE)
157
157
```
@@ -166,23 +166,42 @@ Select SST data.
166
166
rc_sst <- rc_all["analysed_sst", ]
167
167
```
168
168
169
- Calculate monthly SST means.
169
+ Calculate mean SST over the entire time series and map it
170
170
``` {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
+
171
188
# Function to convert times to year-month format
172
189
year_month <- function(x) {
173
190
format(as.Date(time(x), format="%Y-%m-%d"), "%Y-%m")
174
191
}
175
192
176
- # Convert time to Year-month format for aggregation
193
+ # Format time to Year-month for monthly aggregation
177
194
ym <- year_month(rc_sst)
178
195
179
196
# Compute raster mean grouped by Year-month
180
197
monthly_mean_rast <- terra::tapp(rc_sst, ym, fun = mean)
181
198
182
199
# 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
+
184
202
```
185
203
204
+
186
205
## Convert raster into data frame
187
206
188
207
``` {r ras_to_df}
0 commit comments