{"id":18722626,"url":"https://github.com/mdsumner/grainy","last_synced_at":"2025-11-11T05:30:21.812Z","repository":{"id":72211520,"uuid":"561583671","full_name":"mdsumner/grainy","owner":"mdsumner","description":"Raster logic, in an object","archived":false,"fork":false,"pushed_at":"2022-11-06T09:50:53.000Z","size":144,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-28T12:17:04.532Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mdsumner.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-04T02:21:16.000Z","updated_at":"2022-11-06T09:37:27.000Z","dependencies_parsed_at":"2023-02-22T17:16:19.986Z","dependency_job_id":null,"html_url":"https://github.com/mdsumner/grainy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2Fgrainy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2Fgrainy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2Fgrainy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsumner%2Fgrainy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdsumner","download_url":"https://codeload.github.com/mdsumner/grainy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239587244,"owners_count":19663892,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T13:42:15.931Z","updated_at":"2025-11-11T05:30:21.767Z","avatar_url":"https://github.com/mdsumner.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# grainy\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/mdsumner/grainy/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mdsumner/grainy/actions/workflows/R-CMD-check.yaml)\n\u003c!-- badges: end --\u003e\n\nThe goal of grainy is to encapsulate the logic of a raster grid in an object. \n\n## Installation\n\nYou can install the development version of grainy like so:\n\n``` r\nremotes::install_github(\"mdsumner/grainy\")\n```\n\n## Example\n\nThis is a basic example which shows you how to solve a common problem:\n\n```{r example}\nlibrary(grainy)\ng \u003c- grain$new(c(360, 180), c(-180, 180, -90, 90))\ng$cell_from_xy(cbind(0, 0))\n\n## compare to raster/terra/stars/etc\n#library(raster)\n#cellFromXY(raster(extent(-180, 180, -90, 90), ncols = 360, nrows = 180), cbind(0, 0))\n```\n\n\nThis means we can encapsulate this basic information and use it conveniently. \n\n```{r raster}\nu \u003c- \"/vsicurl/https://opentopography.s3.sdsc.edu/raster/COP30/COP30_hh.vrt\"\n## get information about a raster\ninfo \u003c- vapour::vapour_raster_info(u)\n\nCOP30 \u003c- grain$new(info$dimension, info$extent)\n```\n\nWhat is the extent of COP30? \n\n```{r extent}\nCOP30$plot_extent()\n```\n\nWhat exact region would we get from a vague query? \n\n```{r extent1}\nex \u003c- COP30$vcrop(c(144.3578, 148.374, -43.7, -41))\n\nregion \u003c- grain$new(ex$dimension, ex$extent)\n\nCOP30$plot_extent()\nregion$plot_extent(add = TRUE)\n```\n\nLet's get that data but at reduced resolution. \n\n```{r reduced}\nreduced \u003c- grain$new(region$dimension %/% 30, region$extent)\n\nv \u003c- vapour::vapour_warp_raster_int(u, extent = reduced$extent, dimension = reduced$dimension)\nstr(v)\n\nxyz \u003c- reduced$listxyz(data = matrix(v, reduced$dimension[2], byrow = TRUE))\nimage(xyz, asp = 1/cos(mean(xyz$y) * pi/180), useRaster = TRUE)\nmaps::map(add = TRUE)\n```\n\n\nTreat the VRT like a list of files, and zoom in on our region for the COG urls of interest. \n\n```{r zoom }\nu \u003c- \"/vsicurl/https://opentopography.s3.sdsc.edu/raster/COP30/COP30_hh.vrt\"\n\n## ok so what have we got\ninfo \u003c- vapour::vapour_raster_info(u)\nexts \u003c- vaster::extent_vrt(gsub(\"/vsicurl/\", \"\", u))\n\ng \u003c- grain$new(info$dimension, info$extent)\ng$plot_extent()\nregion0  \u003c- g$vcrop(c(144.3578, 148.374, -43.7, -41))\n\nregion \u003c- grain$new(region0$dimension, region0$extent)\n\nrect(exts[,1] ,exts[,3], exts[,2], exts[,4])\n\n## each row in  ext corresponds to an element in info$filelist[-1] so\n\nfiles \u003c- tibble::tibble(dsn = info$filelist[-1], xmin = exts[,1], xmax = exts[,2], ymin = exts[,3], ymax = exts[,4])\n\nlocalfiles \u003c- files |\u003e dplyr::filter(xmin \u003e= region$x_min(), xmax \u003c= region$x_max(), \n                       ymin \u003e= region$y_min(), ymax \u003c= region$y_max())\n\n\n## it's a bit quicker to use the only files involved, but not much\n\nv \u003c- vapour::vapour_warp_raster_int(localfiles$dsn, extent = region$extent, dimension = region$dimension)\n#v \u003c- vapour::vapour_warp_raster_int(u, extent = region$extent, dimension = region$dimension)\n\n```\n\n\n\n## Code of Conduct\n  \nPlease note that the grainy project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdsumner%2Fgrainy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdsumner%2Fgrainy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdsumner%2Fgrainy/lists"}