Skip to content

Commit

Permalink
Merge pull request #19 from nmfs-opensci/sunny-dev
Browse files Browse the repository at this point in the history
#18 Modified Tutorial 3
  • Loading branch information
eeholmes authored May 12, 2024
2 parents 87ce868 + 9cd7d6b commit 63d006e
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 73 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
.RData
.Ruserdata
*.Rproj

**/.DS_Store
/.quarto/
/_site/
/_freeze/
/python-notebooks/demonstrated data/
.DS_Store
.DS_Store
*.nc
247 changes: 182 additions & 65 deletions tutorials/python/3-extract-satellite-data-within-boundary.ipynb

Large diffs are not rendered by default.

32 changes: 26 additions & 6 deletions tutorials/r/3-extract-satellite-data-within-boundary.qmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Extract data within a boundary
author: 'NOAA CoastWatch, NOAA Openscapes'
original author: NOAA CoastWatch
modifications by: NMFS Openscapes
---

::: {.callout-note title="Learning Objectives"}
Expand Down Expand Up @@ -151,7 +152,7 @@ We will construct a data cube to compute monthly average for sea surface tempera
To minimize data loading times, the first 10 results, which correspond to approximately two months
of data, will be used for this exercise.

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

Calculate monthly SST means.
Calculate mean SST over the entire time series and map it
```{r get_means}
# Compute mean over 12 time layers
raster_mean <- terra::mean(rc_sst, na.rm=TRUE)
# Map mean SST
plot(raster_mean)
# Map only the GFST area
plot(terra::crop(raster_mean, GFST))
```


Calculate monthly mean SST means across raster (lat, lon).
```{r get_means}
# Function to convert times to year-month format
year_month <- function(x) {
format(as.Date(time(x), format="%Y-%m-%d"), "%Y-%m")
}
# Convert time to Year-month format for aggregation
# Format time to Year-month for monthly aggregation
ym <- year_month(rc_sst)
# Compute raster mean grouped by Year-month
monthly_mean_rast <- terra::tapp(rc_sst, ym, fun = mean)
# Compute mean across raster grouped by Year-month
monthly_means <- global(monthly_mean_rast, fun = mean, na.rm=TRUE)
monthly_mean <- global(monthly_mean_rast, fun = mean, na.rm=TRUE)
```


## Convert raster into data frame

```{r ras_to_df}
Expand Down Expand Up @@ -211,4 +231,4 @@ If you get the following error:
> Warning: Opening a /vsi file with the netCDF driver requires Linux userfaultfd to be available. Or you may set the GDAL_SKIP=netCDF configuration option to force the use of the HDF5 driver. (GDAL error 1)Error: [rast] file does not exist: /vsicurl/https://archive.podaac.earthdata.nasa.gov/podaac-ops-cumulus-protected/AVHRR_OI-NCEI-L4-GLOB-v2.1/20191231120000-NCEI-L4_GHRSST-SSTblend-AVHRR_OI-GLOB-v02.0-fv02.1.nc
[insert solve]
:::
:::

0 comments on commit 63d006e

Please sign in to comment.