Why this notebook?

This notebook outlines a basic use workflow for the smapr library. It illustrates how to acquire and process NASA (Soil Moisture Active-Passive) SMAP data, crop the data to match the extent of the area of interest, save the output, and generate some simple visualizations.

This notebook aims to help Geomatica Basica students at Universidad Nacional de Colombia with their home activities during this time of social distancing. This notebook has been created, parsed, and published using R Studio Cloud. Students needs to replicate it in order to get the SMAP dataset needed for conducting spatial interpolation tasks in the upcoming weeks. Please make sure to complete this task not later than 30th May.

SMAP data products

Multiple SMAP data products are provided by the U.S. National Snow & Ice Data Center (NSIDC). The SMAP products vary in the amount of processing. Currently, smapr primarily supports level 3 and level 4 data products, which represent global daily composite and global three hourly modeled data products, respectively. NSIDC provides documentation for all SMAP data products on their website, and we provide a summary of data products supported by smapr below.

The Level 1 products contain raw or calibrated and geolocated instrument measurements from the SMAP Radar and Radiometer; all Level 1 products have a temporal resolution of 49 minutes, the length of time required for the SMAP satellite to complete a half orbit of the Earth. The Level 2 products contain soil moisture retrievals derived from Level 1 products and ancillary files; all Level 2 products are based on half orbits, with a temporal resolution of 49 minutes. The Level 3 products are daily composites of the Level 2 soil moisture and freeze/thaw state data. The Level 4 products provide model-derived root-zone soil moisture and carbon net ecosystem exchange.

SMAP Products This notebook uses the level 4 SPL4SMAU (Surface/Rootzone Soil Moisture Analysis Update) data product.

NSIDC Authentication

Access to the NASA SMAP data requires authentication through NASA’s Earthdata portal. If you do not already have a username and password through Earthdata, you can register for an account here: https://urs.earthdata.nasa.gov/ You cannot use the smapr package without an Earthdata account.

Once you have an account, you need to pass your Earthdata username (ed_un) and password (ed_pw) as environmental variables that can be read from within your R session. There are a couple of ways to do this:

This is the recommended approach for authentication:

Use set_smap_credentials(‘yourusername’, ‘yourpasswd’). This will save your credentials by default, overwriting existing credentials if overwrite = TRUE.

Note that these credentials needs to be passed later, that is, after loading the smapr library

Installing packages

The code chunks comprising this section need to be completed using the R console.

## do not uncomment
## run the following line from R console:
## remotes::install_github("wilkelab/isoband")
## do not uncomment
## run the following command from the R console:
## BiocManager::install("rhdf5")
## it may take several minutes
## do not uncomment
## run the following command from the R console:
## install.packages("smapr")

Loading libraries

## Loading required package: sp
## rgdal: version: 1.4-8, (SVN revision 845)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.2.2, released 2017/09/15
##  Path to GDAL shared files: /usr/share/gdal/2.2
##  GDAL binary built with GEOS: TRUE 
##  Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 492]
##  Path to PROJ.4 shared files: (autodetected)
##  Linking to sp version: 1.4-1
## Linking to GEOS 3.5.1, GDAL 2.2.2, PROJ 4.9.2
## Loading required package: raster
## Loading required package: lattice
## Loading required package: latticeExtra

Authentication

Set your credentials now, using the following command within a code chunk:

set_smap_credentials(‘user_name’, ‘password’, overwrite=TRUE)

Note that I inserted such a chunk but using {r include=FALSE} to have the code evaluated, but neither the code nor its output displayed.

Typical workflow

At a high level, most workflows follow these steps:

Each of these steps are outlined below:

Finding SMAP data

Let’s remind that data are hosted on a server by the NSIDC. The find_smap() function searches for specific data products and returns a data frame of available data. As data mature and pass checks, versions advance. At any specific time, not all versions of all datasets for all dates may exist. For the most up to date overview of dataset versions, see the NSIDC SMAP data version webpage.

