R/FITS2JPG_function.R

Defines functions FITS2JPG

Documented in FITS2JPG

#' ReVuePro: FITS2JPG
#'
#' A function to convert two-dimensional FITS files to JPG images.
#' @param source The path to a file, or folder of FITS files you wish to convert to JPG images.
#' @param destination The path to a folder you wish to save your JPG output files to.
#' @keywords Thermal Imaging, ReVuePro
#' @import FITSio jpeg
#' @export
#' @examples
#' source="C:/ThermalFITSfiles"
#' destination="C:/MyJPGimages"
#' FITS2JPG(source=source, destination=destination)

FITS2JPG = function(source, destination){

   require('FITSio')
   require('jpeg')
   originalwd=getwd()

   is.character0 <- function(x){
   is.character(x) && length(x) == 0L
   }

   rotate <- function(x) t(apply(x, 2, rev))

   if(!is.character0(list.files(source))){
      for(i in 1:length(list.files(source))){ 
      setwd(source)   
      toconv=list.files()[i]
      fits=readFITS(toconv)
  
      WriteFile=paste(gsub("\\..*", "", source),".jpg",sep="")      
      setwd(destination)
      writeJPEG(rotate(rotate(rotate(fits))), WriteFile)
      }
     setwd(originalwd)
    }

    if(is.character0(list.files(source))){

      fits=read.fits(source)
      WriteFile=paste(gsub("\\..*", "", source),".jpg",sep="")      
      setwd(destination)
      writeJPEG(rotate(rotate(rotate(fits$dat[[1]]))), WriteFile)
      setwd(originalwd)
      }
}
joshuakrobertson/R-Package_ReVuePro documentation built on June 2, 2020, 8:23 p.m.