From 71e107542d5383b38ea1ec477d46900592370e66 Mon Sep 17 00:00:00 2001 From: Carl Boettiger Date: Fri, 22 Dec 2023 20:59:07 +0000 Subject: [PATCH] gdal vs fsspec --- drafts/sst.R | 29 +++++++++++++++++++++++++++++ drafts/xarray.ipynb | 13 ++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 drafts/sst.R diff --git a/drafts/sst.R b/drafts/sst.R new file mode 100644 index 0000000..9dae23c --- /dev/null +++ b/drafts/sst.R @@ -0,0 +1,29 @@ +remotes::install_github("boettiger-lab/earthdatalogin") +library(earthdatalogin) +edl_netrc() +urls <- edl_search(short_name = "MUR-JPL-L4-GLOB-v4.1", + temporal = c("2019-01-01", "2019-01-31")) + + +vrt <- function(url) { + prefix <- "vrt://NETCDF:/vsicurl/" + suffix <- ":analysed_sst?a_srs=OGC:CRS84&a_ullr=-180,90,180,-90" + paste0(prefix, url, suffix) +} + + +library(gdalcubes) +gdalcubes_options(parallel = parallel::detectCores()*2) +url_dates <- as.Date(gsub(".*(\\d{8})\\d{6}.*", "\\1", urls), format="%Y%m%d") +data_gd <- gdalcubes::stack_cube(vrt(urls), datetime_values = url_dates) + + + +bench::bench_time({ + extent = list(left=-93, right=-76, bottom=41, top=49, + t0="2019-01-01", t1="2019-01-31") + data_gd |> + gdalcubes::crop(extent) |> + aggregate_time(dt="P1M", method="sd") |> + plot(col = viridisLite::viridis(10)) +}) diff --git a/drafts/xarray.ipynb b/drafts/xarray.ipynb index 582f2c9..1681ca1 100644 --- a/drafts/xarray.ipynb +++ b/drafts/xarray.ipynb @@ -169,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "8a7eec77-de5d-43bd-af77-b912851d57bc", "metadata": {}, "outputs": [ @@ -180,6 +180,13 @@ "/opt/venv/lib/python3.10/site-packages/rioxarray/_io.py:1132: NotGeoreferencedWarning: Dataset has no geotransform, gcps, or rpcs. The identity matrix will be returned.\n", " warnings.warn(str(rio_warning.message), type(rio_warning.message)) # type: ignore\n" ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "via_gdalvsi took 94.623sec\n" + ] } ], "source": [ @@ -212,7 +219,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "21ba6f1d-0915-47d0-a67f-2b0508cc0b38", "metadata": {}, "outputs": [], @@ -224,7 +231,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "f226e390-f84c-4440-8cc1-48b7df6c41d9", "metadata": {}, "outputs": [