The following are examples of the available products (the identification goes into parenthesis):

  • SMAP L4 Global 3-hourly 9 km EASE-Grid Surface and Root Zone Soil Moisture Geophysical Data (SPL4SMGP)

  • SMAP L4 Global 3-hourly 9 km EASE-Grid Surface and Root Zone Soil Moisture Analysis Update (SPL4SMAU)

  • SMAP L4 Global 9 km EASE-Grid Surface and Root Zone Soil Moisture Land Model Constants (SPL4SMLM) SOIL CLASSIFICATION, SOIL DEPTH, SOIL POROSITY, SOIL TEXTURE, TERRAIN ELEVATION

Let’s try to find the product identified as SPL3SMP_E. If the version number is not right, an error message will appear:

# 
# https://n5eil01u.ecs.nsidc.org/SMAP/SPL4SMAU.004/
# SPL4SMAU
#
# SPL2SMP_E.003 
# https://nsidc.org/data/SPL4SMLM/versions/4
# 
available_data <- find_smap(id = "SPL4SMAU", date = "2020-04-10", version = 4)
str(available_data)
## 'data.frame':    8 obs. of  3 variables:
##  $ name: chr  "SMAP_L4_SM_aup_20200410T030000_Vv4030_001" "SMAP_L4_SM_aup_20200410T060000_Vv4030_001" "SMAP_L4_SM_aup_20200410T090000_Vv4030_001" "SMAP_L4_SM_aup_20200410T120000_Vv4030_001" ...
##  $ date: Date, format: "2020-04-10" "2020-04-10" ...
##  $ dir : chr  "SPL4SMAU.004/2020.04.10/" "SPL4SMAU.004/2020.04.10/" "SPL4SMAU.004/2020.04.10/" "SPL4SMAU.004/2020.04.10/" ...
#> 'data.frame':    1 obs. of  3 variables:
#>  $ name: chr "SMAP_L3_SM_AP_20150525_R13080_001"
#>  $ date: Date, format: "2015-05-25"
#>  $ dir : chr "SPL3SMAP.003/2015.05.25/"

Download data

We are interested in the product identified as SMAP Enhanced L3 Radiometer Global Daily 9 km EASE-Grid Soil Moisture, Version 3. The next figure describes several characteristics of this product. What are the variables provided with this product?

Users can download SMAP data directly from the NSIDC website (i.e using the web interface). Usually, the data comprise two files: a bigger file contains the data in HDF5 format (.h5); and a smaller file contains metadata in XML format.

For more information about HDF5 files, including an HDF5 tutorial, visit the HDF Group’s HDF5 website.

files <- find_smap(id = "SPL3SMP_E", dates = "2020-04-28", version = 3)

Check the result:

files

Lets’ download the data to a local directory. Note that I may take several minutes.

local_dir <- "./soil"
downloads <- download_smap(files[1, ], local_dir)
## Downloading https://n5eil01u.ecs.nsidc.org/SMAP/SPL3SMP_E.003/2020.04.28/SMAP_L3_SM_P_E_20200428_R16515_001.h5
## Downloading https://n5eil01u.ecs.nsidc.org/SMAP/SPL3SMP_E.003/2020.04.28/SMAP_L3_SM_P_E_20200428_R16515_001.qa
## Downloading https://n5eil01u.ecs.nsidc.org/SMAP/SPL3SMP_E.003/2020.04.28/SMAP_L3_SM_P_E_20200428_R16515_001.h5.iso.xml

Note that the size of the downloaded file is about 350 MB.

downloads

The SMAP data are provided in HDF5 format, and in any one file there are actually multiple data sets, including metadata. The list_smap function allows users to inspect the contents of downloaded data at a high level (all = FALSE) or in depth (all = TRUE).

Now, let’s inspect what is inside the downloaded file:

