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
## whereever SGAT code does this: 


library(maptools)
data("wrld_simpl")
## Cells per degree
n <- 1
grid <- raster(nrows=n*diff(ylim),ncols=n*diff(xlim),
  xmn=xlim[1],xmx=xlim[2],ymn=ylim[1],ymx=ylim[2],
gdalinfo "/vsicurl/https://n5eil01u.ecs.nsidc.org/AMSA/AU_SI12.001/2012.07.02/AMSR_U2_L3_SeaIce12km_B04_20120702.he5" -sd 26
Driver: HDF5Image/HDF5 Dataset
Files: /vsicurl/https://n5eil01u.ecs.nsidc.org/AMSA/AU_SI12.001/2012.07.02/AMSR_U2_L3_SeaIce12km_B04_20120702.he5
Size is 608, 896
Metadata:
  Conventions=CF-1.6
  HDFEOS_INFORMATION_HDFEOSVersion=HDFEOS_5.1.15
  history=This version of the Sea Ice processing code contains updates provided by the science team on September 16, 2019. For details on these updates, see the release notes provided in the DAP.
  institution=NASA's AMSR Science Investigator-led Processing System (SIPS)

See

> ## Number of chunks and runs per chunk
> chunks <- 250
> runs <- 40
> plan(multisession, workers= availableCores()-1)
Error: Cannot create 127 parallel PSOCK nodes. Each node needs one connection, but there are only 124 connections left out of the maximum 128 available on this R installation

GeoBox from a DSN

def extent(dimension, transform): 
  return [transform[0], transform[0] + dimension[0] * transform[1], 
  transform[3] + dimension[1] * transform[5], transform[3]]
  
  
def bbox(dimension, transform): 
library(duckdbfs)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.9.0dev-cb4d30f56d, PROJ 9.3.1; sf_use_s2() is
#> TRUE
library(raster)
#> Loading required package: sp


## threshold is roughly side length in metres of the roi, i.e. sqrt(area)
dem_source <- function(threshold = 1) {

I don't entirely trust the timings here, but it's faster (maybe 2x faster to plot).

  dsn <- "WMTS:https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/WMTS/1.0.0/WMTSCapabilities.xml"

library(gdalraster)
#> GDAL 3.9.0dev-cb4d30f56d, released 2024/04/15 (debug build), GEOS 3.12.1, PROJ 9.3.1


ds_int <- new(GDALRaster, sprintf("vrt://%s?ot=Int32", dsn))
from osgeo import gdal
gdal.UseExceptions()



## we do something with vrt
dsn = "vrt:///vsicurl/https://github.com/cran/rgl/raw/master/inst/textures/worldsmall.png?a_ullr=-180,90,180,-90&amp;expand=rgb"