Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Created May 21, 2025 04:40

Revisions

  1. mdsumner created this gist May 21, 2025.
    40 changes: 40 additions & 0 deletions bowerbird_thredds_esacci.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    ```R
    library(bowerbird)
    my_source <- bb_source(
    name = "Chlorophyll-a concentration in seawater (not log-transformed), generated by as a blended combination of OCI, OCI2, OC2 and OCx algorithms, depending on water class memberships",
    id = "ESACCI-OC-L3S-CHLOR_A-MERGED",
    description = "European Space Agency Climate Change Initiative composites of merged sensor (MERIS, MODIS Aqua, SeaWiFS LAC & GAC, VIIRS, OLCI) products.",
    doc_url = "http://esa-oceancolour-cci.org",
    source_url =
    c("https://www.oceancolour.org/thredds/catalog/cci/v6.0-release/geographic/monthly/chlor_a/catalog.html",
    "https://www.oceancolour.org/thredds/catalog/cci/v6.0-release/geographic/daily/chlor_a/catalog.html",
    "https://www.oceancolour.org/thredds/catalog/cci/v6.0-release/geographic/5day/chlor_a/catalog.html",
    "https://www.oceancolour.org/thredds/catalog/cci/v6.0-release/geographic/annual/chlor_a/catalog.html"),
    citation = "See https://climate.esa.int/en/projects/ocean-colour/,",
    license = "ESA CCI, EOCIS, and C3S Data Policy: free and open access. When referencing, please use: Ocean Colour Climate Change Initiative dataset, Version 6.0, European Space Agency, available online at https://climate.esa.int/en/projects/ocean-colour/. We would also appreciate being notified of publications so that we can list them on the project website at https://climate.esa.int/en/projects/ocean-colour/, https://eocis.org/, https://climate.copernicus.eu/",
    method = list("bb_handler_thredds", level = 2, accept_download = ".*nc$"),
    access_function = "",
    data_group = "Ocean colour")

    result <- bb_get(my_source, local_file_root = tempdir(), verbose = FALSE, dry_run = TRUE)

    files <- do.call(rbind, result$files)

    ## convert local file to dsn with crs and variable name made explicit
    urltodsn <- function(x) {
    sprintf("vrt://%s?sd_name=chlor_a&a_srs=EPSG:4326", x)
    }

    tmpdir <- file.path(Sys.getenv("MYSCRATCH"), "tmp")
    if (!file.exists(tmpdir)) dir.create(tmpdir)


    ## this is what we test for existence on Acacia
    files$source <- gsub("https://", "/vsicurl/https://projects.pawsey.org.au/idea-esacci/", gsub("\\.nc$", ".tif", files$url))
    ## this is what we download,
    files$download <- file.path(tmpdir, basename(files$url))
    ## this is what we read from (local netcdf to convert to COG)
    files$dsn <- urltodsn(files$download)
    ## this is what we write to
    files$vsiwrite <- gsub("/vsicurl/https://projects.pawsey.org.au", "/vsis3", files$source)
    ```