Skip to content

Commit c5ef27c

Browse files
committed
something is wrong with the indexing, can't match REMA to COP30 sanely
1 parent ce5d3dc commit c5ef27c

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

R/run_extract.R

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
extracted <- file.exists("longlat_points_dem.parquet")
22
Sys.setenv("AWS_NO_SIGN_REQUEST" = "YES") ## shouldn't be necessary, added in desperation during ghactions testing
3+
4+
35
if (!extracted) {
46
track <- nanoparquet::read_parquet("longlat_points.parquet")
57
library(xml2)
68
library(gdalraster)
7-
dsn <- "/vsicurl/https://raw.githubusercontent.com/mdsumner/rema-ovr/main/REMA-2m_dem_ovr.vrt"
8-
##dsn <- "/vsicurl/https://opentopography.s3.sdsc.edu/raster/COP30/COP30_hh.vrt"
9+
#dsn <- "/vsicurl/https://raw.githubusercontent.com/mdsumner/rema-ovr/main/REMA-2m_dem_ovr.vrt"
10+
dsn <- "/vsicurl/https://opentopography.s3.sdsc.edu/raster/COP30/COP30_hh.vrt"
911
url <- gsub("/vsicurl/", "", dsn)
1012
xml <- read_xml(url)
1113
dst <- xml |> xml_find_all(".//DstRect")
@@ -58,29 +60,41 @@ tile <- unlist(lapply(geos::geos_strtree_query(tree, wk::xy(xy[,1, drop = TRUE],
5860
extract_pt <- function(x) {
5961
dsn <- x$dsn[1]
6062
bbox <- x$bbox[[1]]
63+
if (x$tile[1] == 0) return(rep(NA_real_, length(x$X)))
6164
pts <- cbind(x$X, x$Y)
6265
tf <- tempfile(fileext = ".vrt")
63-
#bbbbb <- paste0(bbox, collapse = ",")
64-
#dsn <- glue::glue("vrt://{dsn}?projwin={bbbbb}")
66+
6567
translate(dsn, tf, cl_arg = c("-projwin", unname(bbox[c(1, 4, 3, 2)])), quiet = TRUE)
66-
pixel_extract(new(GDALRaster, tf), pts)
68+
ds <- new(GDALRaster, tf)
69+
on.exit(ds$close(), add = TRUE)
70+
pixel_extract(ds, pts)
6771
}
6872

6973

7074
v <- vector("list", length(unique(tile)))
7175
## create the payload
7276
for (i in seq_along(v)) {
73-
tib <- tibble::tibble(dsn = dsn, X = xy[tile == unique(tile)[i],1 , drop = TRUE],
74-
Y = xy[tile == unique(tile)[i],2 , drop = TRUE],
75-
bbox = list(bb[unique(tile)[i],, drop = TRUE]))
77+
tile_index <- unique(tile)[i]
78+
X <- xy[!is.na(tile) & tile == tile_index,1 , drop = TRUE]
79+
Y <- xy[!is.na(tile) & tile == tile_index,2 , drop = TRUE]
80+
## when we don't have a tile call it zero
81+
if (is.na(tile_index)) {
82+
tile_index <- 0
83+
Y <- X <- rep(NA, sum(is.na(tile)))
84+
print(sum(is.na(tile)))
85+
}
86+
tib <- tibble::tibble(dsn = dsn, X = X,
87+
Y = Y,
88+
bbox = list(bb[tile_index,, drop = TRUE]),
89+
tile = tile_index)
7690
v[[i]] <- tib
7791
}
7892

7993
options(parallelly.fork.enable = TRUE, future.rng.onMisuse = "ignore")
80-
library(furrr); plan(multicore)
81-
94+
library(furrr);
95+
plan(multicore)
8296
v1 <- future_map(v, extract_pt)
83-
97+
plan(sequential)
8498

8599
# for (i in seq_along(v)) {
86100
# v[[i]] <- extract_pt(dsn, bb[unique(tile)[i],, drop = TRUE], xy[tile == unique(tile)[i], , drop = FALSE])

data-raw/DATASET.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
start <- c(2e6, -1e6)
22
end <- c(1.8e6, -800000)
33
incr <- seq(0, 1, length = 10000)
4+
5+
start <- c(25000, 3e6)
6+
end <- c(25000, -2e6)
7+
48
track <- cbind(approxfun(c(0, 1), c(start[1], end[1]))(incr), approxfun(c(0, 1), c(start[2], end[2]))(incr))
59

610
longlat <- gdalraster::transform_xy(track, srs_to = "EPSG:4326", srs_from = "EPSG:3031")

longlat_points.parquet

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)