--- title: "India electrification trends with VIIRS" description: > Download VIIRS/Black Marble annual composites, extract panel statistics by state, and plot electrification trends over time. output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{India electrification trends with VIIRS} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", dev.args = list(bg = "transparent") ) ``` ## Get a NASA Earthdata token 1. Register at 2. Go to Profile → Generate Token 3. `Sys.setenv(EARTHDATA_TOKEN = "YOUR_TOKEN")`, or pass the token directly to `earthdata_token("TOKEN")` Tiles are cached in `~/.lightson/cache/` after the first download. ## Quick workflow ```{r ten-lines, eval = FALSE} library(lightson) token <- earthdata_token() rasters <- ntl_download(region = "IND", years = 2015:2025, token = token) districts <- get_india_admin(level = "district") panel <- extract_panel(rasters, districts) plot_ntl_trend(panel, region = "Lucknow") ``` ## Use your own shape/boundary file `extract_panel()` accepts any `sf` object: ```{r custom-boundary, eval = FALSE} library(sf) my_districts <- sf::read_sf("~/github/bharatviz/public/India_LGD_districts.geojson") panel2 <- extract_panel(rasters, my_districts, id_col = "district_name") ``` See the *Custom geometry* vignette for a complete walkthrough using bharatviz boundaries with Bhuvan NTL rasters, which need only ISRO's public API.