Skip to content

Commit

Permalink
Merge pull request #4 from jdbcode/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jdbcode authored Jul 26, 2016
2 parents 312dab5 + 92b83ac commit 366f6c5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: LandsatLinkr
Title: Tools to spectrally link Landsat data
Version: 0.3.4
Date: 2016-07-07
Version: 0.3.5
Date: 2016-07-026
Authors@R: c(person("Justin", "Braaten", email = "[email protected]", role = c("aut", "cre")),
person("Warren", "Cohen", email = "[email protected]", role = "aut"),
person("Zhiqiang", "Yang", email = "[email protected]", role = "aut"))
Expand Down
6 changes: 3 additions & 3 deletions R/calibrate_and_composite.r
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' @export


calibrate_and_composite = function(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index,outdir,runname,useareafile,doyears="all",order="none",overlap="mean", cores=2, process, overwrite=F ,startday, endday){
calibrate_and_composite = function(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index,outdir,runname,useareafile,doyears="all",order="none",overlap="mean", cores=2, process, overwrite=F ,startday, endday, yearadj){

#msscal
if(1 %in% process ==T){
Expand Down Expand Up @@ -60,10 +60,10 @@ calibrate_and_composite = function(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,in
if(index == "all"){
index = c("tca", "tcb", "tcg", "tcw")
outdir = c(file.path(outdir,"tca"),file.path(outdir,"tcb"),file.path(outdir,"tcg"),file.path(outdir,"tcw"))
for(i in 1:length(index)){mixel(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index[i],outdir[i],runname,useareafile,doyears="all",order="none",overlap=overlap, startday=startday, endday=endday)} #overlap="mean"
for(i in 1:length(index)){mixel(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index[i],outdir[i],runname,useareafile,doyears="all",order="none",overlap=overlap, startday=startday, endday=endday, yearadj=yearadj)} #overlap="mean"
} else {
outdir = file.path(outdir,index)
mixel(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index,outdir,runname,useareafile,doyears="all",order="none",overlap=overlap, startday=startday, endday=endday) #overlap="mean"
mixel(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index,outdir,runname,useareafile,doyears="all",order="none",overlap=overlap, startday=startday, endday=endday, yearadj=yearadj) #overlap="mean"
}
print(proc.time()-t)
}
Expand Down
16 changes: 9 additions & 7 deletions R/mixel.r
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @export


mixel = function(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index,outdir,runname,useareafile,doyears="all",order="none",overlap="mean",startday,endday){
mixel = function(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index,outdir,runname,useareafile,doyears="all",order="none",overlap="mean",startday,endday,yearadj=0){

mixel_find = function(files, refimg){
info = matrix(ncol = 4, nrow=length(files))
Expand Down Expand Up @@ -74,7 +74,7 @@ mixel = function(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index,outdir,runname
file.rename(envixmlfile,bsqxmlfile)
}

mixel_composite = function(outdir, imginfosub, runname, index, order, useareafile, overlap){
mixel_composite = function(outdir, imginfosub, runname, index, order, useareafile, overlap, yearadj){

#outdir= mssdir
#imginfosub = mssdf
Expand Down Expand Up @@ -110,7 +110,8 @@ mixel = function(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index,outdir,runname
if(len == 1){newimg = r1} else {eval(parse(text=mergeit))} #only run merge it if there are multiple files to merge

#name the new file
newbase = paste(uniyears[i],"_",runname,"_",index,"_composite.bsq", sep="")
yearlabel = as.character(as.numeric(uniyears[i])+yearadj)
newbase = paste(yearlabel,"_",runname,"_",index,"_composite.bsq", sep="")
outimgfile = file.path(outdir,newbase)
outtxtfile = sub("composite.bsq", "composite_img_list.csv", outimgfile)
theseimgs = data.frame(theseimgs)
Expand Down Expand Up @@ -341,7 +342,8 @@ mixel = function(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index,outdir,runname
for(i in 1:nrow(imginfo)){imginfo$decdate[i] = decyearday(as.numeric(imginfo$year[i]),as.numeric(imginfo$day[i]))}

#figure out the dec year day range that is good
uniyears = as.numeric(sort(unique(imginfo$year)))
#uniyears = as.numeric(sort(unique(imginfo$year)))
uniyears = 1972:as.numeric(format(Sys.Date(),'%Y'))

if(doyears != "all"){uniyears = uniyears[match(doyears,uniyears)]}

Expand Down Expand Up @@ -376,15 +378,15 @@ mixel = function(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index,outdir,runname
#create annual composites for all sensors
if(nrow(mssdf) != 0){
dir.create(mssdir, recursive=T, showWarnings=F)
mixel_composite(mssdir, mssdf, runname=runname,index=index, order=order, useareafile=useareafile, overlap=overlap)
mixel_composite(mssdir, mssdf, runname=runname,index=index, order=order, useareafile=useareafile, overlap=overlap, yearadj=yearadj)
}
if(nrow(tmetmdf) != 0){
dir.create(tmdir, recursive=T, showWarnings=F)
mixel_composite(tmdir, tmetmdf, runname=runname,index=index, order=order, useareafile=useareafile, overlap=overlap)
mixel_composite(tmdir, tmetmdf, runname=runname,index=index, order=order, useareafile=useareafile, overlap=overlap, yearadj=yearadj)
}
if(nrow(olidf) != 0){
dir.create(olidir, recursive=T, showWarnings=F)
mixel_composite(olidir, olidf, runname=runname,index=index, order=order, useareafile=useareafile, overlap=overlap)
mixel_composite(olidir, olidf, runname=runname,index=index, order=order, useareafile=useareafile, overlap=overlap, yearadj=yearadj)
}

#deal with the overlapping composites
Expand Down
15 changes: 14 additions & 1 deletion R/run_landsatlinkr.r
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,19 @@ run_landsatlinkr = function(){
if(correct == "Exit"){return(cat("Stopping LLR","\n\n"))}
}

#figure out how to name the files
if((endday-startday) < 0){
cat("\n")
correct = "No"
while(correct == "No"){
yearadj = select.list(c("Pre","Post"), title = "Your date range crosses the year divide, would you like to label the annual composite files with the pre- or post- divide year?")
cat("You have selected:",yearadj,"\n")
correct = select.list(c("Yes","No","Exit"), title = "Is that correct?")
if(correct == "Exit"){return(cat("Stopping LLR","\n\n"))}
}
yearadj = ifelse(yearadj == "Post", 1, 0)
}

#overlap methods
correct = "No"
while(correct == "No"){
Expand Down Expand Up @@ -425,7 +438,7 @@ run_landsatlinkr = function(){
#################################################################################################################
#execute the calibrate_and_composite function

calibrate_and_composite(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index="all",outdir,runname,useareafile,doyears="all",order="none",overlap=overlap, cores=cores, process=calcomprocess, overwrite=overwrite, startday=startday, endday=endday) #overlap="mean"
calibrate_and_composite(msswrs1dir,msswrs2dir,tmwrs2dir,oliwrs2dir,index="all",outdir,runname,useareafile,doyears="all",order="none",overlap=overlap, cores=cores, process=calcomprocess, overwrite=overwrite, startday=startday, endday=endday, yearadj=yearadj) #overlap="mean"
}

#if(sum(process %in% 9 > 0)){
Expand Down
3 changes: 2 additions & 1 deletion man/calibrate_and_composite.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/mixel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 366f6c5

Please sign in to comment.