list_smap(downloads, all = TRUE)
## $SMAP_L3_SM_P_E_20200428_R16515_001
##                                   group                            name
## 0                                     /                        Metadata
## 1                             /Metadata          AcquisitionInformation
## 2      /Metadata/AcquisitionInformation                        platform
## 3      /Metadata/AcquisitionInformation                platformDocument
## 4      /Metadata/AcquisitionInformation                           radar
## 5      /Metadata/AcquisitionInformation                   radarDocument
## 6      /Metadata/AcquisitionInformation                      radiometer
## 7      /Metadata/AcquisitionInformation              radiometerDocument
## 8                             /Metadata                     DataQuality
## 9                 /Metadata/DataQuality            CompletenessOmission
## 10                /Metadata/DataQuality               DomainConsistency
## 11                            /Metadata           DatasetIdentification
## 12                            /Metadata                          Extent
## 13                            /Metadata       GridSpatialRepresentation
## 14  /Metadata/GridSpatialRepresentation                          Column
## 15  /Metadata/GridSpatialRepresentation                  GridDefinition
## 16  /Metadata/GridSpatialRepresentation          GridDefinitionDocument
## 17  /Metadata/GridSpatialRepresentation                             Row
## 18                            /Metadata                         Lineage
## 19                    /Metadata/Lineage                  EASEGRID_LON_M
## 20                    /Metadata/Lineage              InputConfiguration
## 21                    /Metadata/Lineage                         L2_SM_P
## 22                    /Metadata/Lineage                       L2_SM_P_E
## 23                    /Metadata/Lineage           MetadataConfiguration
## 24                    /Metadata/Lineage             OutputConfiguration
## 25                    /Metadata/Lineage                RunConfiguration
## 26                            /Metadata           OrbitMeasuredLocation
## 27                            /Metadata                     ProcessStep
## 28                            /Metadata    ProductSpecificationDocument
## 29                            /Metadata         QADatasetIdentification
## 30                            /Metadata            SeriesIdentification
## 31                                    / Soil_Moisture_Retrieval_Data_AM
## 32     /Soil_Moisture_Retrieval_Data_AM               EASE_column_index
## 33     /Soil_Moisture_Retrieval_Data_AM                  EASE_row_index
## 34     /Soil_Moisture_Retrieval_Data_AM                          albedo
## 35     /Soil_Moisture_Retrieval_Data_AM             boresight_incidence
## 36     /Soil_Moisture_Retrieval_Data_AM                    bulk_density
## 37     /Soil_Moisture_Retrieval_Data_AM                   clay_fraction
## 38     /Soil_Moisture_Retrieval_Data_AM            freeze_thaw_fraction
## 39     /Soil_Moisture_Retrieval_Data_AM             grid_surface_status
## 40     /Soil_Moisture_Retrieval_Data_AM                        latitude
## 41     /Soil_Moisture_Retrieval_Data_AM               latitude_centroid
## 42     /Soil_Moisture_Retrieval_Data_AM                       longitude
## 43     /Soil_Moisture_Retrieval_Data_AM              longitude_centroid
## 44     /Soil_Moisture_Retrieval_Data_AM       radar_water_body_fraction
## 45     /Soil_Moisture_Retrieval_Data_AM             retrieval_qual_flag
## 46     /Soil_Moisture_Retrieval_Data_AM           roughness_coefficient
## 47     /Soil_Moisture_Retrieval_Data_AM                   soil_moisture
## 48     /Soil_Moisture_Retrieval_Data_AM             soil_moisture_error
## 49     /Soil_Moisture_Retrieval_Data_AM      static_water_body_fraction
## 50     /Soil_Moisture_Retrieval_Data_AM                    surface_flag
## 51     /Soil_Moisture_Retrieval_Data_AM             surface_temperature
## 52     /Soil_Moisture_Retrieval_Data_AM     surface_water_fraction_mb_h
## 53     /Soil_Moisture_Retrieval_Data_AM     surface_water_fraction_mb_v
## 54     /Soil_Moisture_Retrieval_Data_AM                  tb_3_corrected
## 55     /Soil_Moisture_Retrieval_Data_AM                  tb_4_corrected
## 56     /Soil_Moisture_Retrieval_Data_AM                  tb_h_corrected
## 57     /Soil_Moisture_Retrieval_Data_AM                tb_h_uncorrected
## 58     /Soil_Moisture_Retrieval_Data_AM                  tb_qual_flag_3
## 59     /Soil_Moisture_Retrieval_Data_AM                  tb_qual_flag_4
## 60     /Soil_Moisture_Retrieval_Data_AM                  tb_qual_flag_h
## 61     /Soil_Moisture_Retrieval_Data_AM                  tb_qual_flag_v
## 62     /Soil_Moisture_Retrieval_Data_AM                 tb_time_seconds
## 63     /Soil_Moisture_Retrieval_Data_AM                     tb_time_utc
## 64     /Soil_Moisture_Retrieval_Data_AM                  tb_v_corrected
## 65     /Soil_Moisture_Retrieval_Data_AM                tb_v_uncorrected
## 66     /Soil_Moisture_Retrieval_Data_AM              vegetation_opacity
## 67     /Soil_Moisture_Retrieval_Data_AM        vegetation_water_content
## 68                                    / Soil_Moisture_Retrieval_Data_PM
## 69     /Soil_Moisture_Retrieval_Data_PM            EASE_column_index_pm
## 70     /Soil_Moisture_Retrieval_Data_PM               EASE_row_index_pm
## 71     /Soil_Moisture_Retrieval_Data_PM                       albedo_pm
## 72     /Soil_Moisture_Retrieval_Data_PM          boresight_incidence_pm
## 73     /Soil_Moisture_Retrieval_Data_PM                 bulk_density_pm
## 74     /Soil_Moisture_Retrieval_Data_PM                clay_fraction_pm
## 75     /Soil_Moisture_Retrieval_Data_PM         freeze_thaw_fraction_pm
## 76     /Soil_Moisture_Retrieval_Data_PM          grid_surface_status_pm
## 77     /Soil_Moisture_Retrieval_Data_PM            latitude_centroid_pm
## 78     /Soil_Moisture_Retrieval_Data_PM                     latitude_pm
## 79     /Soil_Moisture_Retrieval_Data_PM           longitude_centroid_pm
## 80     /Soil_Moisture_Retrieval_Data_PM                    longitude_pm
## 81     /Soil_Moisture_Retrieval_Data_PM    radar_water_body_fraction_pm
## 82     /Soil_Moisture_Retrieval_Data_PM          retrieval_qual_flag_pm
## 83     /Soil_Moisture_Retrieval_Data_PM        roughness_coefficient_pm
## 84     /Soil_Moisture_Retrieval_Data_PM          soil_moisture_error_pm
## 85     /Soil_Moisture_Retrieval_Data_PM                soil_moisture_pm
## 86     /Soil_Moisture_Retrieval_Data_PM   static_water_body_fraction_pm
## 87     /Soil_Moisture_Retrieval_Data_PM                 surface_flag_pm
## 88     /Soil_Moisture_Retrieval_Data_PM          surface_temperature_pm
## 89     /Soil_Moisture_Retrieval_Data_PM  surface_water_fraction_mb_h_pm
## 90     /Soil_Moisture_Retrieval_Data_PM  surface_water_fraction_mb_v_pm
## 91     /Soil_Moisture_Retrieval_Data_PM               tb_3_corrected_pm
## 92     /Soil_Moisture_Retrieval_Data_PM               tb_4_corrected_pm
## 93     /Soil_Moisture_Retrieval_Data_PM               tb_h_corrected_pm
## 94     /Soil_Moisture_Retrieval_Data_PM             tb_h_uncorrected_pm
## 95     /Soil_Moisture_Retrieval_Data_PM               tb_qual_flag_3_pm
## 96     /Soil_Moisture_Retrieval_Data_PM               tb_qual_flag_4_pm
## 97     /Soil_Moisture_Retrieval_Data_PM               tb_qual_flag_h_pm
## 98     /Soil_Moisture_Retrieval_Data_PM               tb_qual_flag_v_pm
## 99     /Soil_Moisture_Retrieval_Data_PM              tb_time_seconds_pm
## 100    /Soil_Moisture_Retrieval_Data_PM                  tb_time_utc_pm
## 101    /Soil_Moisture_Retrieval_Data_PM               tb_v_corrected_pm
## 102    /Soil_Moisture_Retrieval_Data_PM             tb_v_uncorrected_pm
## 103    /Soil_Moisture_Retrieval_Data_PM           vegetation_opacity_pm
## 104    /Soil_Moisture_Retrieval_Data_PM     vegetation_water_content_pm
##           otype  dclass         dim
## 0     H5I_GROUP                    
## 1     H5I_GROUP                    
## 2     H5I_GROUP                    
## 3     H5I_GROUP                    
## 4     H5I_GROUP                    
## 5     H5I_GROUP                    
## 6     H5I_GROUP                    
## 7     H5I_GROUP                    
## 8     H5I_GROUP                    
## 9     H5I_GROUP                    
## 10    H5I_GROUP                    
## 11    H5I_GROUP                    
## 12    H5I_GROUP                    
## 13    H5I_GROUP                    
## 14    H5I_GROUP                    
## 15    H5I_GROUP                    
## 16    H5I_GROUP                    
## 17    H5I_GROUP                    
## 18    H5I_GROUP                    
## 19    H5I_GROUP                    
## 20    H5I_GROUP                    
## 21    H5I_GROUP                    
## 22    H5I_GROUP                    
## 23    H5I_GROUP                    
## 24    H5I_GROUP                    
## 25    H5I_GROUP                    
## 26    H5I_GROUP                    
## 27    H5I_GROUP                    
## 28    H5I_GROUP                    
## 29    H5I_GROUP                    
## 30    H5I_GROUP                    
## 31    H5I_GROUP                    
## 32  H5I_DATASET INTEGER 3856 x 1624
## 33  H5I_DATASET INTEGER 3856 x 1624
## 34  H5I_DATASET   FLOAT 3856 x 1624
## 35  H5I_DATASET   FLOAT 3856 x 1624
## 36  H5I_DATASET   FLOAT 3856 x 1624
## 37  H5I_DATASET   FLOAT 3856 x 1624
## 38  H5I_DATASET   FLOAT 3856 x 1624
## 39  H5I_DATASET INTEGER 3856 x 1624
## 40  H5I_DATASET   FLOAT 3856 x 1624
## 41  H5I_DATASET   FLOAT 3856 x 1624
## 42  H5I_DATASET   FLOAT 3856 x 1624
## 43  H5I_DATASET   FLOAT 3856 x 1624
## 44  H5I_DATASET   FLOAT 3856 x 1624
## 45  H5I_DATASET INTEGER 3856 x 1624
## 46  H5I_DATASET   FLOAT 3856 x 1624
## 47  H5I_DATASET   FLOAT 3856 x 1624
## 48  H5I_DATASET   FLOAT 3856 x 1624
## 49  H5I_DATASET   FLOAT 3856 x 1624
## 50  H5I_DATASET INTEGER 3856 x 1624
## 51  H5I_DATASET   FLOAT 3856 x 1624
## 52  H5I_DATASET   FLOAT 3856 x 1624
## 53  H5I_DATASET   FLOAT 3856 x 1624
## 54  H5I_DATASET   FLOAT 3856 x 1624
## 55  H5I_DATASET   FLOAT 3856 x 1624
## 56  H5I_DATASET   FLOAT 3856 x 1624
## 57  H5I_DATASET   FLOAT 3856 x 1624
## 58  H5I_DATASET INTEGER 3856 x 1624
## 59  H5I_DATASET INTEGER 3856 x 1624
## 60  H5I_DATASET INTEGER 3856 x 1624
## 61  H5I_DATASET INTEGER 3856 x 1624
## 62  H5I_DATASET   FLOAT 3856 x 1624
## 63  H5I_DATASET  STRING 3856 x 1624
## 64  H5I_DATASET   FLOAT 3856 x 1624
## 65  H5I_DATASET   FLOAT 3856 x 1624
## 66  H5I_DATASET   FLOAT 3856 x 1624
## 67  H5I_DATASET   FLOAT 3856 x 1624
## 68    H5I_GROUP                    
## 69  H5I_DATASET INTEGER 3856 x 1624
## 70  H5I_DATASET INTEGER 3856 x 1624
## 71  H5I_DATASET   FLOAT 3856 x 1624
## 72  H5I_DATASET   FLOAT 3856 x 1624
## 73  H5I_DATASET   FLOAT 3856 x 1624
## 74  H5I_DATASET   FLOAT 3856 x 1624
## 75  H5I_DATASET   FLOAT 3856 x 1624
## 76  H5I_DATASET INTEGER 3856 x 1624
## 77  H5I_DATASET   FLOAT 3856 x 1624
## 78  H5I_DATASET   FLOAT 3856 x 1624
## 79  H5I_DATASET   FLOAT 3856 x 1624
## 80  H5I_DATASET   FLOAT 3856 x 1624
## 81  H5I_DATASET   FLOAT 3856 x 1624
## 82  H5I_DATASET INTEGER 3856 x 1624
## 83  H5I_DATASET   FLOAT 3856 x 1624
## 84  H5I_DATASET   FLOAT 3856 x 1624
## 85  H5I_DATASET   FLOAT 3856 x 1624
## 86  H5I_DATASET   FLOAT 3856 x 1624
## 87  H5I_DATASET INTEGER 3856 x 1624
## 88  H5I_DATASET   FLOAT 3856 x 1624
## 89  H5I_DATASET   FLOAT 3856 x 1624
## 90  H5I_DATASET   FLOAT 3856 x 1624
## 91  H5I_DATASET   FLOAT 3856 x 1624
## 92  H5I_DATASET   FLOAT 3856 x 1624
## 93  H5I_DATASET   FLOAT 3856 x 1624
## 94  H5I_DATASET   FLOAT 3856 x 1624
## 95  H5I_DATASET INTEGER 3856 x 1624
## 96  H5I_DATASET INTEGER 3856 x 1624
## 97  H5I_DATASET INTEGER 3856 x 1624
## 98  H5I_DATASET INTEGER 3856 x 1624
## 99  H5I_DATASET   FLOAT 3856 x 1624
## 100 H5I_DATASET  STRING 3856 x 1624
## 101 H5I_DATASET   FLOAT 3856 x 1624
## 102 H5I_DATASET   FLOAT 3856 x 1624
## 103 H5I_DATASET   FLOAT 3856 x 1624
## 104 H5I_DATASET   FLOAT 3856 x 1624

