<commit_before>#' Make a usearea file in ENVI (bsq) format
#'
#' Make a usearea file in ENVI (bsq) format
#' @param infile character. full path name to a usearea mask file
#' @param projref charcter. full path to an image file from the scene relevent to the usearea file - can be any .tif file in the "images" directory
#' @import raster
#' @import rgdal
#' @import gdalUtils
#' @export

make_usearea_file_bsq = function(infile, projref){
  
  #infile = "E:/llr_chlor_projects/test/useareafiles/useareafile.tif"
  #projref = "E:/llr_chlor_projects/test/mss/wrs1/041029/images/1976/LM10410291976181_archv.tif"
  print("Making a copy of use-area file as .bsq for optional use in LandTrendr")
  
  tempout = paste(infile,"_temp.tif",sep="")
  template = r = raster(infile)
  r = as.matrix(r)
  nas = which(is.na(r) == T)
  ones = which(r != 0)
  zero = which(r == 0)
  if(length(nas) > 0){r[nas] = 0}
  if(length(zero) > 0){r[zero] = 0}
  r[ones] = 1
  r = setValues(template,r)
  projection(r) = set_projection(projref)
  r = as(r, "SpatialGridDataFrame")
  writeGDAL(r, tempout, drivername = "GTiff", type = "Byte", options="INTERLEAVE=BAND")
  
  outfile = paste(substr(infile,1,(nchar(infile)-3)),"bsq",sep="")
  
  s_srs = projection(raster(tempout))
  t_srs = set_projection(projref)
  gdalwarp(srcfile=tempout, dstfile=outfile, s_srs=s_srs, t_srs=t_srs, order=1, tr=c(30,30), r="near", of="ENVI", dstnodata="none")
  unlink(tempout)
}<commit_msg>added deleting of old usearea bsq files when new one is created<commit_after>#' Make a usearea file in ENVI (bsq) format
#'
#' Make a usearea file in ENVI (bsq) format
#' @param infile character. full path name to a usearea mask file
#' @param projref charcter. full path to an image file from the scene relevent to the usearea file - can be any .tif file in the "images" directory
#' @import raster
#' @import rgdal
#' @import gdalUtils
#' @export

make_usearea_file_bsq = function(infile, projref){
  
  #infile = "E:/llr_chlor_projects/test/useareafiles/useareafile.tif"
  #projref = "E:/llr_chlor_projects/test/mss/wrs1/041029/images/1976/LM10410291976181_archv.tif"
  print("Making a copy of use-area file as .bsq for optional use in LandTrendr")
  
  tempout = paste(infile,"_temp.tif",sep="")
  template = r = raster(infile)
  r = as.matrix(r)
  nas = which(is.na(r) == T)
  ones = which(r != 0)
  zero = which(r == 0)
  if(length(nas) > 0){r[nas] = 0}
  if(length(zero) > 0){r[zero] = 0}
  r[ones] = 1
  r = setValues(template,r)
  projection(r) = set_projection(projref)
  r = as(r, "SpatialGridDataFrame")
  writeGDAL(r, tempout, drivername = "GTiff", type = "Byte", options="INTERLEAVE=BAND")
  
  outfile = paste(substr(infile,1,(nchar(infile)-3)),"bsq",sep="")
  oldfiles = list.files(dirname(outfile),basename(outfile),full.names=T)
  oldhdr = sub("bsq","hdr",outfile)
  unlink(c(oldfiles,oldhdr))
  
  s_srs = projection(raster(tempout))
  t_srs = set_projection(projref)
  gdalwarp(srcfile=tempout, dstfile=outfile, s_srs=s_srs, t_srs=t_srs, order=1, tr=c(30,30), r="near", of="ENVI", dstnodata="none")
  unlink(tempout)
}
{'fraction_non_alphanumeric': 0.15155440414507773, 'fraction_numerical': 0.025259067357512953, 'mean_word_length': 4.883809523809524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '739912', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1220, 'n_words': 286}