Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cboettig committed Apr 30, 2024
1 parent 770302e commit 17661b6
Show file tree
Hide file tree
Showing 15 changed files with 3,093 additions and 16 deletions.
3 changes: 1 addition & 2 deletions _freeze/notebook/example-2/execute-results/html.json

Large diffs are not rendered by default.

Binary file not shown.
2,787 changes: 2,787 additions & 0 deletions _freeze/site_libs/leaflet-binding-2.2.2/leaflet.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LeafletWidget.methods.addProviderTiles = function(provider, layerId, group, options) {
this.layerManager.addLayer(L.tileLayer.provider(provider, options), "tile", layerId, group);
};
3 changes: 1 addition & 2 deletions _freeze/tutorials/example-1/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"hash": "73ec8608d7eb19954853e754021ef32f",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"1: Satellite data\"\nauthor: Carl Boettiger\ndate: \"2024-01-31\"\n---\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(rstac)\nlibrary(gdalcubes)\nlibrary(stars)\nlibrary(tmap)\nlibrary(dplyr)\nearthdatalogin::gdal_cloud_config()\ngdalcubes::gdalcubes_options(parallel = TRUE)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nbox <- c(xmin=-123, ymin=37, xmax=-121, ymax=39) \nstart_date <- \"2022-06-01\"\nend_date <- \"2022-08-01\"\nitems <-\n stac(\"https://earth-search.aws.element84.com/v0/\") |>\n stac_search(collections = \"sentinel-s2-l2a-cogs\",\n bbox = box,\n datetime = paste(start_date, end_date, sep=\"/\"),\n limit = 100) |>\n ext_query(\"eo:cloud_cover\" < 20) |>\n post_request()\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\ncol <- stac_image_collection(items$features, asset_names = c(\"B08\", \"B04\", \"SCL\"))\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\nWarning in stac_image_collection(items$features, asset_names = c(\"B08\", : STAC\nasset with name 'SCL' does not include eo:bands metadata and will be considered\nas a single band source\n```\n\n\n:::\n\n```{.r .cell-code}\ncube <- cube_view(srs =\"EPSG:4326\",\n extent = list(t0 = start_date, t1 = end_date,\n left = box[1], right = box[3],\n top = box[4], bottom = box[2]),\n dx = 0.001, dy = 0.001, dt = \"P1M\",\n aggregation = \"median\", resampling = \"average\")\n```\n:::\n\n\n\nThe SCL data layer in Sentinel is one of three 'quality assurance' layers provided in this data catalog. Table 3 in this description of the [Sentinel-2 Level2A Specifications](https://docs.digitalearthafrica.org/en/latest/data_specs/Sentinel-2_Level-2A_specs.html) summarizes the classification codes (Cloud shadows, medium probability cloud, high probability cloud). An image mask basically drops these bad pixels. \n\n\n::: {.cell}\n\n```{.r .cell-code}\nmask <- image_mask(\"SCL\", values=c(3, 8, 9)) # mask clouds and cloud shadows\n\ndata <- raster_cube(col, cube, mask = mask)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nndvi <- data |>\n select_bands(c(\"B04\", \"B08\")) |>\n apply_pixel(\"(B08-B04)/(B08+B04)\", \"NDVI\") |>\n reduce_time(c(\"mean(NDVI)\")) \n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nndvi_stars <- st_as_stars(ndvi)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nmako <- tm_scale_continuous(values = viridisLite::mako(30))\nfill <- tm_scale_continuous(values = \"Greens\")\n\ntm_shape(ndvi_stars) + tm_raster(col.scale = mako)\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\nstars object downsampled to 1000 by 1000 cells.\n```\n\n\n:::\n\n::: {.cell-output .cell-output-stderr}\n\n```\nWarning in value[[3L]](cond): could not rename the data.table\n```\n\n\n:::\n\n::: {.cell-output-display}\n![](example-1_files/figure-html/unnamed-chunk-7-1.png){width=672}\n:::\n:::",
"markdown": "---\ntitle: \"1: Satellite data\"\nauthor: Carl Boettiger\ndate: \"2024-01-31\"\n---\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(rstac)\nlibrary(gdalcubes)\nlibrary(stars)\nlibrary(tmap)\nlibrary(dplyr)\nearthdatalogin::gdal_cloud_config()\ngdalcubes::gdalcubes_options(parallel = TRUE)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nbox <- c(xmin=-123, ymin=37, xmax=-121, ymax=39) \nstart_date <- \"2022-06-01\"\nend_date <- \"2022-08-01\"\nitems <-\n stac(\"https://earth-search.aws.element84.com/v0/\") |>\n stac_search(collections = \"sentinel-s2-l2a-cogs\",\n bbox = box,\n datetime = paste(start_date, end_date, sep=\"/\"),\n limit = 100) |>\n ext_query(\"eo:cloud_cover\" < 20) |>\n post_request()\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\ncol <- stac_image_collection(items$features, asset_names = c(\"B08\", \"B04\", \"SCL\"))\n\ncube <- cube_view(srs =\"EPSG:4326\",\n extent = list(t0 = start_date, t1 = end_date,\n left = box[1], right = box[3],\n top = box[4], bottom = box[2]),\n dx = 0.001, dy = 0.001, dt = \"P1M\",\n aggregation = \"median\", resampling = \"average\")\n```\n:::\n\n\n\nThe SCL data layer in Sentinel is one of three 'quality assurance' layers provided in this data catalog. Table 3 in this description of the [Sentinel-2 Level2A Specifications](https://docs.digitalearthafrica.org/en/latest/data_specs/Sentinel-2_Level-2A_specs.html) summarizes the classification codes (Cloud shadows, medium probability cloud, high probability cloud). An image mask basically drops these bad pixels. \n\n\n::: {.cell}\n\n```{.r .cell-code}\nmask <- image_mask(\"SCL\", values=c(3, 8, 9)) # mask clouds and cloud shadows\n\ndata <- raster_cube(col, cube, mask = mask)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nndvi <- data |>\n select_bands(c(\"B04\", \"B08\")) |>\n apply_pixel(\"(B08-B04)/(B08+B04)\", \"NDVI\") |>\n reduce_time(c(\"mean(NDVI)\")) \n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nndvi_stars <- st_as_stars(ndvi)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nmako <- tm_scale_continuous(values = viridisLite::mako(30))\nfill <- tm_scale_continuous(values = \"Greens\")\n\ntm_shape(ndvi_stars) + tm_raster(col.scale = mako)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nstars object downsampled to 1000 by 1000 cells.\n```\n:::\n\n::: {.cell-output-display}\n![](example-1_files/figure-html/unnamed-chunk-7-1.png){width=672}\n:::\n:::",
"supporting": [
"example-1_files"
],
Expand Down
Binary file modified _freeze/tutorials/example-1/figure-html/unnamed-chunk-7-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions _freeze/tutorials/example-2/execute-results/html.json

