Skip to content

Instantly share code, notes, and snippets.

View mdsumner's full-sized avatar

Michael Sumner mdsumner

  • Integrated Digital East Antarctica, Australian Antarctic Division
  • Hobart, Australia
View GitHub Profile
library(reticulate)
p <- c("polars", "h5netcdf", "fsspec", "aiohttp", "requests", "xarray", "dask")
py_require(p)
polars <- import("polars")
xarray <- import("xarray")

pp <-  arrow::read_parquet("https://projects.pawsey.org.au/idea-objects/idea-curated-objects.parquet")
## in R before
# p <- c("polars", "h5netcdf", "fsspec", "aiohttp", "requests", "xarray")
# reticulate::py_require(p)

import polars
pp = polars.read_parquet("https://projects.pawsey.org.au/idea-objects/idea-curated-objects.parquet")
d = pp.filter(polars.col("Dataset") == "oisst-avhrr-v02r01")
d = d.with_columns(source = polars.format("https://projects.pawsey.org.au/{}/{}", polars.col("Bucket"), polars.col("Key")))
dsn <- "https://raw.githubusercontent.com/OSGeo/gdal/refs/heads/master/frmts/wms/frmt_wms_bluemarble_s3_tms.xml"
library(terra)
r <- rast(dsn)



## first I did
m <- do.call(cbind, maps::map(plot = F)[1:2])
plot(project(m, to = "+proj=isea", from = "EPSG:4326"), pch = ".", asp = 1)
files <- readr::read_csv("https://ogd.swisstopo.admin.ch/resources/ch.swisstopo.swissalti3d-fOYMuina.csv", col_names = FALSE)

head(files$X1)
[1] "https://data.geo.admin.ch/ch.swisstopo.swissalti3d/swissalti3d_2019_2501-1120/swissalti3d_2019_2501-1120_0.5_2056_5728.tif"
[2] "https://data.geo.admin.ch/ch.swisstopo.swissalti3d/swissalti3d_2019_2501-1121/swissalti3d_2019_2501-1121_0.5_2056_5728.tif"
[3] "https://data.geo.admin.ch/ch.swisstopo.swissalti3d/swissalti3d_2019_2501-1122/swissalti3d_2019_2501-1122_0.5_2056_5728.tif"
[4] "https://data.geo.admin.ch/ch.swisstopo.swissalti3d/swissalti3d_2019_2502-1120/swissalti3d_2019_2502-1120_0.5_2056_5728.tif"
## a manifest array in a virtual Zarr store contains references like this (for this file it is >90000 references
##  because 28x51*1500x3600 in 1x1x300x300 blocks)

#'1.39.0.7': {'path': 'https://thredds.nci.org.au/thredds/fileServer/gb6/BRAN/BRAN2020/daily/ocean_salt_1993_01.nc', 
#  'offset': 302129687, 'length': 48186}, 
path = 'https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73909/world.topo.bathy.200412.3x5400x2700.png'

import rioxarray
import rasterio
## assign by bbox (respected by open, when we open via rioxarray)
dsn_bbox = f'vrt:///vsicurl/{path}?a_ullr=-180,90,180,-90&a_srs=EPSG:4326'
ds = rasterio.open(dsn_bbox)
gt = ds.get_transform()
## ul corner x, x pixel width, shear, ul corner y, shear, y pixel height (from top)
gebco <- "/vsicurl/https://projects.pawsey.org.au/idea-gebco-tif/GEBCO_2024.tif"
library(gdalraster)
library(wk)
library(geos)
proj <- "+proj=spilhaus"
w <- warp(gebco, tf <- "/vsimem/spil.vrt", proj, cl_arg = c("-tr", 25000, 25000))
alg/data/2by2.tif
alg/data/3by3_average.tif
alg/data/3by3_sum.tif
alg/data/4by4.tif
alg/data/bug_6526_input.tif
alg/data/contour_in.tif
alg/data/geoloc/latitude_including_pole.tif
alg/data/geoloc/longitude_including_pole.tif
alg/data/nodata_precision_issue_float32.tif
alg/data/pat.tif
##  docker run --rm -ti ghcr.io/mdsumner/gdal-builds:rocker-gdal-dev-python bash
reticulate::use_python("/workenv/bin/python3")
library(reticulate)
py_require("virtualizarr")
open_virtual_mfdataset <- import("virtualizarr")$open_virtual_mfdataset
ds <- open_virtual_mfdataset(list("https://thredds.nci.org.au/thredds/fileServer/gb6/BRAN/BRAN2023/daily/atm_flux_diag_2024_06.nc"))

Spider worldclim for urls of useable data


library(bowerbird)
my_directory <- tempdir()
cf <- bb_config(local_file_root = my_directory)

##https://geodata.ucdavis.edu/climate/worldclim/2_1/base/wc2.1_10m_tmin.zip
src <-