diff --git a/.Rbuildignore b/.Rbuildignore deleted file mode 100644 index 112ad26..0000000 --- a/.Rbuildignore +++ /dev/null @@ -1,3 +0,0 @@ -^.*\.Rproj$ -^\.Rproj\.user$ -^\.travis\.yml$ diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 807ea25..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.Rproj.user -.Rhistory -.RData diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8275323..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -# Sample .travis.yml for R projects - -language: r -warnings_are_errors: true -sudo: required - -env: - global: - - CRAN: http://cran.rstudio.com - -notifications: - email: - on_success: change - on_failure: change diff --git a/DESCRIPTION b/DESCRIPTION deleted file mode 100644 index 781c520..0000000 --- a/DESCRIPTION +++ /dev/null @@ -1,20 +0,0 @@ -Type: Package -Package: MSScvm -Title: Automated Cloud Masking for Landsat MSS Images -Version: 1.0.0 -Date: 2015-07-23 -Authors@R: c(person("Justin", "Braaten", email = "jstnbraaten@gmail.com", role = c("aut", "cre")), - person("Warren", "Cohen", email = "warren.cohen@oregonstate.edu", role = "aut"), - person("Zhiqiang", "Yang", email = "zhiqiang.yang@oregonstate.edu", role = "aut")) -Description: An automated cloud and cloud shadow masking system for Landsat MSS imagery. It provides a means of more easily incorporating MSS imagery in large-area and time series analysis by providing an efficient way to prevent cloud and cloud shadow pixels from contaminating mosaics, composites, and time series. -Depends: R (>= 3.2.1) -Imports: - gdalUtils, - igraph, - raster, - rgdal, - SDMTools -SystemRequirements: GDAL binaries -License: GPL-2 -URL: http://www.msscvm.jdbcode.com/ -LazyData: true diff --git a/MSScvm.Rproj b/MSScvm.Rproj deleted file mode 100644 index 1788e68..0000000 --- a/MSScvm.Rproj +++ /dev/null @@ -1,18 +0,0 @@ -Version: 1.0 - -RestoreWorkspace: Default -SaveWorkspace: Default -AlwaysSaveHistory: Default - -EnableCodeIndexing: Yes -UseSpacesForTab: Yes -NumSpacesForTab: 2 -Encoding: UTF-8 - -RnwWeave: Sweave -LaTeX: pdfLaTeX - -BuildType: Package -PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source -PackageRoxygenize: rd,collate,namespace,vignette diff --git a/NAMESPACE b/NAMESPACE deleted file mode 100644 index add79b1..0000000 --- a/NAMESPACE +++ /dev/null @@ -1,10 +0,0 @@ -# Generated by roxygen2 (4.1.1): do not edit by hand - -export(MSScvm) -export(MSSdn2rad) -export(MSSdn2refl) -export(MSSunpack) -export(eudist) -export(getMetadata) -export(mosaicDEMs) -export(reprojectDEM) diff --git a/R/MSScvm.r b/R/MSScvm.r deleted file mode 100644 index 88cb96a..0000000 --- a/R/MSScvm.r +++ /dev/null @@ -1,344 +0,0 @@ -#' Landsat MSS cloud and cloud shadow masking -#' -#' Creates a cloud and cloud shadow mask for Landsat MSS imagery. -#' @param imgDir directory name (character). Full path to a MSS image directory produced by the \code{\link{MSSunpack}} function. -#' @param demFile filename (character). Full path to image-corresponding DEM file. -#' @param classify logical. If TRUE clouds, cloud shadows, and clear pixels have unique values (0 = clear, 1 = cloud shadow, 2 = cloud). -#' If FALSE obscured pixles = 0 and clear = 1. -#' @details It is important that the input DEM file, specified by the 'demFile' parameter, be the same projection and pixel resolution as the -#' input image. It must also be >= in spatial extent, relative to the image. The program will check for these attributes and throw an error message if -#' there is a violation. There are two helper functions to prepare a suitable DEM. Use the \code{\link{reprojectDEM}} function to ensure proper projection -#' and pixel resolution of an exisiting DEM, and the \code{\link{mosaicDEMs}} function to create a mosaic from several DEMs to ensure proper extent, projection, -#' and pixel resolution. -#' @return A GeoTIFF raster image file with the same dimensions as the MSS image. The file will be placed in the -#' 'imgDir' directory with the name equal to the image ID followed by '_msscvm'. -#' @examples -#' \dontrun{ -#' -#' MSScvm(imgDir = "C:/mss/LM10360321973191AAA04", -#' demFile = "C:/mss/dem/wrs1_p036r032_dem.tif") -#' } -#' @export - - -MSScvm = function(imgDir, demFile, classify=F){ - - - - #get the image file and check - files = list.files(imgDir, full.names=T) - refl_match = grep("toa_reflectance.tif$", files) - if(length(refl_match) != 1){ - dn_match = grep("dn.tif$", files) - if(length(dn_match) != 1){ - print(paste("Can't find a '*toa_reflectance.tif' or '*dn.tif' file in the directory:", imgDir)) - print("Please check that the 'imgDir' parameter path is correct and that it contains either a '*toa_reflectance.tif' or '*dn.tif' file") - stop("Stopping MSScvm") - } else { - match = dn_match - imgtype = "dn" - } - } else { - match = refl_match - imgtype = "refl" - } - - imgfile = files[match] - print(paste("Making cloud & shadow mask for",basename(imgfile))) - - #get some info about the image - ref = raster::raster(imgfile) #read in the MSS file for information on image extent and as a template for holding values later - dem = raster::raster(demFile) #read in the DEM file - raster package function - demproj = raster::projection(dem) - imgproj = raster::projection(ref) - demres = raster::xres(dem) - imgres = raster::xres(ref) - - #check to make the DEM and image resolutions are the same - if(demres != imgres){ - print(paste("The DEM file:",demFile,"does not have the same pixel resolution as the image file.")) - print("Please make sure the DEM file has the same pixel resolution as the image file. Use the function 'reprojectDEM' to assist in getting it in the same resolution") - stop("Stopping MSScvm") - } - - #check to make the DEM and image projections are the same - if(demproj != imgproj){ - print(paste("The DEM file:",demFile,"does not have the same projection as the image file.")) - print("Please make sure the DEM file is the same projection as the image file. Use the function 'reprojectDEM' to assist in getting it in the same projection") - stop("Stopping MSScvm") - } - - #check to make sure the extent of teh DEM is at least as big as the image - demext = raster::extent(dem) - imgext = raster::extent(ref) - - demokay = demext@ymax >= imgext@ymax & - demext@ymin <= imgext@ymin & - demext@xmin <= imgext@xmin & - demext@xmax >= imgext@xmax - - if(demokay == F){ - print(paste("The DEM file:",demFile,"does not fully intersect the image file.")) - print("Please make sure the DEM file is larger in extent than the image file. Use the function 'mosaicDEMs' to assist in making a larger DEM") - stop("Stopping MSScvm") - } - - #get some info about the image - info = getMetadata(imgfile) #get the image MTL metadata: sunelev, sunaz, sunzen, gain, bias, sensor, etc - used in calulating illumination and in projecting clouds - reso = raster::xres(ref) #get the image resolution - it should be 60m - used during cloud projection - sunzen = info$sunzen*(pi/180) #get sun zenith angle in radians for cos - - - if(imgtype == "dn"){ - #convert from DN to TOA reflectance - #define the TOA reflectance function - refl = function(file, band, gain, bias, sunzen, d, esun){ - img = raster::as.matrix(raster::raster(file, band)) #read in the file - img = (gain*img)+bias #convert to TOA radiance #link to equations to convert DN to TOA radiance - http://landsat.usgs.gov/how_is_radiance_calculated.php - img[img < 0] = 0 #make sure values less than 0 are set to 0 - negative radiance doesn't make sense - img = (pi * img * (d^2))/(esun * cos(sunzen)) #convert from TOA radiance to TOA reflectance #link to the equations to convert TOA radiance to TOA reflectance - http://landsathandbook.gsfc.nasa.gov/data_prod/prog_sect11_3.html - img = round(img * 10000) #scale by 10000 and round so we aren't working with floating point - return(img) #pass the TOA reflectance image back - } - - #define esun values for MSS (chander et al 2009 summary of current radiometric calibration coefficients... RSE 113) - if(info$sensor == "LANDSAT_1"){esun = c(1823,1559,1276,880.1)} #for "LANDSAT 1" - if(info$sensor == "LANDSAT_2"){esun = c(1829,1539,1268,886.6)} #for "LANDSAT 2" - if(info$sensor == "LANDSAT_3"){esun = c(1839,1555,1291,887.9)} #for "LANDSAT 3" - if(info$sensor == "LANDSAT_4"){esun = c(1827,1569,1260,866.4)} #for "LANDSAT 4" - if(info$sensor == "LANDSAT_5"){esun = c(1824,1570,1249,853.4)} #for "LANDSAT 5" - - #prepare some variables for converting DN to TOA reflectance - d = eudist(info$doy) #get the earth sun distance for the image day-of-year - - #apply the TOA reflectance function to the DN MSS image bands 1, 2, and 4 - b1 = refl(imgfile, 1 ,info$b1gain, info$b1bias, sunzen, d, esun[1]) #get TOA reflectance for MSS band 1 - b2 = refl(imgfile, 2 ,info$b2gain, info$b2bias, sunzen, d, esun[2]) #get TOA reflectance for MSS band 2 - b4 = refl(imgfile, 4 ,info$b4gain, info$b4bias, sunzen, d, esun[4]) #get TOA reflectance for MSS band 4 - } - - - if(imgtype == "refl") { - #load in the image bands - b1 = raster::as.matrix(raster::raster(imgfile, 1)) #band 1 - b2 = raster::as.matrix(raster::raster(imgfile, 2)) #band 2 - b4 = raster::as.matrix(raster::raster(imgfile, 4)) #band 4 - } - - - #crop the hillshade layer - dem_ex = raster::alignExtent(dem, ref, snap="near") #aligned the extent of the DEM to the image - raster package function - raster::extent(dem) = dem_ex #set the DEM extend to aligned extent - raster package function - dem = raster::crop(dem,ref) #crop the DEM to size of the image - - - #make slope, aspect, and illumination images - used for topographic correction - slope = raster::terrain(dem, opt="slope") #create slope from preped DEM - aspect = raster::terrain(dem, opt="aspect") #create slope from preped DEM - ill = raster::as.matrix(raster::hillShade(slope, aspect, angle=info$sunelev, direction=info$sunaz, normalize=F)) #create illumination from slope and aspect, convert to matrix for faster processing - - - #apply topographic correction to band 4 for identifying cloud shadows - k=0.55 #set the k constant - c = (cos(sunzen)/ill)^k #apply the minnaert topographic correction - b4topoc = round(b4*c) #round the values - probably not important, possibly faster processing and saves memory - - - #identify the cloud pixels - ndgr = (b1-b2)/(b1+b2) #normalized difference between MSS band 1 and 2 - clouds = which(ndgr > 0.0 & b1 > 1750 | b1 > 3900) #apply cloud thresholds to "ndgr" and on band 1 - - - #find cloud shadows - #model the topo-corrected band 4 cloud shadow theshold - b4topoc[clouds] = NA #set the cloud pixels in topo-corrected band 4 to NA - b4nocldmean = mean(b4topoc, na.rm=T) #get the mean of the non-cloud pixel in topo-corrected band 4 - shadowthresh1 = round(0.40 * b4nocldmean + 247.97) #apply line equation to calculate the provisional topo-corrected band 4 cloud shadow theshold - nocldorshdw = which(b4topoc > shadowthresh1) #find the topo-corrected band 4 pixels that are considered provisional cloud shadow - b4nocldorshdw = b4topoc[nocldorshdw] #pull out the topo-corrected band 4 pixels that are not cloud shadow - b4nocldorshdwmean = mean(b4nocldorshdw, na.rm=T) #get the mean of the non-cloud, non-provisional cloud shadow pixels in topo-corrected band 4 - shadowthresh2 = round(0.47 * b4nocldorshdwmean + 73.23) #apply line equation to calculate the final topo-corrected band 4 cloud shadow theshold - - #identify the cloud shadow pixels - shadows = which(b4topoc <= shadowthresh2) #apply cloud shadow threshold to topo-corrected band 4 - - - #find water - slope = raster::as.matrix(slope) #convert slope to matric for faster processing - ndvi = (b4-b2)/(b4+b2) #calculate NDVI from MSS band 2 and 4 - waterpixels = which(ndvi < 0.0850 & slope < (0.5*(pi/180))) #apply thresholds to ndvi and slope - looking for nearly flat pixels that look like water in NDVI - - - #make some blank matrices to holder the water, shadow, and cloud layers - b1[] = 0 #set all the pixels in MSS band 1 matrix to 0 as a image template holder - water=shadow=cloud=b1 #copy the template holder as a water, shadow, and cloud layer - - - #reduce used data - b1=b2=b4=ill=slope=ndgr=b4nocldorshdw=b4topoc=nocldorshdw=0 #reduce memory - - - #spatial sieve on water clumps that are too small (produces better looking and more accurate final mask) - water[waterpixels] = 1 #in the empty water layer, set the water pixels to value 1 (all other values are 0) - #clumps = .Call("ccl", water, PACKAGE = "SDMTools") #find clumps of water pixels - clumps = SDMTools::ConnCompLabel(water) - clumps = raster::setValues(ref, clumps) #convert the clumps image (which is a matrix) into a raster - fre = raster::freq(clumps) #use the raster function "freq" to count the number of pixels in each clump - these = which(fre[,2] < 7) #find the clumps that are smaller than 7 pixels (we don't consider these as water - just noise) - values = fre[these,1] #pull out the too-small clump id values from the frequency table - m = match(raster::as.matrix(clumps), values) #first convert the clumps raster to a matrix for faster processing, then identify too-small clumps - these = which(is.na(m) == F) #find which pixels are associated with too-small clumps - water[these] = 0 #set the too-small clump pixels as 0 (not water) in the water layer - - - #apply a 2-pixel buffer to the sieved water layer - helps capture mixed shore/water pixels - water = raster::setValues(ref,water) #convert the water layer from matrix to raster so the raster "focal" function can be used - water = raster::focal(water, w=matrix(1,5,5), fun=max, na.rm=T) #use the raster focal function to apply a buffer around water clumps - waterpixels = which(raster::as.matrix(water) == 1) #convert water back to matrix for faster processing and identify the water pixels - - - #set the cloud shadow layer - shadow[shadows] = 1 #in the empty cloud shadow layer, set the cloud shadow pixels to value 1 (all other values are 0) - shadow[waterpixels] = 0 #set the water pixels to 0 (not cloud shadow) - - - #set the cloud layer - cloud[clouds] = 1 #in the empty cloud layer, set the cloud pixels to value 1 (all other values are 0) - - - #spatial sieve on cloud clumps that are too small (produces better looking and more accurate final mask) -same process as above for water layer - #clumps = .Call("ccl", cloud, PACKAGE = "SDMTools") - clumps = SDMTools::ConnCompLabel(cloud) - clumps = raster::setValues(ref, clumps) - fre = raster::freq(clumps) - these = which(fre[,2] < 10) #note that this sieve size is < 10 (water is < 7) - values = fre[these,1] - m = match(raster::as.matrix(clumps), values) - these = which(is.na(m) == F) - cloud[these] = 0 - - - #apply a 2-pixel buffer to the sieved cloud layer - helps capture cloud edges - same process as for the above water layer - cloud = raster::setValues(ref,cloud) - cloud = raster::focal(cloud, w=matrix(1,5,5), fun=max, na.rm=F, pad=T, padValue=0) - - - #getting ready to project the cloud layer out as potential area of cloud shadow - #create a kernal to slide over the cloud layer - r = raster::raster(ncol=31,nrow=31) #create a 1860m square raster - ext = raster::extent(0, 31, 0, 31) #define its extent - raster::extent(r) = ext #set its extent - raster::projection(r) = imgproj #set its projection - r[] = NA #fill the raster with NA - r[16,16] = 1 #set the center pixel of the raster to 1 - dist = raster::gridDistance(r, 1) #find the distance of all pixels in the raster to the center pixel - kernal = dist <= 16 #set all pixel in raster that have a distance to the center pixel <= 16 as 1 - creates a circular pattern of value 1 around the center of the raster with a radius of 15 pixels (900m) - - - #put a 15 pixel buffer around the clouds in the cloud layer - cloudproj = raster::focal(cloud, w=raster::as.matrix(kernal), fun=max, na.rm=F, pad=T, padValue=0) #w needs to be a matrix, but kernal is a raster - - #set up the start and end points of the cloud projection based on the image's sun elevation and a low cloud height of 1000m and high cloud height of 7000m - shiftstart = 1000/tan((pi/180)*info$sunelev) #calculate the starting distance - shiftend = 7000/tan((pi/180)*info$sunelev) #calculate the ending distance - shiftlen = seq(shiftstart,shiftend,900) #create a sequence of equal interval distances (900m) between the start and end distances - - - #create a function to shift the cloud image a distance away from its original position - shiftit = function(cloudproj,shiftlen,info,reso){ - if(info$sunaz > 90 & info$sunaz <= 180){ #sun projects to the NW - #do some trigonometry to figure out how many meters in x and y the shift needs to be made, based on the sun azimuth and projection length - angle = info$sunaz - 90 #need to get the azimuth in the right context - yshift = round((sin((pi/180)*angle) * shiftlen * 1)/reso)*reso #calculate the y shift - xshift = round((cos((pi/180)*angle) * shiftlen * -1)/reso)*reso #calculate the x shift - - #shift the cloud projection layer - cloudproj = raster::shift(cloudproj, x=xshift, y=yshift) - } - if(info$sunaz > 0 & info$sunaz <= 90){ #sun projects to the SW - angle = 90 - info$sunaz - yshift = round((sin((pi/180)*angle) * shiftlen * -1)/reso)*reso - xshift = round((cos((pi/180)*angle) * shiftlen * -1)/reso)*reso - cloudproj = raster::shift(cloudproj, x=xshift, y=yshift) - } - if(info$sunaz <= 0 & info$sunaz >= -90){ #sun projects to the SE - angle = info$sunaz - -90 - yshift = round((sin((pi/180)*angle) * shiftlen * -1)/reso)*reso - xshift = round((cos((pi/180)*angle) * shiftlen * 1)/reso)*reso - cloudproj = raster::shift(cloudproj, x=xshift, y=yshift) - } - if(info$sunaz <= -90 & info$sunaz >= -180){ #sun projects to the NE - angle = -90 - info$sunaz - yshift = round((sin((pi/180)*angle) * shiftlen * 1)/reso)*reso - xshift = round((cos((pi/180)*angle) * shiftlen * 1)/reso)*reso - cloudproj = raster::shift(cloudproj, x=xshift, y=yshift) - } - return(cloudproj) - } - - - #iterate through all the shift distances using the "shiftit" function just defined - it will create rasters on-the-fly and write a line of code to combine each shift into a mosaic - for(m in 1:length(shiftlen)){ - if(m == 1){mergeit = "r1"} else {mergeit = paste(mergeit,",r",m, sep="")} - dothis = paste("r",m,"=shiftit(cloudproj,shiftlen[m],info,reso)", sep="") - eval(parse(text=dothis)) - if(m == length(shiftlen)){mergeit = paste("cloudproj = raster::mosaic(",mergeit,",fun=max)", sep="")} - } - - - #run the mosiac line of code created above - eval(parse(text=mergeit)) - - - #prepare the the cloudproj layer for intersecting the cloud shadow layer - cloudproj[!is.finite(raster::values(cloudproj))] = 0 #make sure that all values are finite in the cloud projection layer, the mosaicing function with max can cause some problems where there are no pixels - cloudproj = raster::extend(cloudproj, cloud, value=0) #extend the cloud projection layer so it has a full union with the cloud layer - cloudproj = raster::crop(cloudproj, cloud) #crop the cloud projection layer by the cloud layer - - - #convert the cloud shadow layer to a raster to match the class of the cloud projection layer - shadow = raster::setValues(ref,shadow) - - - #get the intersection of the cloud shadow layer and cloud projection layer - shadow = shadow*cloudproj - - - #convert the final cloud shadow layer to a matrix for spatial sieve - shadow = raster::as.matrix(shadow) - - - #spatial sieve on cloud shadow clumps that are too small (produces better looking and more accurate final mask) - same process as above for water and cloud layer - #clumps = .Call("ccl", shadow, PACKAGE = "SDMTools") - clumps = SDMTools::ConnCompLabel(shadow) - clumps = raster::setValues(ref, clumps) - fre = raster::freq(clumps) - these = which(fre[,2] < 10) #note that this sieve size is < 10 (water is < 7) - values = fre[these,1] - m = match(raster::as.matrix(clumps), values) - these = which(is.na(m) == F) - shadow[these] = 0 - shadow = raster::setValues(ref, shadow) - - - #apply a 2-pixel buffer to the sieved cloud shadow layer - helps capture shadow edges - same process as for the above water and cloud layer - shadow = raster::focal(shadow, w=matrix(1,5,5), fun=max, na.rm=F, pad=T, padValue=0) - - - #deal with either classifying cloud, cloud shadow, and clear-view separately or treat as binary obsured/clear-view - if(classify == T){ #if classify == T, then cloud, cloud shadow, and clear view will each be assigned a unique value clear-view=0, cloud shadow=1, cloud=2 - cloud = cloud*2 #if classify == T make the cloud pixels in the cloud layer have a value of 2, clear-view is already 0 and cloud shadow is already 1 - cloudshadow = raster::mosaic(cloud,shadow,fun=max, na.rm=T) #create a mosaic of the cloud, and cloud shadow layers - cloud takes precedence where they overlap - } else { #if classify == F, then - cloudshadow = sum(cloud, shadow, na.rm=T) #combine the cloud and cloud shadow layers - cloudshadow = raster::setValues(ref,as.numeric(raster::values(cloudshadow) == 0)) #set obscured pixels to value 0 and clear-view to 1. This makes for easy masking of images, just multiply the mask by the image - } - - - cloudshadow[is.na(ref)] = NA - cloudshadow = as(cloudshadow, "SpatialGridDataFrame") - #write out the mask - outfile = file.path(dirname(imgfile),paste(substr(basename(imgfile),1,21),"_msscvm.tif",sep="")) #define a file name for the mask - uses same directory as the image and then use the image ID and appends "_cloudmask.tif" for the name - rgdal::writeGDAL(cloudshadow, outfile, drivername = "GTiff", type = "Byte", mvFlag=255) #write out the mask - no compression - -} \ No newline at end of file diff --git a/R/MSSdn2rad.r b/R/MSSdn2rad.r deleted file mode 100644 index 7efa31a..0000000 --- a/R/MSSdn2rad.r +++ /dev/null @@ -1,35 +0,0 @@ -#' Convert MSS DN values to TOA radiance -#' -#' Convert MSS DN values to TOA radiance. -#' @param imgFile filename (character). Full path to *dn.tif image file produced by the \code{\link{MSSunpack}} function. -#' @details The equation used to convert DN to TOA radiance can be found \href{http://landsat.usgs.gov/how_is_radiance_calculated.php}{here}. -#' @return A 4-band Landsat MSS GeoTIFF raster image file in units of top-of-atmosphere (TOA) radiance. The file will be placed in -#' same directory as the 'imgFile' with the name equal to the image ID followed by 'toa_radiance'. Note that the values are scaled by 100 -#' and rounded to the nearest integer to reduce the file size. -#' @seealso \code{\link{MSSdn2refl}} -#' @examples \dontrun{ -#' -#' MSSdn2rad("C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif") -#' } -#' @export - -MSSdn2rad = function(imgFile){ - - print(paste("Converting",basename(imgFile),"to TOA radiance")) - info = getMetadata(imgFile) #get image metadata - b = raster::brick(imgFile) #load the DN image as a brick - img = raster::as.array(b) #convert the brick to an array - - img[,,1] = round(100*((info$b1gain*img[,,1])+info$b1bias)) #convert fro DN to radiance and scale by 100 and round - img[,,2] = round(100*((info$b2gain*img[,,2])+info$b2bias)) #convert fro DN to radiance and scale by 100 and round - img[,,3] = round(100*((info$b3gain*img[,,3])+info$b3bias)) #convert fro DN to radiance and scale by 100 and round - img[,,4] = round(100*((info$b4gain*img[,,4])+info$b4bias)) #convert fro DN to radiance and scale by 100 and round - - img[img < 0] = 0 #you can't have negative radiance - set negative values to 0 - - img = raster::setValues(b,img) #convert the array to a brick - img = as(img, "SpatialGridDataFrame") #convert the brick to SGHF to be written by GDAL - outfile = sub("dn", "toa_radiance", imgFile) #define output filename - rgdal::writeGDAL(img, outfile, drivername = "GTiff", type = "Int16", mvFlag = -32768, options="INTERLEAVE=BAND") #write the file -} - diff --git a/R/MSSdn2refl.r b/R/MSSdn2refl.r deleted file mode 100644 index d197975..0000000 --- a/R/MSSdn2refl.r +++ /dev/null @@ -1,59 +0,0 @@ -#' Convert MSS DN values to TOA reflectance -#' -#' Convert MSS DN values to TOA reflectance. -#' @param imgFile filename (character). Full path to *dn.tif image file produced by the \code{\link{MSSunpack}} function. -#' @details DN values are first converted to top-of-atmosphere (TOA) radiance using the equation found \href{http://landsat.usgs.gov/how_is_radiance_calculated.php}{here}. -#' Then TOA radiance is converted to TOA reflectance using the equation found \href{http://landsathandbook.gsfc.nasa.gov/data_prod/prog_sect11_3.html}{here}. -#' The ESUN values used are from the publication 'Chander et al. 2009. Summary of current radiometric calibration coefficients... Remote Sensing of Environment. 113'. -#' @return A 4-band Landsat MSS GeoTIFF raster image file in units of top-of-atmosphere (TOA) reflectance. The file will be placed in the -#' same directory as the 'imgFile' with the name equal to the image ID followed by 'toa_reflectance'. Note that the values are scaled by 10,000 -#' and rounded to the nearest integer to reduce the file size. -#' @seealso \code{\link{MSSdn2rad}} -#' @examples \dontrun{ -#' -#' MSSdn2refl("C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif") -#' } -#' @export - -MSSdn2refl = function(imgFile){ - - print(paste("Converting",basename(imgFile),"to TOA reflectance")) - #link to the equations to convert DN to TOA and TOA to SR - #http://landsathandbook.gsfc.nasa.gov/data_prod/prog_sect11_3.html - - #define the TOA reflectance function - refl = function(imgFile, band, gain, bias, sunzen, d, esun){ - orig = raster::raster(imgFile, band) #read in the file - img = raster::as.matrix(orig) #convert from raster to matrix - img = ((gain*img)+bias) #convert from DN to TOA radiance - img[img < 0] = 0 #set all values less than 0 to 0 - negative radiance does not make sense - img = (pi * img * (d^2))/(esun * cos(sunzen)) #convert from TOA radiance to TOA reflectance - img = round(img * 10000) #scale by 10,000 and round to save on file size - img = raster::setValues(orig,img) #convert from matrix to raster - return(img) #return the TOA radiance raster - } - - info = getMetadata(imgFile) #read in the image metadata - - #define esun values for mss (chander et al 2009 summary of current radiometric calibration coefficients... RSE 113) - if(info$sensor == "LANDSAT_1"){esun = c(1823,1559,1276,880.1)} - if(info$sensor == "LANDSAT_2"){esun = c(1829,1539,1268,886.6)} - if(info$sensor == "LANDSAT_3"){esun = c(1839,1555,1291,887.9)} - if(info$sensor == "LANDSAT_4"){esun = c(1827,1569,1260,866.4)} - if(info$sensor == "LANDSAT_5"){esun = c(1824,1570,1249,853.4)} - - d = eudist(info$doy) #define the earth sun distance - sunzen = info$sunzen*(pi/180) #get sun zenith angle in radians for cos - - #apply the conversion to reflectance using the 'refl' function - b1 = refl(imgFile,1,info$b1gain, info$b1bias, sunzen, d, esun[1]) - b2 = refl(imgFile,2,info$b2gain, info$b2bias, sunzen, d, esun[2]) - b3 = refl(imgFile,3,info$b3gain, info$b3bias, sunzen, d, esun[3]) - b4 = refl(imgFile,4,info$b4gain, info$b4bias, sunzen, d, esun[4]) - - img = raster::stack(b1,b2,b3,b4) #stack the bands - - img = as(img, "SpatialGridDataFrame") #convert the raster to SGHF so it can be written using GDAL (faster than writing it with the raster package) - outfile = sub("dn", "toa_reflectance", imgFile) #define the outputs file - rgdal::writeGDAL(img, outfile, drivername = "GTiff", type = "Int16", mvFlag = -32768, options="INTERLEAVE=BAND") #write out the TOA reflectance file -} \ No newline at end of file diff --git a/R/MSSunpack.r b/R/MSSunpack.r deleted file mode 100644 index 729389a..0000000 --- a/R/MSSunpack.r +++ /dev/null @@ -1,84 +0,0 @@ -#' Decompress and stack Landsat LPGS MSS images -#' -#' Decompresses and stacks Landsat LPGS MSS images provided by USGS as *.tar.gz files. Optionally -#' outputs top-of-atmosphere (TOA) radiance and reflectance files. -#' @param imgFile filename (character). Full path to compressed LPGS Landsat MSS image file provided by USGS. -#' @param toaRad logical. If TRUE, a TOA radiance image will be created. -#' @param toaRefl logical. If TRUE, a TOA reflectance image will be created. -#' @param useL1G logical. If TRUE, L1G images will be processed. -#' @details It is important that the 'imgFile' be an unaltered tar.gz-compressed LPGS image file that you receive -#' from USGS through \href{http://rstudio.com}{EarthExplorer}. Note that DN values <= 1 are set to NA across all bands. -#' This mitigates a problem caused by bad columns on the east and west edge of images when mosaicing adjacent images together. -#' @return A 4-band Landsat MSS GeoTIFF raster image file in DN units. If optional 'toaRad' and/or 'toaRefl' -#' parameters are set to TRUE, then similar TOA radiance and reflectance image files will created. The files will be places in -#' the same location as the 'imgFile' with the name equal to the image ID plus an appended descriptor. Descriptors -#' include 'dn' (digital number), 'toa_radiance' (TOA radiance), and 'toa_reflectance' (TOA reflectance). -#' @seealso \code{\link{MSSdn2rad}}, \code{\link{MSSdn2refl}} -#' @examples -#' \dontrun{ -#' -#' MSSunpack(imgFile = "C:/mss/LM10360321973191AAA04.tar.gz") -#' MSSunpack(imgFile = "C:/mss/LM10360321973191AAA04.tar.gz", -#' toaRad = FALSE, toaRefl = TRUE, useL1G = TRUE) -#' } -#' @export - -MSSunpack = function(imgFile, toaRad=FALSE, toaRefl=FALSE, useL1G=FALSE){ - - #figure out if this is an L1G image and stop the function according to the 'useL1G' parameter - print(paste("Unpacking and preparing",basename(imgFile))) - tempdir = file.path(dirname(imgFile),"temp") - untar(imgFile, exdir=tempdir) - mtlfile = list.files(tempdir, pattern = "MTL.txt", full.names = T, recursive = T) #find the mtl metadata file - info = getMetadata(mtlfile) - if(useL1G == F & info$datatype == "L1G"){ - unlink(tempdir, recursive=T, force=T) #delete the temp folder and its contents - print(paste("MSS file:",imgFile,"is L1G, if you want to use it, set the 'useL1G' parameter to TRUE")) - stop("Stopping MSSunpack") - } - - #get file and directory info - allfiles = list.files(tempdir, full.names=T) #find all the decompressed files - tiffiles = allfiles[grep("TIF",allfiles)] #subset the tif image files - ancfiles = allfiles[grep("TIF",allfiles, invert=T)] #subset the other files - filebase = basename(tiffiles[1]) #get the basename - filedir = dirname(imgFile) #get the directory - - #create stack output name - name = paste(info$imgid, "_dn.tif", sep = "") #define the new file basename - outdir = file.path(filedir, info$imgid) #define the output directory - finalstack = file.path(outdir, name) #define the new full filename of the output image - - #deal with the ancillary file names - baseancfiles = basename(ancfiles) #get the basenames of the ancillary files - newancfiles = file.path(outdir, baseancfiles) #define the new filenames for ancillary files - - #start working with the image files - stack and set bad pixels to 0 - s = raster::stack(tiffiles[1],tiffiles[2],tiffiles[3],tiffiles[4]) #stack the band files - img = raster::as.array(s) #convert to array for fastering processing - b1bads = img[,,1]>1 #finds bad image edge pixels that cause problems when mosaicing - b2bads = img[,,2]>1 #finds bad image edge pixels that cause problems when mosaicing - b3bads = img[,,3]>1 #finds bad image edge pixels that cause problems when mosaicing - b4bads = img[,,4]>1 #finds bad image edge pixels that cause problems when mosaicing - bads = b1bads*b2bads*b3bads*b4bads #combines all of the bad pixels - - img[,,1] = img[,,1]*bads #sets all the bad pixels to value 0 - img[,,2] = img[,,2]*bads #sets all the bad pixels to value 0 - img[,,3] = img[,,3]*bads #sets all the bad pixels to value 0 - img[,,4] = img[,,4]*bads #sets all the bad pixels to value 0 - - dir.create(outdir, recursive=T, showWarnings=F) #make a new output directory - - file.rename(ancfiles,newancfiles) #move the associated files - - #write out the dn file - outimg = raster::setValues(s,img) #convert from matrix to raster - outimg = as(outimg, "SpatialGridDataFrame") #convert from rater to SGDF for faster writing - rgdal::writeGDAL(outimg, finalstack, drivername = "GTiff", options="INTERLEAVE=BAND", type = "Byte", mvFlag = 0) #write out the image. - - if(toaRad == T){MSSdn2rad(finalstack)} #calculate and write the toa radiance file if flagged - - if(toaRefl == T){MSSdn2refl(finalstack)} #calculate and write the toa reflectance file if flagged - - unlink(tempdir, recursive=T, force=T) #delete the temp folder and its contents -} \ No newline at end of file diff --git a/R/eudist.r b/R/eudist.r deleted file mode 100644 index 5eaa090..0000000 --- a/R/eudist.r +++ /dev/null @@ -1,385 +0,0 @@ -#' Earth-Sun distance by day-of-year -#' -#' Retrieve the Earth-Sun distance by day-of-year. It is helper function used -#' by the \code{\link{MSSdn2refl}} and \code{\link{MSScvm}} functions when calculating TOA reflectance. -#' @param doy integer. image day-of-year. -#' @details The function returns the Earth-sun distance for a specific day-of-year as defined -#' \href{http://landsathandbook.gsfc.nasa.gov/data_prod/prog_sect11_3.html}{here}. -#' @examples dist = eudist(215) -#' @export - -eudist = function(doy){ - #http://landsathandbook.gsfc.nasa.gov/excel_docs/d.xls - dau = c( - 0.98331, - 0.98330, - 0.98330, - 0.98330, - 0.98330, - 0.98332, - 0.98333, - 0.98335, - 0.98338, - 0.98341, - 0.98345, - 0.98349, - 0.98354, - 0.98359, - 0.98365, - 0.98371, - 0.98378, - 0.98385, - 0.98393, - 0.98401, - 0.98410, - 0.98419, - 0.98428, - 0.98439, - 0.98449, - 0.98460, - 0.98472, - 0.98484, - 0.98496, - 0.98509, - 0.98523, - 0.98536, - 0.98551, - 0.98565, - 0.98580, - 0.98596, - 0.98612, - 0.98628, - 0.98645, - 0.98662, - 0.98680, - 0.98698, - 0.98717, - 0.98735, - 0.98755, - 0.98774, - 0.98794, - 0.98814, - 0.98835, - 0.98856, - 0.98877, - 0.98899, - 0.98921, - 0.98944, - 0.98966, - 0.98989, - 0.99012, - 0.99036, - 0.99060, - 0.99084, - 0.99108, - 0.99133, - 0.99158, - 0.99183, - 0.99208, - 0.99234, - 0.99260, - 0.99286, - 0.99312, - 0.99339, - 0.99365, - 0.99392, - 0.99419, - 0.99446, - 0.99474, - 0.99501, - 0.99529, - 0.99556, - 0.99584, - 0.99612, - 0.99640, - 0.99669, - 0.99697, - 0.99725, - 0.99754, - 0.99782, - 0.99811, - 0.99840, - 0.99868, - 0.99897, - 0.99926, - 0.99954, - 0.99983, - 1.00012, - 1.00041, - 1.00069, - 1.00098, - 1.00127, - 1.00155, - 1.00184, - 1.00212, - 1.00240, - 1.00269, - 1.00297, - 1.00325, - 1.00353, - 1.00381, - 1.00409, - 1.00437, - 1.00464, - 1.00492, - 1.00519, - 1.00546, - 1.00573, - 1.00600, - 1.00626, - 1.00653, - 1.00679, - 1.00705, - 1.00731, - 1.00756, - 1.00781, - 1.00806, - 1.00831, - 1.00856, - 1.00880, - 1.00904, - 1.00928, - 1.00952, - 1.00975, - 1.00998, - 1.01020, - 1.01043, - 1.01065, - 1.01087, - 1.01108, - 1.01129, - 1.01150, - 1.01170, - 1.01191, - 1.01210, - 1.01230, - 1.01249, - 1.01267, - 1.01286, - 1.01304, - 1.01321, - 1.01338, - 1.01355, - 1.01371, - 1.01387, - 1.01403, - 1.01418, - 1.01433, - 1.01447, - 1.01461, - 1.01475, - 1.01488, - 1.01500, - 1.01513, - 1.01524, - 1.01536, - 1.01547, - 1.01557, - 1.01567, - 1.01577, - 1.01586, - 1.01595, - 1.01603, - 1.01610, - 1.01618, - 1.01625, - 1.01631, - 1.01637, - 1.01642, - 1.01647, - 1.01652, - 1.01656, - 1.01659, - 1.01662, - 1.01665, - 1.01667, - 1.01668, - 1.01670, - 1.01670, - 1.01670, - 1.01670, - 1.01669, - 1.01668, - 1.01666, - 1.01664, - 1.01661, - 1.01658, - 1.01655, - 1.01650, - 1.01646, - 1.01641, - 1.01635, - 1.01629, - 1.01623, - 1.01616, - 1.01609, - 1.01601, - 1.01592, - 1.01584, - 1.01575, - 1.01565, - 1.01555, - 1.01544, - 1.01533, - 1.01522, - 1.01510, - 1.01497, - 1.01485, - 1.01471, - 1.01458, - 1.01444, - 1.01429, - 1.01414, - 1.01399, - 1.01383, - 1.01367, - 1.01351, - 1.01334, - 1.01317, - 1.01299, - 1.01281, - 1.01263, - 1.01244, - 1.01225, - 1.01205, - 1.01186, - 1.01165, - 1.01145, - 1.01124, - 1.01103, - 1.01081, - 1.01060, - 1.01037, - 1.01015, - 1.00992, - 1.00969, - 1.00946, - 1.00922, - 1.00898, - 1.00874, - 1.00850, - 1.00825, - 1.00800, - 1.00775, - 1.00750, - 1.00724, - 1.00698, - 1.00672, - 1.00646, - 1.00620, - 1.00593, - 1.00566, - 1.00539, - 1.00512, - 1.00485, - 1.00457, - 1.00430, - 1.00402, - 1.00374, - 1.00346, - 1.00318, - 1.00290, - 1.00262, - 1.00234, - 1.00205, - 1.00177, - 1.00148, - 1.00119, - 1.00091, - 1.00062, - 1.00033, - 1.00005, - 0.99976, - 0.99947, - 0.99918, - 0.99890, - 0.99861, - 0.99832, - 0.99804, - 0.99775, - 0.99747, - 0.99718, - 0.99690, - 0.99662, - 0.99634, - 0.99605, - 0.99577, - 0.99550, - 0.99522, - 0.99494, - 0.99467, - 0.99440, - 0.99412, - 0.99385, - 0.99359, - 0.99332, - 0.99306, - 0.99279, - 0.99253, - 0.99228, - 0.99202, - 0.99177, - 0.99152, - 0.99127, - 0.99102, - 0.99078, - 0.99054, - 0.99030, - 0.99007, - 0.98983, - 0.98961, - 0.98938, - 0.98916, - 0.98894, - 0.98872, - 0.98851, - 0.98830, - 0.98809, - 0.98789, - 0.98769, - 0.98750, - 0.98731, - 0.98712, - 0.98694, - 0.98676, - 0.98658, - 0.98641, - 0.98624, - 0.98608, - 0.98592, - 0.98577, - 0.98562, - 0.98547, - 0.98533, - 0.98519, - 0.98506, - 0.98493, - 0.98481, - 0.98469, - 0.98457, - 0.98446, - 0.98436, - 0.98426, - 0.98416, - 0.98407, - 0.98399, - 0.98391, - 0.98383, - 0.98376, - 0.98370, - 0.98363, - 0.98358, - 0.98353, - 0.98348, - 0.98344, - 0.98340, - 0.98337, - 0.98335, - 0.98333, - 0.98331) - return(dau[doy]) -} - - - - diff --git a/R/getMetadata.r b/R/getMetadata.r deleted file mode 100644 index e0855fa..0000000 --- a/R/getMetadata.r +++ /dev/null @@ -1,136 +0,0 @@ -#' Retrieve Landsat image metadata -#' -#' Uses the image file name to find the corresponding *MTL.txt image metadata file provided with LPSG Landsat images -#' and returns a data.frame with image information. -#' @param imgFile filename (character). Full path to a Landast LPGS MSS file that includes the -#' original image ID as the first block of characters. -#' @return data.frame with image information. -#' @examples \dontrun{ -#' -#' getMetadata("C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif") -#' } -#' @export - -getMetadata = function(imgFile){ - bname = basename(imgFile) - mtlfile = file.path(dirname(imgFile),paste(substr(bname,1,22),"MTL.txt", sep="")) - tbl = unlist(read.delim(mtlfile, header=F, skipNul=T)) - - #get the path row "ppprrr" - ppprrr = substr(bname, 4,9) - - #get the day-of-year - doy = as.numeric(substr(bname, 14,16)) - - #get the image id - imgid = substr(bname, 1, 21) - - #get the data type - string = as.character(grep("DATA_TYPE = ", tbl, value=T)) - pieces = unlist(strsplit(string, " ")) - datatype = pieces[7] - - #get the sensor - string = as.character(grep("SPACECRAFT_ID =", tbl, value=T)) - pieces = unlist(strsplit(string, " ")) - sensor = pieces[7] - - #get the sun elevation - string = as.character(grep("SUN_ELEVATION = ", tbl, value=T)) - pieces = unlist(strsplit(string, " ")) - sunelev = as.numeric(pieces[7]) - sunzen = 90 - sunelev - - #get the sun azimuth - string = as.character(grep("SUN_AZIMUTH = ", tbl, value=T)) - pieces = unlist(strsplit(string, " ")) - sunaz = as.numeric(pieces[7]) - - # get min and max radiance; gain and bias - if(sensor == "LANDSAT_1" | sensor == "LANDSAT_2" | sensor == "LANDSAT_3"){ - bands = c(4,5,6,7)} else{bands = c(1,2,3,4)} - - maxrad = array(0,4) - minrad = array(0,4) - gain = array(0,4) - bias = array(0,4) - - for(i in 1:4){ - maxradsearch = paste("RADIANCE_MAXIMUM_BAND_", bands[i], " =", sep="") - string = as.character(grep(maxradsearch, tbl, value=T)) - pieces = unlist(strsplit(string, " ")) - maxrad[i] = as.numeric(pieces[7]) - - minradsearch = paste("RADIANCE_MINIMUM_BAND_", bands[i], " =", sep="") - string = as.character(grep(minradsearch, tbl, value=T)) - pieces = unlist(strsplit(string, " ")) - minrad[i] = as.numeric(pieces[7]) - - radmultsearch = paste("RADIANCE_MULT_BAND_", bands[i], " =", sep="") - string = as.character(grep(radmultsearch, tbl, value=T)) - pieces = unlist(strsplit(string, " ")) - gain[i] = as.numeric(pieces[7]) - - radaddsearch = paste("RADIANCE_ADD_BAND_", bands[i], " =", sep="") - string = as.character(grep(radaddsearch, tbl, value=T)) - pieces = unlist(strsplit(string, " ")) - bias[i] = as.numeric(pieces[7]) - } - - #prepare variables for inclusion in output table - b1minrad = minrad[1] - b2minrad = minrad[2] - b3minrad = minrad[3] - b4minrad = minrad[4] - b1maxrad = maxrad[1] - b2maxrad = maxrad[2] - b3maxrad = maxrad[3] - b4maxrad = maxrad[4] - - b1gain = gain[1] - b2gain = gain[2] - b3gain = gain[3] - b4gain = gain[4] - b1bias = bias[1] - b2bias = bias[2] - b3bias = bias[3] - b4bias = bias[4] - - #get the wrs type - if(sensor == "LANDSAT_1"){wrstype = "wrs1"} - if(sensor == "LANDSAT_2"){wrstype = "wrs1"} - if(sensor == "LANDSAT_3"){wrstype = "wrs1"} - if(sensor == "LANDSAT_4"){wrstype = "wrs2"} - if(sensor == "LANDSAT_5"){wrstype = "wrs2"} - - #fill in the output table - df = data.frame( - ppprrr, - doy, - imgid, - sensor, - datatype, - wrstype, - sunelev, - sunzen, - sunaz, - b1minrad, - b2minrad, - b3minrad, - b4minrad, - b1maxrad, - b2maxrad, - b3maxrad, - b4maxrad, - b1gain, - b2gain, - b3gain, - b4gain, - b1bias, - b2bias, - b3bias, - b4bias - ) - - return(df) -} \ No newline at end of file diff --git a/R/mosaicDEMs.r b/R/mosaicDEMs.r deleted file mode 100644 index 706f4f5..0000000 --- a/R/mosaicDEMs.r +++ /dev/null @@ -1,86 +0,0 @@ -#' Create a DEM mosaic from a direcory of DEM's -#' -#' A helper function to create the large-extent DEM file required by the \code{\link{MSScvm}} function. -#' @param dir directory name (character). Full path to a directory containing digital elevation model (DEM) files to be mosaiced. -#' @param projRef filename (character). Full path to an image file produced by the \code{\link{MSSunpack}} function to be used as the projection reference. -#' @param srcNodata numeric. Specify the background value of the DEM files in the directory. If there is no background value, use NA (default) . -#' @param dstNodata numeric. Specify the value to represent background pixels in the mosaic DEM. -32768 is the default. -#' @details The provided directory path should only contain decompressed digital elevation files from the same source (SRTM, NED, GTOPO, etc). -#' The function will search the directory and include all files found in the mosaic. It is important that each file have the same background value -#' and that it is correctly assigned to the 'srcNodata' parameter, if not, intersection between DEMs could have unexpected results. -#' Each individual DEM file will be adjusted to match the projection and pixel resolution of the 'proRef' image. -#' Then they will be merged using the mean value of intersecting pixels. -#' @return A GeoTIFF raster file representing the union of all individual DEM files found in the provided directory path. The mosaic file will be written to the -#' provided directory as "dem_mosaic.tif". -#' @seealso \code{\link{reprojectDEM}} -#' @examples \dontrun{ -#' -#' mosaicDEMs(dir = "C:/mss/dems", -#' projRef = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif", -#' srcNodata = -9999, dstNodata= -32768) -#' } -#' @export - - -mosaicDEMs = function(dir, projRef, srcNodata=NA, dstNodata=-32768){ - - align = function(img, refimg){ - img = raster::raster(img) - imgex = raster::alignExtent(img, refimg, snap="near") - raster::extent(img) = imgex - return(img) - } - - template = raster::raster(projRef) - reso = raster::xres(template) - proj = raster::projection(template) - demfiles = normalizePath(list.files(dir, full.names=T)) - - #check files to see if they are compressed - zip = grep("zip", demfiles) - tar = grep("tar", demfiles) - gz = grep("gz", demfiles) - if(sum(length(zip),length(tar),length(gz)) != 0){ - print(paste("There are compressed files in this directory:",dir)) - print("make sure the directory only contains decompressed files") - stop("Stopping mosaicDEMs") - } - - for(i in 1:length(demfiles)){ - demfile = demfiles[i] - print(paste("Reprojecting",basename(demfile))) - bname = basename(demfile) - extension = substr(bname,(nchar(bname)-3),nchar(bname)) - dstfile = sub(extension, "_reprojected.tif", demfile) - - gdalUtils::gdalwarp(srcfile=demfile, dstfile=dstfile, - t_srs=proj, of="GTiff", overwrite=TRUE, - r="near", srcnodata=srcNodata, dstnodata=dstNodata, multi=T, - tr=c(reso,reso), co="INTERLEAVE=BAND") - } - - demfiles = list.files(dir, pattern="reprojected.tif$", full.names=T) - len = length(demfiles) - if(len <= 1){ - print(paste("There are less than 2 DEM files in this directory:",dir)) - print("Not enough to mosaic") - stop("Stopping mosaicDEMs") - } - - refimg = raster::raster(demfiles[1]) - - outfile = file.path(dir,"dem_mosaic.tif") - big = NA #create a dummy variable to be overwritten on-the-fly with eval - for(i in 1:len){ - if(i == 1){mergeit = "r1"} else {mergeit = paste(mergeit,",r",i, sep="")} - dothis = paste("r",i,"=align(demfiles[",i,"], refimg)", sep="") - eval(parse(text=dothis)) - if(i == len){mergeit = paste("big = raster::mosaic(",mergeit,",fun=mean,na.rm=T,tolerance=0.5, filename=outfile, format='GTiff', datatype = 'INT2S',overwrite=T,options=c('COMPRESS=NONE'))", sep="")} - } - - print("Creating DEM mosaic") - eval(parse(text=mergeit)) - unlink(demfiles) - -} - diff --git a/R/reprojectDEM.r b/R/reprojectDEM.r deleted file mode 100644 index 6e5bab4..0000000 --- a/R/reprojectDEM.r +++ /dev/null @@ -1,42 +0,0 @@ -#' Reproject a DEM file -#' -#' Reproject a DEM file to match the projection and pixel resolution of an image file. A helper function to make a DEM -#' conform to the properties of an image file prior to using it as an input to the \code{\link{MSScvm}} masking function. -#' @param demFile filename (character). Full path to DEM file. -#' @param projRef filename (character). Full path to an image file produced by the \code{\link{MSSunpack}} function. -#' @param srcNodata numeric. Specify the background value in the input DEM. If there is no background value, use NA (default). -#' @param dstNodata numeric. Specify the value to represent background pixels in the reprojected DEM. -32768 is the default. -#' @details The DEM file will be adjusted to match the projection and pixel resolution of the 'proRef' image. -#' @return A GeoTIFF raster file with '_reprojected.tif' replacing the last 4 characters of the input DEM filename. -#' @seealso \code{\link{mosaicDEMs}} -#' @examples \dontrun{ -#' -#' reprojectDEM(demFile = "C:/mss/dem/wrs1_p036r032_dem.tif", -#' projRef = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif", -#' srcNodata= -9999, dstNodata= -32768) -#' } -#' @export - -reprojectDEM = function(demFile, projRef, srcNodata=NA, dstNodata=-32768){ - - template = raster::raster(projRef) #read in the projection reference image - reso = raster::xres(template) #get the pixel resolution - proj = raster::projection(template) #get the projection - - print(paste("Reprojecting",demFile)) - bname = basename(demFile) #get the basename of the dem file - extension = substr(bname,(nchar(bname)-3),nchar(bname)) #extract the extension of the dem file - dstfile = sub(extension, "_reprojected.tif", demFile) #define the filename - - gdalUtils::gdalwarp(srcfile=demFile, dstfile=dstfile, - t_srs=proj, of="GTiff", - r="near", multi=T, srcnodata=srcNodata, dstnodata=dstNodata, overwrite=TRUE, - tr=c(reso,reso), co="INTERLEAVE=BAND") #reproject the image using gdalwarp through gdalUtils - -} - - - - - - diff --git a/README.md b/README.md deleted file mode 100644 index 18b2465..0000000 --- a/README.md +++ /dev/null @@ -1,203 +0,0 @@ -# MSScvm - -An automated cloud and cloud shadow masking system for Landsat MSS imagery. It provides a means of more easily incorporating MSS imagery in large-area and time series analysis by providing an efficient way to prevent cloud and cloud shadow pixels from contaminating mosaics, composites, and time series analysis. - -#### Method publication: -[Braaten, J. D., Cohen, W. B., & Yang, Z. (2015). Automated cloud and cloud shadow identification in Landsat MSS imagery for temperate ecosystems. Remote Sensing of Environment, 169, 128-138.](http://www.msscvm.jdbcode.com/imgs/braaten_et_al_2015_automated%20cloud_and_cloud_shadow_identification_in_landsat_mss_imagery_for_temperate_ecosystems.pdf) - -#### Website: -http://www.msscvm.jdbcode.com/ - -# Download -MSScvm is installed by downloading the R package from GitHub and running the `install.packages` function in the R console command line. Copy the three lines of code from the version release below (grey box) and paste them into the R command line and press enter. - -* the first line downloads the MSScvm package from GitHub -* the second installs it -* the third installs the dependent packages from CRAN - -Once MSScvm and its dependencies have been installed, simply type `library(MSScvm)` each time you start a new R session to activate it. For more details on installing, processing procedures, and outputs please see the [Guide](guide.html) page and the MSScvm R package manual file accompanying the MSScvm release. - -Note that GDAL must be installed on your system. Please see the Guide page for assistance. - -* * * - -#### Version 1.0.0 - 7/30/15 - -
download.file("https://github.com/jdbcode/MSScvm/releases/download/1.0.0/MSScvm_1.0.0.zip", "MSScvm")
-install.packages("MSScvm", repos=NULL)
-install.packages(c("gdalUtils","igraph","raster","rgdal","SDMTools"))
- -[MSScvm manual](imgs/MSScvm-manual.pdf) - -* * * - -MSScvm was developed by the [Laboratory for Applications of Remote Sensing in Ecology](http://larse.forestry.oregonstate.edu/) at Oregon State University, Department of Forest Ecosystems and Society with funding from USDA Forest Service and USGS. - -Principle author and maintainer: Justin Braaten - Contributing authors: Warren Cohen, Zhiqiang Yang - GitHub: [https://github.com/jdbcode/MSScvm](https://github.com/jdbcode/MSScvm) - - -# Guide -## Overview - -MSScvm will take Landsat LPGS MSS images and preform the following processes: - -* Decompress -* Stack individual image bands to a single 4-band file -* Write image files for spectral units of DN, TOA radiance, and TOA reflectance -* Help prepare a required DEM file by providing convenient functions to mosaic, reproject, and resample -* Create cloud and cloud shadow masks - -The program uses the R programming environment and GDAL to execute the work. Therefore you must install both R and GDAL, and we recommended that you use RStudio as the front-end to interact with the R environment. This guide will walk you through installing the required software and R packages, as well as demonstrate the use of MSScvm. Note that on the [Download](download.html) page the MSScvm R package manual can be downloaded. It contains standard R documentation for each function described below. In the R command prompt you can also type `?` followed by a function name to display the function's help page. As in: `?MSSunpack`. - -The basic order of operations for running MSScvm is: - -1. Download MSS image -2. Unpack the image using the `MSSunpack` function -3. Identify and download image-corresponding DEM(s) -4. Run the `mosaicDEMs` or `reprojectDEM` functions to prepare the DEM(s) -5. Create cloud and shadow mask using the `MSScvm` function - -If working with many images from the same Landsat footprint you will go through the above steps only once and then just the following for each successive image: - -1. Unpack the image using the `MSSunpack` function -2. Create cloud and shadow mask using the `MSScvm` function - -MSScvm will automatically write outputs to the same directory location as the input image, with intuitive file names that include the original image ID and descriptions for each type (DN, TOA radiance, TOA reflectance, and mask). The images are in the GeoTIFF format in the native resolution and projection of the input image file, with background values set to NoData. - -## System requirements - -### Computer - -MSScvm was developed and tested on computers running Windows 7 64-bit OS with >= 8 GB of RAM. - -### Software - -* R -* RStudio -* GDAL - -## Install software - -MSScvm requires R, RStudio, and GDAL programs be installed on your computer. R is a free computer programming language for statistical computing and graphics. RStudio provides a convenient front-end interface to the R environment. GDAL is a program for reading, writing, and manipulating geospatial data. - -If you don't already have a current version of these programs you'll need to download and install them to your computer. - -### R - -Follow the install directions on the [R](http://www.r-project.org/) website - -### RStudio - -Follow the install directions on the [RStudio](http://www.rstudio.com/) website - -### MSScvm - -See the [Download](download.html) page for instructions and the most current version - -### GDAL - -There are numerous ways you can install GDAL, the following is one example. - -1. Go to [http://www.gisinternals.com/sdk/](http://www.gisinternals.com/sdk/) -2. Click on the _Downloads_ link for the version that best matches your system (we use MSVC 2010 - x64) -3. Download the _Generic installer for the GDAL core components_ -4. Run the installer -5. Include GDAL in your system's environmental variable _PATH_ - -1. Open Windows _Control Panel_ and select _System_ -2. Click on _Advanced system settings_ -3. Click the _Environmental Variables..._ button -4. Under System variables, scroll down to the _Path_ variable and click on it to highlight it -5. Click the _edit_ button -6. Get your cursor to the end of the line, add a semi-colon (;) and add the path to the GDAL installation location. Example: C:\GDAL (this may not actually be the location on your system) - -## Get MSS images - -The MSS images processed by MSScvm should be compressed (.tar.gz) USGS LPGS images requested through [EarthExplorer](http://earthexplorer.usgs.gov/). This will ensure that the automated features of the program work correctly. They are contained in the _Landsat Archive_ directory under the _Data Sets_ tab on the EarthExplorer website. - -Follow the instructions on the EarthExplorer site for selecting and downloading MSS images. When you have received your images, place the unaltered *.tar.gz files in a directory that you have write permission for, since MSScvm will write files to this location (some government and institutional systems restrict user writing capabilities). - -## Prepare MSS images - -Run the `MSSunpack` function to decompress, stack, and optionally output top-of-atmosphere (TOA) radiance and reflectance images. The imgFile input is the full path to a compressed LPGS MSS image from USGS EarthExplorer. The logical parameters toaRad and toaRefl determine whether TOA radiance and reflectance images are created along with the default DN image. The following examples demonstrate loading the MSScvm package and running the `MSSunpack` function with and without the toaRad and toaRefl parameters (each set to FALSE by default). - -Load the MSScvm library (this only needs to be done once when a new R session is started): - -
library(MSScvm)
- -Run the `MSSunpack` function to create a 4-band DN image stack: - -
MSSunpack(imgFile = "C:/mss/LM10360321973191AAA04.tar.gz")
- -... or optionally run the `MSSunpack` function with the toaRad and toaRefl parameters set to TRUE to create 4-band DN, TOA radiance,and TOA reflectance image stacks: - -
MSSunpack(imgFile = "C:/mss/LM10360321973191AAA04.tar.gz", toaRad = TRUE, toaRefl = TRUE)
- -GeoTIFF raster image files will be written out. The files will be placed in a directory in the same location as the input imgFile with the name equal to the image ID. The files will contain the image ID followed by descriptors "dn.tif" (digital number), "toa_radiance.tif" (TOA radiance), and "toa_reflectance.tif" (TOA reflectance). Note that the values for TOA radiance are scaled by 100 and rounded to the nearest integer and TOA reflectance is scaled by 10,000 and rounded to the nearest integer. This is done to reduce image file size while retaining some decimal precision. - -Input/output file path examples: - -If imgFile input equals: "C:/mss/LM10360321973191AAA04.tar.gz", - output DN file will be: "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif", - output TOA radiance file will be: "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_toa_radiance.tif", - output TOA reflectance file will be: "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_toa_reflectance.tif" - -## Prepare DEMs - -MSScvm uses a digital elevation model (DEM) to aid in separating topographic shadows from cloud shadows and for identifying water. It is important that the DEM be greater or equal to the extent of the image it is being used for, and that it matches the pixel resolution and projection of the image. - -Setting up the DEM can be a hassle, but MSScvm provides helper functions to make DEM preparation easy, but you first need to download them or check that the DEMs you have are large enough or can be mosaiced to cover the image extent. If you ensure that the DEM you use has a liberal buffer out from the WRS path/row you are working on, you will only need to prepare it once. After that it can be applied to any image for that WRS path/row. So take a little extra time up front to prepare the DEM for future use. - -There are many sources of DEMs, and you can use what you like, but it's recommended that they be no more than 90 meters in pixel resolution. A good source for DEMs is the [Global Landcover Facility](http://glcf.umd.edu/data/srtm/), which distributes SRTM data as Landsat WRS-2 footprints. Use the _Filled Finished-B product at 1 arc second_ (30 meter) where possible and the _Filled Finished-B product at 3 arc seconds_ (90 meter) elsewhere. If using these data keep in mind that MSS images from sensors 1-3 use the WRS-1 footprint system so you will need to download several WRS-2 DEM footprints to fully intersect the MSS WRS-1 footprint. We've also found that the actual extent of a WRS-2 SRTM DEM will often not fully intersect the extent of a given image, even when the image is also WRS-2 (sensors 4-5). For this reason, we typically mosaic 9 DEMs for each WRS footprint to ensure full overlap with any image from the WRS path/row that we are working on (the `MSScvm` function will crop it on-the-fly in memory). In any case, check for full overlap between your DEM(s) and your MSS image in a GIS. - -### Mosaicking several DEMs together - -If you need to mosaic several DEMs together to ensure full overlap with your image, place all of the relevant DEM files into a single directory. There should be nothing else in the directory, and the files should all be decompressed GeoTIFF files. It is also important that the DEMs are from the same source so that their background value is the same. This value is specified in the call to the `mosaicDEMs` function and will be ignored during the mosaic procedure. If you need to convert to GeoTIFF files, you can use the `reprojectDEM` function to do so. - -With the all of your relevant DEMs in a directory, run the `mosaicDEMs` function as follows, where dir is the full path to the DEM directory, projRef is a *dn.tif file produced by the `MSSunpack` function that corresponds to the DEMs, srcNodata is the background value of the DEMs in the DEM directory, and dstNoData sets the desired background value for the output DEM mosaic. - -Example: - -
mosaicDEMs(dir = "C:/mss/dems", projRef = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif", srcNodata = -9999, dstNodata= -32768)
- -The function will produce a mosaic from all the files found in the directory specified by the dir parameter. It will be GeoTIFF format, with the background value set to the value specified by the dstNodata parameter and will be placed in the same directory as dir with the name dem_mosaic.tif. - -### Reprojecting and resampling an existing DEM - -If you have an existing DEM that is >= to the extend of the MSS image you want to create a cloud and shadow mask for or you need to convert DEM files to GeoTIFF format for use in the `mosaicDEMs` function, use the `reprojectDEM` function. It will take an input DEM file specified by the demFile parameter and make it match the projection and resolution of the relevant MSS image specified by the projRef parameter. The srcNodata and dstNodata parameters are used to set the output's background value. srcNodata is the background value of the input DEM and dstNoData sets the desired background value for the output DEM. - -Example: - -
reprojectDEM(demFile = "C:/mss/dem/wrs1_p036r032_dem.tif", projRef = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif", srcNodata = -9999, dstNodata = -32768)
- -The function will produce a new DEM file in the GeoTIFF format, with the projection and pixel resolution matching that of the projRef image. The the srcNodata value will be set to the value specified by the dstNodata parameter and the file will placed in the same directory as the demFile with _reprojected.tif replacing the input file's extension. - - - -
- -## Create cloud mask - -Run the `MSScvm` function to create cloud and cloud shadow masks for MSS images. The inputs are the full path to a directory containing an unpacked MSS image as the result of running the `MSSunpack` function (imgDir) and the prepared image-corresponding DEM (demFile). An optional logical parameter classify specifies how to label the mask pixels. The default is classify = FALSE, which returns a binary mask where pixels are either obscured (cloud and cloud shadow aggregated) or clear-view, alternatively, TRUE will classify the pixels by clear-view, cloud shadow, and cloud. - -Example of running the `MSScvm` function: - -
MSScvm(imgDir = "C:/mss/LM10360321973191AAA04", demFile = "C:/mss/dem/wrs1_p036r032_dem.tif", classify = FALSE)
- -A GeoTIFF raster image file will be placed in the imgDir directory with the name equal to the image ID followed by _msscvm.tif. If the classify parameter was set to FALSE then obscured pixels (cloud and cloud shadow) will be set to value 0 and clear-view pixel set to 1. If the classify parameter was set to TRUE then clear-view = 0, cloud shadow = 1, cloud = 2\. - -## Auxiliary functions - -MSScvm has functions to convert DN images to TOA radiance and reflectance images. These functions can optionally be called when running the `MSSunpack` function. If they were not run during unpacking, they can be run independently by running the `MSSdn2rad` and `MSSdn2refl` functions. The input (imgFile) for both functions is the full path to a *dn.tif file produced by running the `MSSunpack` function. - -Create a TOA radiance file from a *dn.tif file: - -
MSSdn2rad(imgFile = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif")
- -Create a TOA reflectance file from a *dn.tif file: - -
MSSdn2refl(imgFile = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif")
- -Both functions will output a 4-band GeoTIFF raster image. The file will be placed in the same directory as the input imgFile with the name equal to the image ID followed by "_toa_radiance.tif" or "_toa_reflectance.tif". Note that the values for TOA radiance are scaled by 100 and rounded to the nearest integer and TOA reflectance is scaled by 10,000 and rounded to the nearest integer. This is done to reduce image file size while retaining some decimal precision. diff --git a/about.html b/about.html new file mode 100644 index 0000000..f4d146b --- /dev/null +++ b/about.html @@ -0,0 +1,109 @@ + + + + About - MSScvm + + + + + + + + + + + +
+
+
+

What is MSScvm?

+

+ MSScvm (MSS clear-view-mask) is an automated cloud and cloud shadow identification system + for Landsat MSS imagery. It is an important contribution to the field of large-volume Landsat + image processing, as it provides an efficient means of identifying and removing cloud and cloud + shadow pixels from inclusion in image mosaics, composites, and time series analysis. +

+

+ Similar cloud and cloud shadow identification systems for Landsat TM, ETM+, and OLI imagery have been developed and + have played a crucial role in facilitating the current trend of large-area and dense time series analysis. +

+

+ MSScvm was developed to provide the same service to MSS data so that it could more easily be incorporated with + TM, ETM+ and OLI data to produce 42+ year spectral chronologies representing the longest satellite-derived + earth observation dataset. This extended record provides information on long-term Earth surface changes, + including forest dynamics, desertification, urbanization, glacier recession, and coastal inundation. It also has + the benefit of increasing the observation frequency of cyclic and sporadic events, such as drought, insect outbreaks, + wildfire, and floods. Furthermore, utilization of the full 42+ years of Landsat imagery sets an example of effectual + resource use and supports the need for continuity of Landsat missions to provide seamless spatial and temporal + coverage into the future. +

+
+ +

Why identify and mask clouds in satellite imagery?

+

+ Clouds and their shadows block or reduce satellite sensors' view of Earth surface features, + obscuring spectral information characteristic of clear-sky viewing. This spectral deviation + from clear-sky view can cause false change in a change detection analysis and conceals true + land cover, which can reduce the accuracy and information content of map products where + cloud-free images are not available. As a result, cloud and cloud shadow identification + and masking are important and often necessary pre-processing steps. +

+
+ +

How does it work?

+

+ The algorithm is specific to the unique spectral characteristics of MSS data, relying on a simple, + rule-based approach. Clouds are identified based on green band brightness and the normalized difference + between the green and red bands, while cloud shadows are identified by near infrared band darkness + and cloud projection. A digital elevation model is incorporated to correct for topography-induced + illumination variation and aid in identifying water. +

+

+ The MSScvm program is written in the R programming language and distributed as an R package for straightforward + installation and easy use. +

+

+ Besides creating cloud and cloud shadow masks, MSScvm will also prepare MSS images downloaded from + EarthExplorer by decompressing, stacking, and converting DN values to TOA radiance and/or reflectance. +

+

For more information, see the Guide and Download pages.

+
+ +

Publication

+ + Braaten, J. D., Cohen, W. B., & Yang, Z. (2015). Automated cloud and cloud shadow identification in Landsat MSS imagery + for temperate ecosystems. Remote Sensing of Environment, 169, 128-138. + +
+ +

Application

+

+ MSScvm can be used as a stand-alone utility, but perhaps more significantly, it plays a vital role in the implementation of the LandsatLinkr + program, which is an automated system for processing large volumes of Landsat imagery and building long spectrally consistent + chronologies across MSS, TM, ETM+, and OLI sensors. This is where the real benefit of the MSScvm program lies - check it out! +

+
+
+
+ + \ No newline at end of file diff --git a/contact.html b/contact.html new file mode 100644 index 0000000..659d87e --- /dev/null +++ b/contact.html @@ -0,0 +1,62 @@ + + + + Contact - MSScvm + + + + + + + + + + + +
+
+
+ +
+
+
+
+

Contact information

+

+ Justin Braaten
+ + Email: jstnbraaten@gmail.com +

+

Curriculum vitae

+

Other work

+
+
+ +
+
+
+ + \ No newline at end of file diff --git a/download.html b/download.html new file mode 100644 index 0000000..a9f7b29 --- /dev/null +++ b/download.html @@ -0,0 +1,74 @@ + + + + Download - MSScvm + + + + + + + + +
+
+
+

+ MSScvm is installed by downloading the R package from GitHub and running the + install.packages function in the R console command line. Copy the three lines of + code from the version release below (grey box) and paste them into the R command line and press + enter. +

    +
  • the first line downloads the MSScvm package from GitHub
  • +
  • the second installs it
  • +
  • the third installs the dependent packages from CRAN
  • +
+ Once MSScvm and its dependencies have been installed, simply type library(MSScvm) each time + you start a new R session to activate it. For more details on installing, + processing procedures, and outputs please see the Guide page and the + MSScvm R package manual file accompanying the MSScvm release. +

+

Note that GDAL must be installed on your system. Please see the Guide page for assistance.

+
+

Version 1.0.0 - 7/30/15

+

+download.file("https://github.com/jdbcode/MSScvm/releases/download/1.0.0/MSScvm_1.0.0.zip", "MSScvm")

+install.packages("MSScvm", repos=NULL)

+install.packages(c("gdalUtils","igraph","raster","rgdal","SDMTools"))
+ MSScvm manual +
+

+ MSScvm was developed by the Laboratory for Applications of Remote Sensing in + Ecology at Oregon State University, Department of Forest Ecosystems and Society with + funding from USDA Forest Service and USGS. +

+

+ Principle author and maintainer: Justin Braaten
+ Contributing authors: Warren Cohen, Zhiqiang Yang
+ GitHub: https://github.com/jdbcode/MSScvm +

+
+
+
+ + \ No newline at end of file diff --git a/examples.html b/examples.html new file mode 100644 index 0000000..e7e4f46 --- /dev/null +++ b/examples.html @@ -0,0 +1,107 @@ + + + + Examples - MSScvm + + + + + + + + +
+

Move your cursor in and out of the images to alternate an overlay display + of the MSScvm cloud mask.

+

+ The algorithm is certainly not perfect, but given the low radiometric and spectral richness of MSS data, it + does pretty well. It has high accuracy for thick clouds and their shadows, but there is moderate omission error + for thin, semi-transparent clouds and their shadows. Additionally, there is cloud commission error for + extremely bright surfaces, as well as cloud shadow commission error for dark surfaces west of clouds. Take a + look at the examples below to get a sense for its suitability for your application. Note that the display images have been quantized + to 6-bit color for better web performance. +

+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/guide.html b/guide.html new file mode 100644 index 0000000..638ffaf --- /dev/null +++ b/guide.html @@ -0,0 +1,321 @@ + + + + Guide - MSScvm + + + + + + + + + + + +
+
+
+
+ + +

MSScvm will take Landsat LPGS MSS images and preform the following processes:

+
    +
  • Decompress
  • +
  • Stack individual image bands to a single 4-band file
  • +
  • Write image files for spectral units of DN, TOA radiance, and TOA reflectance
  • +
  • Help prepare a required DEM file by providing convenient functions to mosaic, reproject, and resample
  • +
  • Create cloud and cloud shadow masks
  • +
+

+ The program uses the R programming environment and GDAL to execute the work. Therefore you must + install both R and GDAL, and we recommended that you use RStudio as the front-end to interact with + the R environment. This guide will walk you through installing the required software and R packages, + as well as demonstrate the use of MSScvm. Note that on the Download page + the MSScvm R package manual can be downloaded. It contains standard R documentation for each function + described below. In the R command prompt you can also type ? followed by a function name to display the + function's help page. As in: ?MSSunpack. +

+

The basic order of operations for running MSScvm is:

+
    +
  1. Download MSS image
  2. +
  3. Unpack the image using the MSSunpack function
  4. +
  5. Identify and download image-corresponding DEM(s)
  6. +
  7. Run the mosaicDEMs or reprojectDEM functions to prepare the DEM(s)
  8. +
  9. Create cloud and shadow mask using the MSScvm function
  10. +
+

+ If working with many images from the same Landsat footprint you will go through the above steps only once and + then just the following for each successive image: +

+
    +
  1. Unpack the image using the MSSunpack function
  2. +
  3. Create cloud and shadow mask using the MSScvm function
  4. +
+

+ MSScvm will automatically write outputs to the same directory location as the input image, with intuitive file + names that include the original image ID and descriptions for each type (DN, TOA radiance, TOA reflectance, and mask). + The images are in the GeoTIFF format in the native resolution and projection of the input image file, with background + values set to NoData. +

+
+ +
+ + +

Computer

+

MSScvm was developed and tested on computers running Windows 7 64-bit OS with >= 8 GB of RAM.

+

Software

+
    +
  • R
  • +
  • RStudio
  • +
  • GDAL
  • +
+
+ +
+ + +

+ MSScvm requires R, RStudio, and GDAL programs be installed on your computer. R is a free computer + programming language for statistical computing and graphics. RStudio provides a convenient front-end + interface to the R environment. GDAL is a program for reading, writing, and manipulating geospatial + data. +

+

+ If you don't already have a current version of these programs you'll need to download and install + them to your computer. +

+

R

+

Follow the install directions on the R website

+

RStudio

+

Follow the install directions on the RStudio website

+

MSScvm

+

See the Download page for instructions and the most current version

+

GDAL

+

There are numerous ways you can install GDAL, the following is one example.

+
    +
  1. Go to http://www.gisinternals.com/sdk/
  2. +
  3. Click on the Downloads link for the version that best matches your system (we use MSVC 2010 - x64)
  4. +
  5. Download the Generic installer for the GDAL core components
  6. +
  7. Run the installer
  8. +
  9. Include GDAL in your system's environmental variable PATH
  10. +
      +
    1. Open Windows Control Panel and select System
    2. +
    3. Click on Advanced system settings
    4. +
    5. Click the Environmental Variables... button
    6. +
    7. Under System variables, scroll down to the Path variable and click on it to highlight it
    8. +
    9. Click the edit button
    10. +
    11. + Get your cursor to the end of the line, add a semi-colon (;) and add the path to the GDAL + installation location. Example: C:\GDAL (this may not actually be the location on your system) +
    12. +
    +
+
+ +
+ + +

+ The MSS images processed by MSScvm should be compressed (.tar.gz) USGS LPGS images requested + through EarthExplorer. This will ensure that the automated + features of the program work correctly. They are contained in the Landsat Archive directory under the Data Sets + tab on the EarthExplorer website. +

+

+ Follow the instructions on the EarthExplorer site for selecting and downloading MSS images. When + you have received your images, place the unaltered *.tar.gz files in a directory that you have write + permission for, since MSScvm will write files to this location (some government and institutional systems + restrict user writing capabilities). +

+
+
+ + +

+ Run the MSSunpack function to decompress, stack, and optionally output top-of-atmosphere (TOA) + radiance and reflectance images. The imgFile input is the full path to a compressed LPGS MSS image from USGS EarthExplorer. The logical + parameters toaRad and toaRefl determine whether TOA radiance and reflectance images are created along + with the default DN image. The following examples demonstrate loading the MSScvm package and + running the MSSunpack function with and without the toaRad and toaRefl parameters (each set to FALSE by default). +

+

Load the MSScvm library (this only needs to be done once when a new R session is started):

+
library(MSScvm)
+
+

Run the MSSunpack function to create a 4-band DN image stack:

+
MSSunpack(imgFile = "C:/mss/LM10360321973191AAA04.tar.gz")
+
+

+ ... or optionally run the MSSunpack function with the toaRad and toaRefl parameters set to TRUE + to create 4-band DN, TOA radiance,and TOA reflectance image stacks: +

+
MSSunpack(imgFile = "C:/mss/LM10360321973191AAA04.tar.gz", toaRad = TRUE, toaRefl = TRUE)
+
+

+ GeoTIFF raster image files will be written out. The files will be placed + in a directory in the same location as the input imgFile with the name equal to the image ID. The files will + contain the image ID followed by descriptors "dn.tif" (digital number), "toa_radiance.tif" (TOA radiance), and + "toa_reflectance.tif" (TOA reflectance). Note that the values for TOA radiance + are scaled by 100 and rounded to the nearest integer and TOA reflectance is scaled by 10,000 and rounded + to the nearest integer. This is done to reduce image file size while retaining some decimal precision. +

+ +

Input/output file path examples:

+

+ If imgFile input equals: "C:/mss/LM10360321973191AAA04.tar.gz",
+ output DN file will be: "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif",
+ output TOA radiance file will be: "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_toa_radiance.tif",
+ output TOA reflectance file will be: "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_toa_reflectance.tif" +

+
+ +
+ + +

+ MSScvm uses a digital elevation model (DEM) to aid in separating topographic shadows from cloud shadows + and for identifying water. It is important that the DEM be greater or equal to the extent of the image it + is being used for, and that it matches the pixel resolution and projection of the image. +

+

+ Setting up the DEM can be a hassle, but MSScvm provides helper functions to make DEM preparation easy, but you first + need to download them or check that the DEMs you have are large enough or can be mosaiced to cover the image extent. If you ensure + that the DEM you use has a liberal buffer out from the WRS path/row you are working on, you will only need to prepare it once. After + that it can be applied to any image for that WRS path/row. So take a little extra time up front to prepare the DEM for future use. +

+

+ There are many sources of DEMs, and you can use what you like, but it's recommended that they be no more + than 90 meters in pixel resolution. A good source for DEMs is the Global Landcover Facility, which + distributes SRTM data as Landsat WRS-2 footprints. Use the Filled Finished-B product at 1 arc second + (30 meter) where possible and the Filled Finished-B product at 3 arc seconds (90 meter) elsewhere. + If using these data keep in mind that MSS images from sensors 1-3 use the WRS-1 footprint system so you will need to download several WRS-2 DEM footprints to + fully intersect the MSS WRS-1 footprint. We've also found that the actual extent of + a WRS-2 SRTM DEM will often not fully intersect the extent of a given image, even when the image is also WRS-2 (sensors 4-5). + For this reason, we typically mosaic 9 DEMs for each WRS footprint to ensure full overlap with any image + from the WRS path/row that we are working on (the MSScvm function will crop it on-the-fly in memory). In any case, + check for full overlap between your DEM(s) and your MSS image in a GIS. +

+

Mosaicking several DEMs together

+

+ If you need to mosaic several DEMs together to ensure full overlap with your image, place all of the relevant DEM files into a + single directory. There should be nothing else in the directory, and the files should all be decompressed GeoTIFF files. + It is also important that the DEMs are from the same source so that their background value is the same. This + value is specified in the call to the mosaicDEMs function and will be ignored during the mosaic procedure. If you need to + convert to GeoTIFF files, you can use the reprojectDEM function to do so. +

+

+ With the all of your relevant DEMs in a directory, run the mosaicDEMs function as follows, where dir is the + full path to the DEM directory, projRef is a *dn.tif file produced by the MSSunpack function that corresponds to the DEMs, + srcNodata is the background value of the DEMs in the DEM directory, and dstNoData sets the desired background value + for the output DEM mosaic. +

+

Example:

+
mosaicDEMs(dir = "C:/mss/dems", projRef = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif", srcNodata = -9999, dstNodata= -32768)
+
+

+ The function will produce a mosaic from all the files found in the directory specified by the dir parameter. It will be GeoTIFF format, with + the background value set to the value specified by the dstNodata parameter and will be placed in the same directory as dir with the name + dem_mosaic.tif. +

+ +

Reprojecting and resampling an existing DEM

+

+ If you have an existing DEM that is >= to the extend of the MSS image you want to create a cloud and shadow mask for or you need to + convert DEM files to GeoTIFF format for use in the mosaicDEMs function, use the reprojectDEM function. It will + take an input DEM file specified by the demFile parameter and make it match the projection and resolution of the relevant MSS image + specified by the projRef parameter. The srcNodata and dstNodata parameters are used to set the output's background + value. srcNodata is the background value of the input DEM and dstNoData sets the desired background value + for the output DEM. +

+

Example:

+
reprojectDEM(demFile = "C:/mss/dem/wrs1_p036r032_dem.tif", projRef = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif", srcNodata = -9999, dstNodata = -32768)
+
+

+ The function will produce a new DEM file in the GeoTIFF format, with the projection and pixel resolution matching that of the projRef image. The + the srcNodata value will be set to the value specified by the dstNodata parameter and the file will placed in the same directory as the demFile + with _reprojected.tif replacing the input file's extension. +

+
+ +
+ + +

+ Run the MSScvm function to create cloud and cloud shadow masks for MSS images. The inputs are the full + path to a directory containing an unpacked MSS image as the result of running the MSSunpack function (imgDir) and + the prepared image-corresponding DEM (demFile). An optional logical parameter classify specifies how to label the mask pixels. + The default is classify = FALSE, which returns a binary mask where pixels are either obscured (cloud and cloud shadow aggregated) or clear-view, alternatively, + TRUE will classify the pixels by clear-view, cloud shadow, and cloud. +

+

Example of running the MSScvm function:

+
MSScvm(imgDir = "C:/mss/LM10360321973191AAA04", demFile = "C:/mss/dem/wrs1_p036r032_dem.tif", classify = FALSE)
+
+

+ A GeoTIFF raster image file will be placed in the imgDir + directory with the name equal to the image ID followed by _msscvm.tif. If the classify parameter was + set to FALSE then obscured pixels (cloud and cloud shadow) will be set to value 0 and clear-view pixel set to 1. + If the classify parameter was set to TRUE then clear-view = 0, cloud shadow = 1, cloud = 2. +

+
+ +
+ + +

+ MSScvm has functions to convert DN images to TOA radiance and reflectance images. These functions can + optionally be called when running the MSSunpack function. If they were not run during + unpacking, they can be run independently by running the MSSdn2rad and MSSdn2refl functions. + The input (imgFile) for both functions is the full path to a *dn.tif file produced by running the MSSunpack + function. +

+

Create a TOA radiance file from a *dn.tif file:

+
MSSdn2rad(imgFile = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif")
+
+

Create a TOA reflectance file from a *dn.tif file:

+
MSSdn2refl(imgFile = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif")
+
+

+ Both functions will output a 4-band GeoTIFF raster image. The file will be placed in the same directory as the input imgFile + with the name equal to the image ID followed by "_toa_radiance.tif" or "_toa_reflectance.tif". Note that the values for TOA radiance + are scaled by 100 and rounded to the nearest integer and TOA reflectance is scaled by 10,000 and rounded + to the nearest integer. This is done to reduce image file size while retaining some decimal precision. +

+
+
+ +
+
+ + \ No newline at end of file diff --git a/imgs/MSScvm-manual.pdf b/imgs/MSScvm-manual.pdf new file mode 100644 index 0000000..0c46a06 Binary files /dev/null and b/imgs/MSScvm-manual.pdf differ diff --git a/imgs/braaten_et_al_2015_automated cloud_and_cloud_shadow_identification_in_landsat_mss_imagery_for_temperate_ecosystems.pdf b/imgs/braaten_et_al_2015_automated cloud_and_cloud_shadow_identification_in_landsat_mss_imagery_for_temperate_ecosystems.pdf new file mode 100644 index 0000000..df84e8a Binary files /dev/null and b/imgs/braaten_et_al_2015_automated cloud_and_cloud_shadow_identification_in_landsat_mss_imagery_for_temperate_ecosystems.pdf differ diff --git a/imgs/braatenj_portrait.jpg b/imgs/braatenj_portrait.jpg new file mode 100644 index 0000000..7e8827f Binary files /dev/null and b/imgs/braatenj_portrait.jpg differ diff --git a/imgs/example1.png b/imgs/example1.png new file mode 100644 index 0000000..62e073b Binary files /dev/null and b/imgs/example1.png differ diff --git a/imgs/example10.png b/imgs/example10.png new file mode 100644 index 0000000..ee98ce4 Binary files /dev/null and b/imgs/example10.png differ diff --git a/imgs/example11.png b/imgs/example11.png new file mode 100644 index 0000000..9d73cbe Binary files /dev/null and b/imgs/example11.png differ diff --git a/imgs/example12.png b/imgs/example12.png new file mode 100644 index 0000000..aa3dbc3 Binary files /dev/null and b/imgs/example12.png differ diff --git a/imgs/example13.png b/imgs/example13.png new file mode 100644 index 0000000..aba2c75 Binary files /dev/null and b/imgs/example13.png differ diff --git a/imgs/example14.png b/imgs/example14.png new file mode 100644 index 0000000..d620125 Binary files /dev/null and b/imgs/example14.png differ diff --git a/imgs/example15.png b/imgs/example15.png new file mode 100644 index 0000000..2240ecc Binary files /dev/null and b/imgs/example15.png differ diff --git a/imgs/example16.png b/imgs/example16.png new file mode 100644 index 0000000..b3798a3 Binary files /dev/null and b/imgs/example16.png differ diff --git a/imgs/example17.png b/imgs/example17.png new file mode 100644 index 0000000..4b14834 Binary files /dev/null and b/imgs/example17.png differ diff --git a/imgs/example17_2.png b/imgs/example17_2.png new file mode 100644 index 0000000..4b14834 Binary files /dev/null and b/imgs/example17_2.png differ diff --git a/imgs/example18.png b/imgs/example18.png new file mode 100644 index 0000000..2830f7b Binary files /dev/null and b/imgs/example18.png differ diff --git a/imgs/example19.png b/imgs/example19.png new file mode 100644 index 0000000..d7d0a09 Binary files /dev/null and b/imgs/example19.png differ diff --git a/imgs/example2.png b/imgs/example2.png new file mode 100644 index 0000000..3a1083d Binary files /dev/null and b/imgs/example2.png differ diff --git a/imgs/example20.png b/imgs/example20.png new file mode 100644 index 0000000..6973cf2 Binary files /dev/null and b/imgs/example20.png differ diff --git a/imgs/example3.png b/imgs/example3.png new file mode 100644 index 0000000..561e111 Binary files /dev/null and b/imgs/example3.png differ diff --git a/imgs/example4.png b/imgs/example4.png new file mode 100644 index 0000000..7f90b89 Binary files /dev/null and b/imgs/example4.png differ diff --git a/imgs/example5.png b/imgs/example5.png new file mode 100644 index 0000000..7c1e53e Binary files /dev/null and b/imgs/example5.png differ diff --git a/imgs/example6.png b/imgs/example6.png new file mode 100644 index 0000000..6162d18 Binary files /dev/null and b/imgs/example6.png differ diff --git a/imgs/example7.png b/imgs/example7.png new file mode 100644 index 0000000..54fa85a Binary files /dev/null and b/imgs/example7.png differ diff --git a/imgs/example8.png b/imgs/example8.png new file mode 100644 index 0000000..d811842 Binary files /dev/null and b/imgs/example8.png differ diff --git a/imgs/example9.png b/imgs/example9.png new file mode 100644 index 0000000..c8a932e Binary files /dev/null and b/imgs/example9.png differ diff --git a/imgs/favicon.ico b/imgs/favicon.ico new file mode 100644 index 0000000..bbdd238 Binary files /dev/null and b/imgs/favicon.ico differ diff --git a/imgs/indeximg.png b/imgs/indeximg.png new file mode 100644 index 0000000..e7f90be Binary files /dev/null and b/imgs/indeximg.png differ diff --git a/imgs/indeximgsmall.png b/imgs/indeximgsmall.png new file mode 100644 index 0000000..2fd7631 Binary files /dev/null and b/imgs/indeximgsmall.png differ diff --git a/imgs/spinner.gif b/imgs/spinner.gif new file mode 100644 index 0000000..f83606a Binary files /dev/null and b/imgs/spinner.gif differ diff --git a/imgs/tcb_banner.jpg b/imgs/tcb_banner.jpg new file mode 100644 index 0000000..4ee81dc Binary files /dev/null and b/imgs/tcb_banner.jpg differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..058b227 --- /dev/null +++ b/index.html @@ -0,0 +1,49 @@ + + + + MSScvm + + + + + + + + + + +
+
+
+

MSScvm: An automated system to created cloud and + cloud shadow masks for Landsat MSS imagery. +

+ Learn more +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/man/MSScvm.Rd b/man/MSScvm.Rd deleted file mode 100644 index 99ca015..0000000 --- a/man/MSScvm.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand -% Please edit documentation in R/MSScvm.r -\name{MSScvm} -\alias{MSScvm} -\title{Landsat MSS cloud and cloud shadow masking} -\usage{ -MSScvm(imgDir, demFile, classify = F) -} -\arguments{ -\item{imgDir}{directory name (character). Full path to a MSS image directory produced by the \code{\link{MSSunpack}} function.} - -\item{demFile}{filename (character). Full path to image-corresponding DEM file.} - -\item{classify}{logical. If TRUE clouds, cloud shadows, and clear pixels have unique values (0 = clear, 1 = cloud shadow, 2 = cloud). -If FALSE obscured pixles = 0 and clear = 1.} -} -\value{ -A GeoTIFF raster image file with the same dimensions as the MSS image. The file will be placed in the -'imgDir' directory with the name equal to the image ID followed by '_msscvm'. -} -\description{ -Creates a cloud and cloud shadow mask for Landsat MSS imagery. -} -\details{ -It is important that the input DEM file, specified by the 'demFile' parameter, be the same projection and pixel resolution as the -input image. It must also be >= in spatial extent, relative to the image. The program will check for these attributes and throw an error message if -there is a violation. There are two helper functions to prepare a suitable DEM. Use the \code{\link{reprojectDEM}} function to ensure proper projection -and pixel resolution of an exisiting DEM, and the \code{\link{mosaicDEMs}} function to create a mosaic from several DEMs to ensure proper extent, projection, -and pixel resolution. -} -\examples{ -\dontrun{ - -MSScvm(imgDir = "C:/mss/LM10360321973191AAA04", - demFile = "C:/mss/dem/wrs1_p036r032_dem.tif") -} -} - diff --git a/man/MSSdn2rad.Rd b/man/MSSdn2rad.Rd deleted file mode 100644 index c31c65e..0000000 --- a/man/MSSdn2rad.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand -% Please edit documentation in R/MSSdn2rad.r -\name{MSSdn2rad} -\alias{MSSdn2rad} -\title{Convert MSS DN values to TOA radiance} -\usage{ -MSSdn2rad(imgFile) -} -\arguments{ -\item{imgFile}{filename (character). Full path to *dn.tif image file produced by the \code{\link{MSSunpack}} function.} -} -\value{ -A 4-band Landsat MSS GeoTIFF raster image file in units of top-of-atmosphere (TOA) radiance. The file will be placed in -same directory as the 'imgFile' with the name equal to the image ID followed by 'toa_radiance'. Note that the values are scaled by 100 -and rounded to the nearest integer to reduce the file size. -} -\description{ -Convert MSS DN values to TOA radiance. -} -\details{ -The equation used to convert DN to TOA radiance can be found \href{http://landsat.usgs.gov/how_is_radiance_calculated.php}{here}. -} -\examples{ -\dontrun{ - -MSSdn2rad("C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif") -} -} -\seealso{ -\code{\link{MSSdn2refl}} -} - diff --git a/man/MSSdn2refl.Rd b/man/MSSdn2refl.Rd deleted file mode 100644 index 7ac0cd5..0000000 --- a/man/MSSdn2refl.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand -% Please edit documentation in R/MSSdn2refl.r -\name{MSSdn2refl} -\alias{MSSdn2refl} -\title{Convert MSS DN values to TOA reflectance} -\usage{ -MSSdn2refl(imgFile) -} -\arguments{ -\item{imgFile}{filename (character). Full path to *dn.tif image file produced by the \code{\link{MSSunpack}} function.} -} -\value{ -A 4-band Landsat MSS GeoTIFF raster image file in units of top-of-atmosphere (TOA) reflectance. The file will be placed in the -same directory as the 'imgFile' with the name equal to the image ID followed by 'toa_reflectance'. Note that the values are scaled by 10,000 -and rounded to the nearest integer to reduce the file size. -} -\description{ -Convert MSS DN values to TOA reflectance. -} -\details{ -DN values are first converted to top-of-atmosphere (TOA) radiance using the equation found \href{http://landsat.usgs.gov/how_is_radiance_calculated.php}{here}. -Then TOA radiance is converted to TOA reflectance using the equation found \href{http://landsathandbook.gsfc.nasa.gov/data_prod/prog_sect11_3.html}{here}. -The ESUN values used are from the publication 'Chander et al. 2009. Summary of current radiometric calibration coefficients... Remote Sensing of Environment. 113'. -} -\examples{ -\dontrun{ - -MSSdn2refl("C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif") -} -} -\seealso{ -\code{\link{MSSdn2rad}} -} - diff --git a/man/MSSunpack.Rd b/man/MSSunpack.Rd deleted file mode 100644 index ef7e147..0000000 --- a/man/MSSunpack.Rd +++ /dev/null @@ -1,44 +0,0 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand -% Please edit documentation in R/MSSunpack.r -\name{MSSunpack} -\alias{MSSunpack} -\title{Decompress and stack Landsat LPGS MSS images} -\usage{ -MSSunpack(imgFile, toaRad = FALSE, toaRefl = FALSE, useL1G = FALSE) -} -\arguments{ -\item{imgFile}{filename (character). Full path to compressed LPGS Landsat MSS image file provided by USGS.} - -\item{toaRad}{logical. If TRUE, a TOA radiance image will be created.} - -\item{toaRefl}{logical. If TRUE, a TOA reflectance image will be created.} - -\item{useL1G}{logical. If TRUE, L1G images will be processed.} -} -\value{ -A 4-band Landsat MSS GeoTIFF raster image file in DN units. If optional 'toaRad' and/or 'toaRefl' -parameters are set to TRUE, then similar TOA radiance and reflectance image files will created. The files will be places in -the same location as the 'imgFile' with the name equal to the image ID plus an appended descriptor. Descriptors -include 'dn' (digital number), 'toa_radiance' (TOA radiance), and 'toa_reflectance' (TOA reflectance). -} -\description{ -Decompresses and stacks Landsat LPGS MSS images provided by USGS as *.tar.gz files. Optionally -outputs top-of-atmosphere (TOA) radiance and reflectance files. -} -\details{ -It is important that the 'imgFile' be an unaltered tar.gz-compressed LPGS image file that you receive -from USGS through \href{http://rstudio.com}{EarthExplorer}. Note that DN values <= 1 are set to NA across all bands. -This mitigates a problem caused by bad columns on the east and west edge of images when mosaicing adjacent images together. -} -\examples{ -\dontrun{ - -MSSunpack(imgFile = "C:/mss/LM10360321973191AAA04.tar.gz") -MSSunpack(imgFile = "C:/mss/LM10360321973191AAA04.tar.gz", - toaRad = FALSE, toaRefl = TRUE, useL1G = TRUE) -} -} -\seealso{ -\code{\link{MSSdn2rad}}, \code{\link{MSSdn2refl}} -} - diff --git a/man/eudist.Rd b/man/eudist.Rd deleted file mode 100644 index 22bbb88..0000000 --- a/man/eudist.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand -% Please edit documentation in R/eudist.r -\name{eudist} -\alias{eudist} -\title{Earth-Sun distance by day-of-year} -\usage{ -eudist(doy) -} -\arguments{ -\item{doy}{integer. image day-of-year.} -} -\description{ -Retrieve the Earth-Sun distance by day-of-year. It is helper function used -by the \code{\link{MSSdn2refl}} and \code{\link{MSScvm}} functions when calculating TOA reflectance. -} -\details{ -The function returns the Earth-sun distance for a specific day-of-year as defined -\href{http://landsathandbook.gsfc.nasa.gov/data_prod/prog_sect11_3.html}{here}. -} -\examples{ -dist = eudist(215) -} - diff --git a/man/getMetadata.Rd b/man/getMetadata.Rd deleted file mode 100644 index 6a55456..0000000 --- a/man/getMetadata.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand -% Please edit documentation in R/getMetadata.r -\name{getMetadata} -\alias{getMetadata} -\title{Retrieve Landsat image metadata} -\usage{ -getMetadata(imgFile) -} -\arguments{ -\item{imgFile}{filename (character). Full path to a Landast LPGS MSS file that includes the -original image ID as the first block of characters.} -} -\value{ -data.frame with image information. -} -\description{ -Uses the image file name to find the corresponding *MTL.txt image metadata file provided with LPSG Landsat images -and returns a data.frame with image information. -} -\examples{ -\dontrun{ - -getMetadata("C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif") -} -} - diff --git a/man/mosaicDEMs.Rd b/man/mosaicDEMs.Rd deleted file mode 100644 index ca1c99e..0000000 --- a/man/mosaicDEMs.Rd +++ /dev/null @@ -1,43 +0,0 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand -% Please edit documentation in R/mosaicDEMs.r -\name{mosaicDEMs} -\alias{mosaicDEMs} -\title{Create a DEM mosaic from a direcory of DEM's} -\usage{ -mosaicDEMs(dir, projRef, srcNodata = NA, dstNodata = -32768) -} -\arguments{ -\item{dir}{directory name (character). Full path to a directory containing digital elevation model (DEM) files to be mosaiced.} - -\item{projRef}{filename (character). Full path to an image file produced by the \code{\link{MSSunpack}} function to be used as the projection reference.} - -\item{srcNodata}{numeric. Specify the background value of the DEM files in the directory. If there is no background value, use NA (default) .} - -\item{dstNodata}{numeric. Specify the value to represent background pixels in the mosaic DEM. -32768 is the default.} -} -\value{ -A GeoTIFF raster file representing the union of all individual DEM files found in the provided directory path. The mosaic file will be written to the -provided directory as "dem_mosaic.tif". -} -\description{ -A helper function to create the large-extent DEM file required by the \code{\link{MSScvm}} function. -} -\details{ -The provided directory path should only contain decompressed digital elevation files from the same source (SRTM, NED, GTOPO, etc). -The function will search the directory and include all files found in the mosaic. It is important that each file have the same background value -and that it is correctly assigned to the 'srcNodata' parameter, if not, intersection between DEMs could have unexpected results. -Each individual DEM file will be adjusted to match the projection and pixel resolution of the 'proRef' image. -Then they will be merged using the mean value of intersecting pixels. -} -\examples{ -\dontrun{ - -mosaicDEMs(dir = "C:/mss/dems", - projRef = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif", - srcNodata = -9999, dstNodata= -32768) -} -} -\seealso{ -\code{\link{reprojectDEM}} -} - diff --git a/man/reprojectDEM.Rd b/man/reprojectDEM.Rd deleted file mode 100644 index 726dae3..0000000 --- a/man/reprojectDEM.Rd +++ /dev/null @@ -1,39 +0,0 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand -% Please edit documentation in R/reprojectDEM.r -\name{reprojectDEM} -\alias{reprojectDEM} -\title{Reproject a DEM file} -\usage{ -reprojectDEM(demFile, projRef, srcNodata = NA, dstNodata = -32768) -} -\arguments{ -\item{demFile}{filename (character). Full path to DEM file.} - -\item{projRef}{filename (character). Full path to an image file produced by the \code{\link{MSSunpack}} function.} - -\item{srcNodata}{numeric. Specify the background value in the input DEM. If there is no background value, use NA (default).} - -\item{dstNodata}{numeric. Specify the value to represent background pixels in the reprojected DEM. -32768 is the default.} -} -\value{ -A GeoTIFF raster file with '_reprojected.tif' replacing the last 4 characters of the input DEM filename. -} -\description{ -Reproject a DEM file to match the projection and pixel resolution of an image file. A helper function to make a DEM -conform to the properties of an image file prior to using it as an input to the \code{\link{MSScvm}} masking function. -} -\details{ -The DEM file will be adjusted to match the projection and pixel resolution of the 'proRef' image. -} -\examples{ -\dontrun{ - -reprojectDEM(demFile = "C:/mss/dem/wrs1_p036r032_dem.tif", - projRef = "C:/mss/LM10360321973191AAA04/LM10360321973191AAA04_dn.tif", - srcNodata= -9999, dstNodata= -32768) -} -} -\seealso{ -\code{\link{mosaicDEMs}} -} - diff --git a/style.css b/style.css new file mode 100644 index 0000000..a0bad3c --- /dev/null +++ b/style.css @@ -0,0 +1,141 @@ +/*style for msscvm webpages*/ + +/*navigation bar colors*/ +.navbar{ + background-color: white; + background: white; +} + +/*puts a little space at the end of pages and between the example images*/ +.bottom_margin{margin-bottom: 40px;} + +/*puts extra space at the bottom of the guide page so that final section link has the same top position as the others*/ +.guide_page_bottom{margin-bottom: 600px;} + +/*adds some space between the navbar and the page content*/ +.top_margin{margin-top:100px;} + +/*ensure that the code lines for downloading msscvm don't wrap*/ +.pre{overflow-x:scroll;} + +/*removes the top margin from some header elements*/ +.no_top_margin{margin-top:0px;} + +/*lowers the msscvm description on the home page for aesthetic*/ +#opening_descrip{margin-top:40px;} + +.img-wrapper{width:1140px; height:280px; background: url("imgs/spinner.gif") 50% 50% no-repeat} +.spriteimg{background-color:transparent;} + +/*the example images and their cloud mask*/ +#indeximg{width:1140px; height:280px; background: url("imgs/indeximgsmall.png") 0px 0px no-repeat} +#indeximg:hover {background: url("imgs/indeximgsmall.png") 0px -280px no-repeat} + +#example1{width:1140px; height:280px; background: url("imgs/example1.png") 0px 0px no-repeat} +#example1:hover {background: url("imgs/example1.png") 0px -280px no-repeat} + +#example2{width:1140px; height:280px; background: url("imgs/example2.png") 0px 0px no-repeat} +#example2:hover {background: url("imgs/example2.png") 0px -280px no-repeat} + +#example3{width:1140px; height:280px; background: url("imgs/example3.png") 0px 0px no-repeat} +#example3:hover {background: url("imgs/example3.png") 0px -280px no-repeat} + +#example4{width:1140px; height:280px; background: url("imgs/example4.png") 0px 0px no-repeat} +#example4:hover {background: url("imgs/example4.png") 0px -280px no-repeat} + +#example5{width:1140px; height:280px; background: url("imgs/example5.png") 0px 0px no-repeat} +#example5:hover {background: url("imgs/example5.png") 0px -280px no-repeat} + +#example6{width:1140px; height:280px; background: url("imgs/example6.png") 0px 0px no-repeat} +#example6:hover {background: url("imgs/example6.png") 0px -280px no-repeat} + +#example7{width:1140px; height:280px; background: url("imgs/example7.png") 0px 0px no-repeat} +#example7:hover {background: url("imgs/example7.png") 0px -280px no-repeat} + +#example8{width:1140px; height:280px; background: url("imgs/example8.png") 0px 0px no-repeat} +#example8:hover {background: url("imgs/example8.png") 0px -280px no-repeat} + +#example9{width:1140px; height:280px; background: url("imgs/example9.png") 0px 0px no-repeat} +#example9:hover {background: url("imgs/example9.png") 0px -280px no-repeat} + +#example10{width:1140px; height:280px; background: url("imgs/example10.png") 0px 0px no-repeat} +#example10:hover {background: url("imgs/example10.png") 0px -280px no-repeat} + +#example11{width:1140px; height:280px; background: url("imgs/example11.png") 0px 0px no-repeat} +#example11:hover {background: url("imgs/example11.png") 0px -280px no-repeat} + +#example12{width:1140px; height:280px; background: url("imgs/example12.png") 0px 0px no-repeat} +#example12:hover {background: url("imgs/example12.png") 0px -280px no-repeat} + +#example13{width:1140px; height:280px; background: url("imgs/example13.png") 0px 0px no-repeat} +#example13:hover {background: url("imgs/example13.png") 0px -280px no-repeat} + +#example14{width:1140px; height:280px; background: url("imgs/example14.png") 0px 0px no-repeat} +#example14:hover {background: url("imgs/example14.png") 0px -280px no-repeat} + +#example15{width:1140px; height:280px; background: url("imgs/example15.png") 0px 0px no-repeat} +#example15:hover {background: url("imgs/example15.png") 0px -280px no-repeat} + +#example16{width:1140px; height:280px; background: url("imgs/example16.png") 0px 0px no-repeat} +#example16:hover {background: url("imgs/example16.png") 0px -280px no-repeat} + +#example17{width:1140px; height:280px; background: url("imgs/example17.png") 0px 0px no-repeat} +#example17:hover {background: url("imgs/example17.png") 0px -280px no-repeat} + +#example18{width:1140px; height:280px; background: url("imgs/example18.png") 0px 0px no-repeat} +#example18:hover {background: url("imgs/example18.png") 0px -280px no-repeat} + +#example19{width:1140px; height:280px; background: url("imgs/example19.png") 0px 0px no-repeat} +#example19:hover {background: url("imgs/example19.png") 0px -280px no-repeat} + +#example20{width:1140px; height:280px; background: url("imgs/example20.png") 0px 0px no-repeat} +#example20:hover {background: url("imgs/example20.png") 0px -280px no-repeat} + + +/*settings for the scrollspy guide page anchor at the top of the page*/ +.guide_anchor_top{ + display: block; + height: 100px; /*same height as header*/ + margin-top: -100px; /*same height as header*/ + visibility: hidden; +} + +/*settings for the scrollspy guide page anchors (not top)*/ +.guide_anchor{ + display: block; + height: 60px; /*same height as header*/ + margin-top: -60px; /*same height as header*/ + visibility: hidden; +} + +/*set position of the sidenav on the guide page and fix it*/ +.bs-docs-sidenav{ + top: 100px; + position: fixed; +} + +/*make the color of the navbar stuff grey*/ +.bs-docs-sidenav > li.active > a, .bs-docs-sidenav > li.active > a:hover, .bs-docs-sidenav > li.active > a:focus { + background-color:#E7E7E7; +} + +/*set the scrollbar to the right of the main text*/ +#myScrollspy{ + display:inline-block; + margin-left:80px; +} + +/*make the scrollbar disappear if less window is less than 1000px*/ +@media screen and (max-width: 1000px){ + #myScrollspy{visibility: hidden;} +} + + + + + + + + + +