Let’s plot the soil_moisture_pm slot of the downloaded file:

# $SMAP_L3_SM_AP_20150525_R13080_001
sm_raster <- extract_smap(downloads, "/Soil_Moisture_Retrieval_Data_PM/soil_moisture_pm")
## sm_raster <- extract_smap("./soil/SMAP_L4_Antioquia/SMAP_L4_SM_lmc_00000000T000000_Vv4030_001", ## "/Geophysical_Data/sm_rootzone_wetness")
plot(sm_raster, main = "Level 3 soil moisture: 28 March 2020")

What is sm_raster?

sm_raster
## class      : RasterLayer 
## dimensions : 1624, 3856, 6262144  (nrow, ncol, ncell)
## resolution : 9008.055, 9008.054  (x, y)
## extent     : -17367530, 17367530, -7314540, 7314540  (xmin, xmax, ymin, ymax)
## crs        : +proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
## source     : /home/rstudio-user/.cache/smap/tmp.tif 
## names      : SMAP_L3_SM_P_E_20200428_R16515_001 
## values     : 0.01999992, 0.882247  (min, max)

Note the dimensions, the resolution, and the values’ range.

What is the crs of the rasterLayer?

crs(sm_raster)
## CRS arguments:
##  +proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m
## +no_defs +ellps=WGS84 +towgs84=0,0,0

