NASA Soil Moisture Active-Passive (SMAP) data are hosted on a server by the National Snow and Ice Data Center. The smapr package provides the find_smap function which searches for specific data products and returns a dataframe of available data.
library(smapr)
library(raster)
## Loading required package: sp
#> Loading required package: sp
available_data <- find_smap(id = "SPL3SMAP", date = "2015-06-19", version = 3)
str(available_data)
## 'data.frame': 1 obs. of 3 variables:
## $ name: chr "SMAP_L3_SM_AP_20150619_R13080_001"
## $ date: Date, format: "2015-06-19"
## $ dir : chr "SPL3SMAP.003/2015.06.19/"
#> '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/"
Given a dataframe produced by find_smap, the download_map function downloads the data onto the local file system. Unless a directory is specified as an argument, the data are stored in the user’s cache.
downloads <- download_smap(available_data)
str(downloads)
## 'data.frame': 1 obs. of 4 variables:
## $ name : chr "SMAP_L3_SM_AP_20150619_R13080_001"
## $ date : Date, format: "2015-06-19"
## $ dir : chr "SPL3SMAP.003/2015.06.19/"
## $ local_dir: chr "C:\\Users\\Iván Lizarazo\\AppData\\Local\\smap\\smap\\Cache"
The SMAP data are provided in HDF5 format. The list_map function allows users to inspect the contents of downloaded data at a high level (all=FALSE) or in depth (all=TRUE).
list_smap(downloads, all = FALSE)
## $SMAP_L3_SM_AP_20150619_R13080_001
## group name otype dclass dim
## 0 / Metadata H5I_GROUP
## 1 / Soil_Moisture_Retrieval_Data H5I_GROUP
list_smap(downloads, all = TRUE)
## $SMAP_L3_SM_AP_20150619_R13080_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_AP
## 22 /Metadata/Lineage MetadataConfiguration
## 23 /Metadata/Lineage OutputConfiguration
## 24 /Metadata/Lineage RunConfiguration
## 25 /Metadata OrbitMeasuredLocation
## 26 /Metadata ProcessStep
## 27 /Metadata ProductSpecificationDocument
## 28 /Metadata QADatasetIdentification
## 29 /Metadata SeriesIdentification
## 30 / Soil_Moisture_Retrieval_Data
## 31 /Soil_Moisture_Retrieval_Data EASE_column_index
## 32 /Soil_Moisture_Retrieval_Data EASE_row_index
## 33 /Soil_Moisture_Retrieval_Data albedo
## 34 /Soil_Moisture_Retrieval_Data alpha_tbh_hh
## 35 /Soil_Moisture_Retrieval_Data alpha_tbv_vv
## 36 /Soil_Moisture_Retrieval_Data bare_soil_roughness_retrieved
## 37 /Soil_Moisture_Retrieval_Data beta_tbh_hh
## 38 /Soil_Moisture_Retrieval_Data beta_tbv_vv
## 39 /Soil_Moisture_Retrieval_Data distance_from_nadir
## 40 /Soil_Moisture_Retrieval_Data freeze_thaw_fraction
## 41 /Soil_Moisture_Retrieval_Data gamma_hh_xpol
## 42 /Soil_Moisture_Retrieval_Data gamma_vv_xpol
## 43 /Soil_Moisture_Retrieval_Data landcover_class
## 44 /Soil_Moisture_Retrieval_Data latitude
## 45 /Soil_Moisture_Retrieval_Data longitude
## 46 /Soil_Moisture_Retrieval_Data radar_vegetation_index
## 47 /Soil_Moisture_Retrieval_Data retrieval_qual_flag
## 48 /Soil_Moisture_Retrieval_Data sigma0_hh_aggregated
## 49 /Soil_Moisture_Retrieval_Data sigma0_vv_aggregated
## 50 /Soil_Moisture_Retrieval_Data sigma0_xpol_aggregated
## 51 /Soil_Moisture_Retrieval_Data soil_moisture
## 52 /Soil_Moisture_Retrieval_Data soil_moisture_std_dev
## 53 /Soil_Moisture_Retrieval_Data spacecraft_overpass_time_seconds
## 54 /Soil_Moisture_Retrieval_Data spacecraft_overpass_time_utc
## 55 /Soil_Moisture_Retrieval_Data surface_flag
## 56 /Soil_Moisture_Retrieval_Data surface_temperature
## 57 /Soil_Moisture_Retrieval_Data tb_h_disaggregated
## 58 /Soil_Moisture_Retrieval_Data tb_h_disaggregated_qual_flag
## 59 /Soil_Moisture_Retrieval_Data tb_h_disaggregated_std
## 60 /Soil_Moisture_Retrieval_Data tb_v_disaggregated
## 61 /Soil_Moisture_Retrieval_Data tb_v_disaggregated_qual_flag
## 62 /Soil_Moisture_Retrieval_Data tb_v_disaggregated_std
## 63 /Soil_Moisture_Retrieval_Data vegetation_opacity
## 64 /Soil_Moisture_Retrieval_Data vegetation_water_content
## 65 /Soil_Moisture_Retrieval_Data water_body_fraction
## 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_DATASET INTEGER 3856 x 1624
## 32 H5I_DATASET INTEGER 3856 x 1624
## 33 H5I_DATASET FLOAT 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 FLOAT 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 INTEGER 3856 x 1624
## 44 H5I_DATASET FLOAT 3856 x 1624
## 45 H5I_DATASET FLOAT 3856 x 1624
## 46 H5I_DATASET FLOAT 3856 x 1624
## 47 H5I_DATASET INTEGER 3856 x 1624
## 48 H5I_DATASET FLOAT 3856 x 1624
## 49 H5I_DATASET FLOAT 3856 x 1624
## 50 H5I_DATASET FLOAT 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 STRING 3856 x 1624
## 55 H5I_DATASET INTEGER 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 FLOAT 3856 x 1624
## 60 H5I_DATASET FLOAT 3856 x 1624
## 61 H5I_DATASET INTEGER 3856 x 1624
## 62 H5I_DATASET FLOAT 3856 x 1624
## 63 H5I_DATASET FLOAT 3856 x 1624
## 64 H5I_DATASET FLOAT 3856 x 1624
## 65 H5I_DATASET FLOAT 3856 x 1624
c1 <- cbind(-73.9, 3.8)
c2 <- cbind(-73.9, 4.8)
c3 <- cbind(-72.9, 4.8)
c4 <- cbind(-72.9, 3.8)
r1 <- rbind(c1,c2,c3,c4)
P1 <- Polygon(r1)
Ps1 <- Polygons(list(P1), ID="roi")
SPs <- SpatialPolygons(list(Ps1))
df <- data.frame(N="zona", row.names="roi")
SPDF <- SpatialPolygonsDataFrame(SPs, data=df)
proj4string(SPDF) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")
The extract_smap function extracts gridded data products and return Raster* objects.
sm_raster <- extract_smap(downloads, "Soil_Moisture_Retrieval_Data/soil_moisture")
new.crs <- proj4string(SPDF)
sm_rep <- projectRaster(sm_raster, crs = new.crs)
plot(sm_rep, main="Level 3 soil moisture: 19 June 2015")
sm.crop<- crop(sm_rep,SPDF)
W <- shapefile("C:\\Users\\Iván Lizarazo\\Documents\\UN\\datos\\soilmoisture\\piedemonte\\WGuatiquia_Negro.shp")
plot(sm.crop, main="Level 3 soil moisture: 19 June 2015")
plot(W, add=TRUE)
The raster object can be saved as GeoTIFF using the writeRaster function from the raster package.
sm.crop
## class : RasterLayer
## dimensions : 14, 11, 154 (nrow, ncol, ncell)
## resolution : 0.0934, 0.0706 (x, y)
## extent : -73.8976, -72.8702, 3.783902, 4.772302 (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0
## data source : in memory
## names : SMAP_L3_SM_AP_20150619_R13080_001
## values : 0.1116916, 0.5280839 (min, max)
writeRaster(sm.crop, "C:\\Users\\Iván Lizarazo\\Documents\\UN\\datos\\soilmoisture\\piedemonte\\test\\smap_19Jun2015.tif", overwrite=TRUE)