knitr::opts_chunk$set(
  fig.height=4, 
  fig.width=7,
  collapse = TRUE,
  comment = "#>"
)

NASAaccess package has multiple functions such as GPM_NRT, GPMpolyCentroid and GPMswat that download, extract, and reformat rainfall remote sensing data of TRMM and IMERG from NASA servers for grids within a specified watershed shapefile. The difference between GPM_NRT and GPMswat functions is the latency period. The GPMswat function retrieves the IMERG Final Run data which is intended for research quality global multi-satellite precipitation estimates with quasi-Lagrangian time interpolation, gauge data, and climatological adjustment. On the other hand, the GPM_NRT function retrieves the IMERG near real-time low-latency gridded global multi-satellite precipitation estimates.

Let's explore GPMpolyCentroid and GPMswat functions.

Basic use

Let's look at an example watershed that we want to examine near Houston, TX:

library(leaflet)
library(ggplot2)
library(terra)
#Reading input data
dem_path <- system.file("extdata", 
                        "DEM_TX.tif", 
                        package = "NASAaccess")

shape_path <- system.file("extdata", 
                          "basin.shp", 
                          package = "NASAaccess")


dem <- terra::rast(dem_path)



shape <- terra::vect(shape_path)






#plot the watershed data
myMap <- leaflet() %>% 
                addTiles() %>% 
                fitBounds(-96, 29.7, -95.2, 30) %>% 
                addPolygons(lng=terra::crds(shape)[,1],
                           lat=terra::crds(shape)[,2])

myMap

The geographic layout of the White Oak Bayou watershed example used in this demonstration is depicted above. Whiteoak Bayou is a tributary for the Buffalo Bayou River (Harris County, Texas). In order to use NASAaccess we also need a digital elevation model (DEM) raster layer. Let's see the White Oak Bayou watershed DEM and a more closer look at the study watershed example.

# create a plot of our DEM raster along with watershed (i.e., elevation in meters)

plot(dem,main="White Oak Bayou Watershed with Digital Elevation Model (DEM)")

plot(shape , add = TRUE)

Now, let's examine GPMswat:

library(NASAaccess)

GPMswat(Dir = "./GPMswat/",
                  watershed = shape_path,
                  DEM = dem_path,
                  start = "2020-08-1",
                  end = "2020-08-3")

Examining the rainfall station file generated by GPMswat

GPMswat.precipitationMaster <- system.file('extdata/GPMswat',
                                         'precipitationMaster.txt', 
                                         package = 'NASAaccess')

# reading GPMswat header file
GPMswat.table<-read.csv(GPMswat.precipitationMaster)

head(GPMswat.table)

dim(GPMswat.table)

GPMswat generated ascii table for each available grid located within the study watershed. There are 11 grids within the study watershed and that means 11 tables have been generated. GPMswat also generated the rainfall stations file input shown above GPMswat.table (table with columns: ID, File NAME, LAT, LONG, and ELEVATION) for those selected grids that fall within the specified watershed.

Now, let's see the location of these generated grid points:

library(ggplot2)
library(tidyterra)

ggplot(shape) + 
      geom_spatvector(color='red',fill=NA) +
      geom_point(data=GPMswat.table,
             aes(x=LONG,
                 y=LAT,
                 fill=ELEVATION), 
             shape=21, 
             size = 4) +
     scale_fill_gradientn(colours = terrain.colors(7))

We note here that GPMswat has given us all the GPM data grids that fall within the boundaries of the White Oak Bayou study watershed. The time series rainfall data stored in the data tables (i.e., 11 tables) can be viewed also. looking at reformatted data from the first grid point as listed in the rainfall station file generated by GPMswat.

GPMswat.point.data <- system.file('extdata/GPMswat',
                              'precipitation2160842.txt', 
                              package = 'NASAaccess')

# reading data records
read.csv(GPMswat.point.data)

The GPMswat has generated a ready format ascii tables that can be ingested easily to the Soil and Water Assessment Tool SWAT model or any other hydrological model of choice.

Now, let's examine GPMpolyCentroid.

GPMpolyCentroid(Dir = "./GPMpolyCentroid/",
                  watershed = shape_path,
                  DEM = dem_path,
                  start = "2019-08-1",
                  end = "2019-08-3")

Examining the rainfall station file generated by GPMpolyCentroid

library(ggplot2)
library(tidyterra)


GPMpolyCentroid.precipitationMaster <- system.file('extdata/GPMpolyCentroid',
                                                    'precipitationMaster.txt', 
                                                    package = 'NASAaccess')

GPMpolyCentroid.precipitation.table <- read.csv(GPMpolyCentroid.precipitationMaster)

# plotting

ggplot(shape) + 

      geom_spatvector(color='red',fill=NA) +

      geom_point(data=GPMpolyCentroid.precipitation.table,
             aes(x=LONG,y=LAT))

We note here that GPMpolyCentroid has given us the GPM data grid that falls within a specified watershed and assigns a pseudo rainfall gauge located at the centroid of the watershed a weighted-average daily rainfall data.

Let's examine the precipitation data just obtained by GPMpolyCentroid over the White Oak Bayou study watershed.

GPMpolyCentroid.precipitation.record <- system.file('extdata/GPMpolyCentroid',
                                                    'precipitation1.txt', 
                                                    package = 'NASAaccess')

GPMpolyCentroid.precipitation.data <- read.csv(GPMpolyCentroid.precipitation.record)

# since data started on 2019-08-01

days <- seq.Date(from = as.Date('2019-08-01'), 
                 length.out = dim(GPMpolyCentroid.precipitation.data)[1],
                 by = 'day')

# plotting the precipitation time series

plot(days, GPMpolyCentroid.precipitation.data [,1], 
                                    pch = 19, ylab= '(mm)', 
                                    xlab = '', 
                                    type = 'b',
     main="White Oak Bayou Watershed precipitation (GPM)")

The time series plot above gives the rainfall amounts in (mm) at the centroid of the White Oak Bayou watershed during 2019-August-01 to 2019-August-03.

Last but not least, let's examine the near real time precipitation data obtained by GPM_NRT over the White Oak Bayou study watershed. Remember that the minimum latency for GPM_NRT is one day. You can experiment this function with yesterday data, nice!

GPM_NRT(Dir = "./GPMswat/",
                  watershed = shape_path,
                  DEM = dem_path,
                  start = "2022-07-1",
                  end = "2022-07-3")

Let's see one point data record. See that the data starts on July 1, 2022 and ends on July 3rd, 2022.

GPM_NRT.point.data <- system.file('extdata/GPM_NRT',
                              'precipitation2160845.txt', 
                              package = 'NASAaccess')

#Reading data records
read.csv(GPM_NRT.point.data)

Built with

sessionInfo()


imohamme/nasaaccess documentation built on Nov. 14, 2024, 11:24 a.m.