Let’s read a shapefile corresponding to Antioquia Departament:

antio <- read_sf("./antioquia/ADMINISTRATIVO/MGN_DPTO_POLITICO.shp")

What is antio?

antio

As you could have guessed, it is simple feature collection with 1 feature. Let’s map the collection:

# do not run 
#antio %>% aoi_map(returnMap = T)

What is the vector data extent?

extent(antio)
## class      : Extent 
## xmin       : -77.12783 
## xmax       : -73.88128 
## ymin       : 5.418558 
## ymax       : 8.873974

Note that it uses a geographic coordinate reference system. Let’s reproject the vector data to match the rasterLayer crs:

cea_antioquia <- st_transform(antio, crs = crs(sm_raster))

What is the new coordinate reference system?

crs(cea_antioquia)
## [1] "+proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs "

Let’s clip the soil moisture data:

# Crop soil moisture data by extent of departamento Antioquia
smap.sub <- crop(sm_raster, extent(cea_antioquia))

What is smap.sub?

smap.sub
## class      : RasterLayer 
## dimensions : 48, 35, 1680  (nrow, ncol, ncell)
## resolution : 9008.055, 9008.054  (x, y)
## extent     : -7440654, -7125372, 693620.2, 1126007  (xmin, xmax, ymin, ymax)
## crs        : +proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
## source     : memory
## names      : SMAP_L3_SM_P_E_20200428_R16515_001 
## values     : 0.1139517, 0.5621499  (min, max)