Large diffs are not rendered by default.

Binary file modified _freeze/tutorials/example-2/figure-html/unnamed-chunk-9-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions _freeze/tutorials/example-3/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"hash": "88091339bf8e900459dc097a700780d5",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"3: animations\"\nauthor: Carl Boettiger\ndate: \"2024-02-05\"\n---\n\n\nFollowing the same template, but we compute over a larger bounding box and generate an animation \n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(rstac)\nlibrary(gdalcubes)\nlibrary(stars)\nlibrary(tmap)\nlibrary(dplyr)\nearthdatalogin::gdal_cloud_config()\nearthdatalogin::with_gdalcubes()\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nbox <- c(xmin=-123, ymin=37, xmax=-122, ymax=38) \nstart_date <- \"2022-01-01\"\nend_date <- \"2022-06-30\"\nitems <-\n stac(\"https://planetarycomputer.microsoft.com/api/stac/v1\") |>\n stac_search(collections = \"sentinel-2-l2a\",\n bbox = box,\n datetime = paste(start_date, end_date, sep=\"/\"),\n limit = 1000) |>\n ext_query(\"eo:cloud_cover\" < 20) |>\n post_request() |>\n items_sign(sign_planetary_computer())\n```\n:::\n\n\nLet's do a true-color RGB image this time by combining data from Blue, Green, and Red bands:\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncol <- stac_image_collection(items$features, asset_names = c(\"B02\", \"B03\", \"B04\", \"SCL\"))\n\ncube <- cube_view(srs =\"EPSG:4326\",\n extent = list(t0 = start_date, t1 = end_date,\n left = box[1], right = box[3],\n top = box[4], bottom = box[2]),\n dx = 0.001, dy = 0.001, dt = \"P1M\")\n\ndata <- raster_cube(col, cube)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nndvi <- data |>\n select_bands(c(\"B02\",\"B03\", \"B04\")) |>\n write_ncdf(\"visual.nc\", overwrite=TRUE)\n```\n:::\n\n\nWhile we could go directly from `apply_pixel` to `animate`, here we show how to stash a copy of the computed, rescaled and reprojected data as a local netcdf file that can be used in any further analysis without going back to the original data. To continue our `gdalcubes` pipeline, we can easily load this space-time ncdf cube and continue as before:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nncdf_cube(\"visual.nc\") |>\n animate(rgb=3:1, \n col = viridisLite::mako, fps=2, \n save_as=\"visual.gif\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] \"/workspaces/cloud-native-geo-cboettig/tutorials/visual.gif\"\n```\n\n\n:::\n:::\n\n\n\n![](visual.gif)",
"markdown": "---\ntitle: \"3: animations\"\nauthor: Carl Boettiger\ndate: \"2024-02-05\"\n---\n\n\nFollowing the same template, but we compute over a larger bounding box and generate an animation \n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(rstac)\nlibrary(gdalcubes)\nlibrary(stars)\nlibrary(tmap)\nlibrary(dplyr)\nearthdatalogin::gdal_cloud_config()\nearthdatalogin::with_gdalcubes()\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nbox <- c(xmin=-123, ymin=37, xmax=-122, ymax=38) \nstart_date <- \"2022-01-01\"\nend_date <- \"2022-06-30\"\nitems <-\n stac(\"https://planetarycomputer.microsoft.com/api/stac/v1\") |>\n stac_search(collections = \"sentinel-2-l2a\",\n bbox = box,\n datetime = paste(start_date, end_date, sep=\"/\"),\n limit = 1000) |>\n ext_query(\"eo:cloud_cover\" < 20) |>\n post_request() |>\n items_sign(sign_planetary_computer())\n```\n:::\n\n\nLet's do a true-color RGB image this time by combining data from Blue, Green, and Red bands:\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncol <- stac_image_collection(items$features, asset_names = c(\"B02\", \"B03\", \"B04\", \"SCL\"))\n\ncube <- cube_view(srs =\"EPSG:4326\",\n extent = list(t0 = start_date, t1 = end_date,\n left = box[1], right = box[3],\n top = box[4], bottom = box[2]),\n dx = 0.001, dy = 0.001, dt = \"P1M\")\n\ndata <- raster_cube(col, cube)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nndvi <- data |>\n select_bands(c(\"B02\",\"B03\", \"B04\")) |>\n write_ncdf(\"visual.nc\", overwrite=TRUE)\n```\n:::\n\n\nWhile we could go directly from `apply_pixel` to `animate`, here we show how to stash a copy of the computed, rescaled and reprojected data as a local netcdf file that can be used in any further analysis without going back to the original data. To continue our `gdalcubes` pipeline, we can easily load this space-time ncdf cube and continue as before:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nncdf_cube(\"visual.nc\") |>\n animate(rgb=3:1, \n col = viridisLite::mako, fps=2, \n save_as=\"visual.gif\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] \"/home/rstudio/espm-288/cloud-native-geo-cboettig/tutorials/visual.gif\"\n```\n:::\n:::\n\n\n\n![](visual.gif)",
"supporting": [],
"filters": [
"rmarkdown/pagebreak.lua"
Expand Down
3 changes: 1 addition & 2 deletions _freeze/tutorials/example-4/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"hash": "901b938e0e5d07201bcfbc6b428ce8a3",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"4: Biodiversity Intactness Index\"\nauthor: Carl Boettiger\ndate: \"2024-02-07\"\n---\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(rstac)\nlibrary(gdalcubes)\nlibrary(stars)\nlibrary(tmap)\nlibrary(dplyr)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(spData)\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\nTo access larger datasets in this package, install the spDataLarge\npackage with: `install.packages('spDataLarge',\nrepos='https://nowosad.github.io/drat/', type='source')`\n```\n\n\n:::\n\n```{.r .cell-code}\nbox_ca <- spData::us_states |> filter(NAME==\"California\") |> st_bbox()\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nbox <- c(xmin=-123, ymin=37, xmax=-121, ymax=39) \nbox <- c(box_ca)\nitems <- \n stac(\"https://planetarycomputer.microsoft.com/api/stac/v1\") |>\n stac_search(collections = \"io-biodiversity\",\n bbox = box,\n limit = 100) |>\n post_request() |>\n items_sign(sign_planetary_computer())\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\ncol <- stac_image_collection(items$features, asset_names = c(\"data\"))\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\nWarning in stac_image_collection(items$features, asset_names = c(\"data\")): STAC\nasset with name 'data' does not include eo:bands metadata and will be\nconsidered as a single band source\n```\n\n\n:::\n\n```{.r .cell-code}\ncube <- cube_view(srs =\"EPSG:4326\",\n extent = list(t0 = \"2017-01-01\", t1 = \"2017-12-31\",\n left = box[1], right = box[3],\n top = box[4], bottom = box[2]),\n dx = 0.005, dy = 0.005, dt = \"P1Y\")\n\ndata <- raster_cube(col, cube)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nbii <- data |> slice_time(\"2017-01-01\") |> st_as_stars()\ntm_shape(bii) + tm_raster()\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\nstars object downsampled to 1028 by 948 cells.\n```\n\n\n:::\n\n::: {.cell-output .cell-output-stderr}\n\n```\nWarning in value[[3L]](cond): could not rename the data.table\n```\n\n\n:::\n\n::: {.cell-output-display}\n![](example-4_files/figure-html/unnamed-chunk-5-1.png){width=672}\n:::\n:::\n",
"markdown": "---\ntitle: \"4: Biodiversity Intactness Index\"\nauthor: Carl Boettiger\ndate: \"2024-02-07\"\n---\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(rstac)\nlibrary(gdalcubes)\nlibrary(stars)\nlibrary(tmap)\nlibrary(dplyr)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(spData)\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nTo access larger datasets in this package, install the spDataLarge\npackage with: `install.packages('spDataLarge',\nrepos='https://nowosad.github.io/drat/', type='source')`\n```\n:::\n\n```{.r .cell-code}\nbox_ca <- spData::us_states |> filter(NAME==\"California\") |> st_bbox()\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nbox <- c(xmin=-123, ymin=37, xmax=-121, ymax=39) \nbox <- c(box_ca)\nitems <- \n stac(\"https://planetarycomputer.microsoft.com/api/stac/v1\") |>\n stac_search(collections = \"io-biodiversity\",\n bbox = box,\n limit = 100) |>\n post_request() |>\n items_sign(sign_planetary_computer())\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\ncol <- stac_image_collection(items$features, asset_names = c(\"data\"))\n\ncube <- cube_view(srs =\"EPSG:4326\",\n extent = list(t0 = \"2017-01-01\", t1 = \"2017-12-31\",\n left = box[1], right = box[3],\n top = box[4], bottom = box[2]),\n dx = 0.005, dy = 0.005, dt = \"P1Y\")\n\ndata <- raster_cube(col, cube)\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nbii <- data |> slice_time(\"2017-01-01\") |> st_as_stars()\ntm_shape(bii) + tm_raster()\n```\n\n::: {.cell-output .cell-output-stderr}\n```\nstars object downsampled to 1028 by 948 cells.\n```\n:::\n\n::: {.cell-output-display}\n![](example-4_files/figure-html/unnamed-chunk-5-1.png){width=672}\n:::\n:::\n",
"supporting": [
"example-4_files"
],
Expand Down
Binary file modified _freeze/tutorials/example-4/figure-html/unnamed-chunk-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions _freeze/tutorials/example-5-fire/execute-results/html.json

Large diffs are not rendered by default.

Loading

0 comments on commit 17661b6

Please sign in to comment.