Light pollution

Create a map using radiance information from VIIRS.

Miriam Lerma true
2025-05-05

Intro

The Visible Infrared Imaging Radiometer Suite (VIIRS) is aboard the joint NASA/NOAA Suomi National Polar-orbiting Partnership (Suomi NPP) and NOAA-platforms. VIIRS collects visible and infrared imagery along with global observations of Earth’s land, atmosphere, cryosphere, and ocean.

Data

Data are available at Light pollution map.
- The data can be downloaded by selecting the icons of the tools, then the square, wait until information appears, then click in the download icon.

To download test data in tif format click here.

Select the directory where the information is stored.

library(here)
your_folder<-paste0(here(),"/_posts/2025-05-05-lightpollution")
#your_folder
#list.files(your_folder)
your_file<-paste0(your_folder,"/viirs_npp_202300b.tif")

Use the package terra to use the function rast.

The function rast reads your file as a formal class SpatRaster

Light_pollution<-rast(your_file)
crs(Light_pollution)

Use ggplot2 and tidyterra to create your plot.

ggplot() +
  geom_spatraster(data = Light_pollution) +
  scale_fill_gradient(limits = c(0,1),low = 'black', high = '#f9c74f', 
                      na.value = "grey93", 
                      breaks = c(0.02,0.20, 0.40, 0.60,0.75, 0.87)
                      )+
  NULL

Data frame

To manipulate convert to data frame.

Light_pollution_df <- as.data.frame(Light_pollution, xy = TRUE)
beepr::beep(sound=1)

The function rename, allows to change the name of the column. The radiance information is in the third column.

Light_pollution_radiance<-Light_pollution_df %>%
  rename(radiance=3)

Check if the radiance values are plausible.

range(Light_pollution_radiance$radiance)
[1]    0 2193

Basic plot

Use the function geom_spatraster to plot the radiance data.

ggplot() +
  geom_spatraster(data = Light_pollution) +
  
  coord_sf(xlim = c(4.5,9), ylim = c(53,56),
           label_axes = list(top = "E", left = "N", bottom = 'E', right='N'),
           default_crs = sf::st_crs(4326))+
  scale_fill_gradient(name='Light pollution \n in the North Sea \n Radiance ',
                      limits = c(0,1),
                      low = 'black', high = '#f9c74f', 
                      na.value = "grey93", 
                      breaks = c(0.02,0.20, 0.40, 0.60,0.75, 0.90)
                      )+
  NULL

Change theme

Change the arguments inside theme to adjust the looks of your plot.

ggplot() +
  geom_spatraster(data = Light_pollution) +
  coord_sf(xlim = c(3,9), ylim = c(53,56),
           label_axes = list(top = "E", left = "N", bottom = 'E', right='N'),
           default_crs = sf::st_crs(4326))+
  scale_fill_gradient(name='Light pollution \n in the North Sea \n Radiance ',
                      limits = c(0,1),
                      low = 'black', high = '#f9c74f', 
                      na.value = "grey93", 
                      breaks = c(0.02,0.20, 0.40, 0.60,0.75, 0.90)
                      )+
  theme_void()+
    theme(legend.background = element_rect(colour = "transparent", fill = "transparent"),
        legend.position = c(0.20,0.30),
        panel.background = element_rect(fill = 'black'),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, size=1.5),
        legend.text=element_text(color='#f9c74f',size=12),
        legend.title=element_text(color='#f9c74f',size=12))+ 
  NULL

Change fill

Select some colors create a color palette.

color_NA <-"#000000"
color_K <-"#ffff3f"
color_J <-"#eeef20"
color_I <-"#dddf00"
color_H <-"#d4d700"
color_G <-"#bfd200"
color_F <-"#aacc00"
color_E <-"#80b918"
color_D <-"#55a630"
color_C <-"#2b9348"
color_B <-"#007f5f"
color_A <-"#548c2f"
your_palette<-c(color_NA,color_A,color_B,color_C,color_D,color_E,color_F,color_G,color_H,color_I,color_J,color_K)

Include scale_fill_gradientn to use the color palette.

ggplot() +
  geom_spatraster(data = Light_pollution) +
 
  coord_sf(xlim = c(3,9), ylim = c(53,56),
           label_axes = list(top = "E", left = "N", bottom = 'E', right='N'),
           default_crs = sf::st_crs(4326))+
 
  theme_void()+
    theme(legend.background = element_rect(colour = "transparent", fill = "transparent"),
        legend.position = c(0.20,0.30),
        panel.background = element_rect(fill = 'black'),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, size=1.5),
        legend.text=element_text(color='#f9c74f',size=12),
        legend.title=element_text(color='#f9c74f',size=12))+
  
  scale_fill_gradientn(name='Light pollution \n in the North Sea \n Radiance ',
                      limits = c(0,1),
                      colours = your_palette,
                      na.value = "grey93", 
                      breaks = c(0.02,0.20, 0.40, 0.60,0.75, 0.90)
                      )+
  NULL

Add text

Add text using the function annotate for reference.

ggplot() +
  geom_spatraster(data = Light_pollution) +
 
  coord_sf(xlim = c(3,9), ylim = c(53,56),
           label_axes = list(top = "E", left = "N", bottom = 'E', right='N'),
           default_crs = sf::st_crs(4326))+
 
  theme_void()+
    theme(legend.background = element_rect(colour = "transparent", fill = "transparent"),
        legend.position = c(0.20,0.30),
        panel.background = element_rect(fill = 'black'),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.border = element_rect(colour = "black", fill=NA, size=1.5),
        legend.text=element_text(color='#f9c74f',size=12),
        legend.title=element_text(color='#f9c74f',size=12))+
  
  scale_fill_gradientn(name='Light pollution \n in the North Sea \n Radiance ',
                      limits = c(0,1),
                      colours = your_palette,
                      na.value = "grey93", 
                      breaks = c(0.02,0.20, 0.40, 0.60,0.75, 0.90)
                      )+
annotate("text", x = 7.885143539318454-1.6, y = 54.181291760152874,
           label = "Helgoland",size=5,color='#d6d6d6',hjust = 0)

Further read