Create a function to normalize raster values, i.e. multiply each value by 100.

normalize <- function(x) {
  return(round(100*x))
}

Use the normalize function:

smap_new = normalize(smap.sub)  

Check the result:

smap_new
## class      : RasterLayer 
## dimensions : 48, 35, 1680  (nrow, ncol, ncell)
## resolution : 9008.055, 9008.054  (x, y)
## extent     : -7440654, -7125372, 693620.2, 1126007  (xmin, xmax, ymin, ymax)
## crs        : +proj=cea +lon_0=0 +lat_ts=30 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
## source     : memory
## names      : layer 
## values     : 11, 56  (min, max)

Now, mask the raster Layer (please review the mask function documentation).

smap_new2 <- mask(x = smap_new, mask = cea_antioquia)

Plotting time. Note that we can create our palette (here, its name is pal). You may use different colors. Make sure to review this link.

pal <- colorNumeric(c( "#FFFFCC", "#41B6C4","#0C2C84"), values(smap_new2),
  na.color = "transparent")

leaflet() %>% addTiles() %>%
  addRasterImage(smap_new2, colors = pal, opacity = 0.8) %>%
  addLegend(pal = pal, values = values(smap_new2),
    title = "Soil moisture in Antioquia on 28 March 2020 [%]")

Now, let’s save the soil moisture dataset for an upcoming task, spatial interpolation. We will use the writeRaster function.

sm <- writeRaster(smap_new2, filename="./soil/sm_antioquia_28_04_2020.tif", format="GTiff", datatype='INT1U', overwrite=TRUE)

Note that datatype is a very important parameter for writing a raster file.

After running the writeRaster code, you should have the intended .tif file in the output directory (here, its name is soil).

Now, it is your turn to replicate, adapt and improve this notebook. Use your own study area as defined in the course. Be as creative as possible. Good luck!!!

sessionInfo()
## R version 3.6.0 (2019-04-26)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 16.04.6 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/atlas-base/atlas/libblas.so.3.0
## LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0
## 
## locale:
##  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
##  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
##  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
## [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] knitr_1.28          leaflet_2.0.3       rasterVis_0.47     
##  [4] latticeExtra_0.6-29 lattice_0.20-38     raster_3.0-12      
##  [7] smapr_0.2.1         sf_0.9-1            rgdal_1.4-8        
## [10] sp_1.4-1           
## 
## loaded via a namespace (and not attached):
##  [1] zoo_1.8-7          xfun_0.12          rhdf5_2.30.1       colorspace_1.4-1  
##  [5] vctrs_0.2.4        htmltools_0.4.0    viridisLite_0.3.0  base64enc_0.1-3   
##  [9] yaml_2.2.1         rlang_0.4.5        pillar_1.4.3       e1071_1.7-3       
## [13] hexbin_1.28.1      glue_1.4.0         DBI_1.1.0          selectr_0.4-2     
## [17] rappdirs_0.3.1     RColorBrewer_1.1-2 jpeg_0.1-8.1       lifecycle_0.2.0   
## [21] stringr_1.4.0      munsell_0.5.0      rvest_0.3.5        htmlwidgets_1.5.1 
## [25] codetools_0.2-16   evaluate_0.14      crosstalk_1.1.0.1  parallel_3.6.0    
## [29] curl_4.3           class_7.3-15       fansi_0.4.1        Rcpp_1.0.4.6      
## [33] KernSmooth_2.23-15 scales_1.1.0       classInt_0.4-3     jsonlite_1.6.1    
## [37] farver_2.0.3       png_0.1-7          digest_0.6.25      stringi_1.4.6     
## [41] grid_3.6.0         cli_2.0.2          tools_3.6.0        magrittr_1.5      
## [45] tibble_3.0.0       pkgconfig_2.0.3    crayon_1.3.4       ellipsis_0.3.0    
## [49] xml2_1.3.1         assertthat_0.2.1   rmarkdown_2.1      httr_1.4.1        
## [53] Rhdf5lib_1.8.0     R6_2.4.1           units_0.6-6        compiler_3.6.0