Learn R Programming

ImageFusion (version 0.0.1)

imginterp_task: Perform time-series image interpolation

Description

A utility function of the ImageFusion Package, which performs simple interpolation on a given time series of remote sensing images

Usage

imginterp_task(
  filenames,
  dates,
  tags = NULL,
  layers = NULL,
  limit_days = 5,
  output_pixelstate = FALSE,
  use_nodata = TRUE,
  interp_invalid = TRUE,
  prioritize_invalid = FALSE,
  interp_ranges = NULL,
  no_interp_ranges = NULL,
  valid_ranges = NULL,
  invalid_ranges = NULL,
  out_prefix = NULL,
  out_postfix = NULL,
  out_pixelstate_prefix = NULL,
  out_pixelstate_postfix = NULL,
  stats_filename = NULL,
  print_stats = FALSE,
  ql_filenames = NULL,
  ql_dates = NULL,
  ql_tags = NULL,
  ql_layers = NULL,
  ql_bits = NULL,
  ql_interp_ranges = NULL,
  ql_non_interp_ranges = NULL,
  mask_filenames = NULL,
  mask_layers = NULL,
  mask_bits = NULL,
  mask_valid_ranges = NULL,
  mask_invalid_ranges = NULL,
  verbose = FALSE
)

Arguments

filenames

A character vector of the filenames of the images to interpolate.

dates

An integer vector of the dates associated with the filenames. Must match filenames in length and order.

tags

(Optional) A character vector of the resolution tags associated with the filenames. Interpolation will be done in groups based on these tags. By default, no grouping will be done.

layers

A list of numeric (specifically a num-list, see below at <num-list>). Specifies the channels or layers, that will be read. Hereby a 0 means the first channel. Should be either matching filenames in length and order or be of length 1, in which case the selection will be applied to all images.

limit_days

(Optional) Integer. Limit the maximum numbers of days from the interpolating day that will be considered. So using e. g. a 3 will only consider images that are 3 days apart from the interpolation day. Default is 5.

output_pixelstate

(Optional) Logical. If "true" output the pixelstate. The pixelstates are 8 bit wide. Default is "false".

use_nodata

(Optional) Logical. If "true" nodata will be used as invalid range for masking. Default is "true".

interp_invalid

(Optional) Logical. Interpolate invalid locations? Default is "true".

prioritize_invalid

(Optional) Logical. When a pixel location is marked as invalid and as interpolate, handle as invalid location and do not interpolate. Default is "false".

interp_ranges

(Optional) Character (specifically a range-list, see below at <range-list>). Specify one or more intervals for values that should be interpolated. By default is empty.

no_interp_ranges

(Optional) Character (specifically a range-list, see below at <range-list>). Specify one or more intervals for values that should not be interpolated. No-interp-ranges can be excluded from interp-ranges. By default is empty.

valid_ranges

(Optional) Character (specifically a range-list, see below at <range-list>). Specify one or more intervals for valid values. Locations with invalid values will be masked out.

invalid_ranges

(Optional) Character (specifically a range-list, see below at <range-list>). Specify one or more intervals for invalid values. These will be masked out.

out_prefix

(Optional) Character. This string will be prepended to the output filenames and can also be used to specify an output filepath. By default, is set to an "Outputs" folder in the R temp directory (See tempdir).

out_postfix

(Optional) Character. This string will be appended to the output filenames. Default is "interpolated_".

out_pixelstate_prefix

(Optional, only used if output_pixelstate was set to "true".) Character. A string which will be prepended to the output filenames (including out_prefix and out_postfix).

out_pixelstate_postfix

(Optional, only used if output_pixelstate was set to "true".) Character. A string which will be appended to the output filenames (including out_prefix and out_postfix). Default is "ps_".

stats_filename

(Optional) Character, a filename. Enable stats (cloud pixels before and after, etc.) and output into the given file. By default, no stats will be output.

print_stats

(Optional) Logical. If no stats_filename was provided: Print stats to console instead? Default is "false".

ql_filenames

(Optional) A character vector of the filenames of the images use as quality layers. By default, no quality layer will be used.

ql_dates

(Optional, only used if any ql_filenames were provided.) An integer vector of the dates associated with the ql_filenames. Must match ql_filenames in length and order.

ql_tags

(Optional, only used if any ql_filenames were provided.) A character vector of the resolution tags associated with the ql_filenames.

ql_layers

(Optional, only used if any ql_filenames were provided.) A list of numeric vectors (see below at <num-list>). Specifies the channels or layers, that will be read. Hereby a 0 means the first channel. Should be either matching ql_filenames in length and order or be of length 1, in which case the selection will be applied to all ql_images.

ql_bits

(Optional, only used if any ql_filenames were provided.) A list of numeric (see below at <num-list>). Specifies the bits to use. The selected bits will be extracted. from the quality layer image and then shifted to the least significant positions. If unspecified, all bits will be used. Should be either matching ql_filenames in length and order or be of length 1, in which case the selection will be applied to all ql_images.

ql_interp_ranges

(Optional, only used if any ql_filenames were provided.) A list of character (specifically a list of range-lists, see below at <range-list>). Specifies the ranges of the shifted value that should mark the location for interpolation. Should be either matching ql_filenames in length and order or be of length 1, in which case the ranges will be applied to all ql_images.

ql_non_interp_ranges

(Optional, only used if any ql_filenames were provided.) A list of character (specifically a list of range-lists, see below at <range-list>). Specifies the ranges of the shifted value that should mark the location for interpolation. Should be either matching ql_filenames in length and order or be of length 1, in which case the ranges will be applied to all ql_images.

mask_filenames

(Optional) A character vector of the filenames of the images use as Mask image (8-bit, boolean, i. e. consists of 0 and 255). By default, no mask image will be used.

mask_layers

(Optional, only used if any mask_filenames were provided.) A list of numeric vectors(see below at <num-list>). Specifies the channels or layers, that will be read. Hereby a 0 means the first channel. Should be either matching mask_filenames in length and order or be of length 1, in which case the selection will be applied to all mask_images.Should be either matching mask_filenames in length and order or be of length 1, in which case the selection will be applied to all mask_images.

mask_bits

(Optional, only used if any mask_filenames were provided.) A list of numeric (see below at <num-list>). Specifies the bits to use. The selected bits will be sorted (so the order is irrelevant), extracted from the quality layer image and then shifted to the least significant positions. By default all bits will be used.

mask_valid_ranges

(Optional) A list of character (specifically a list of range-lists, see below at <range-list>). Specifies the ranges of the shifted value that should mark the location as valid (true; 255). Should be either matching mask_filenames in length and order or be of length 1, in which case the ranges will be applied to all ql_images.

mask_invalid_ranges

A list of character (specifically a list of range-lists, see below at <range-list>). Specifies the ranges of the shifted value that should mark the location as invalid (false; 0). Should be either matching mask_filenames in length and order or be of length 1, in which case the ranges will be applied to all ql_images.

verbose

(Optional) Logical. Output intermediate progress reports? Default is "true".

Value

Nothing, files are written to disk.

Details

This utility is developed to perform simple interpolation on a given time series of remote sensing images. This utility can also perform cloud masking on satellite images with the quality layer provided using ql options. The quality layer can be a bit field image (ex. State_1km: Reflectance Data State QA layer from MODIS) or state image which provides the state of the pixel (ex. quality layer from FMASK). When a single image with a date and a quality layer with the same date is provided, this utility will fill the cloud (or whatever is specified) locations with the nodata value and output the modified image. If multiple images with dates are provided with quality layers, this utility will try to interpolate the bad locations linearly. When there is not enough data, the non-interpolated locations will be set to the nodata value. Note, nodata locations will not be interpolated by default.

Pixelstates

Using output_pixelstate the pixelstates can be produces as an additional output. The pixelstates are 8 bit wide. bit 6 indicates that it was a location to interpolate before,bit 7 indicates that it is a clear pixel afterwards. This results in the following states (other bits are 0):

value b7 b6 meaning
0 0 0 Was nodata before and still is
64 0 1 Could not be interpolated and is set to nodata
192 1 1 Is interpolated

Specific Formats

Some arguments require inputs in a specific format.

  • starfm: STARFM stands for spatial and temporal adaptive reflectance fusion model. It requires a relatively low amount of computation time for prediction. Supports singlepair and doublepair modes. See starfm_job.

  • estarfm: ESTARFM stands for enhanced spatial and temporal adaptive reflectance fusion model so it claims to be an enhanced STARFM. It can yield better results in some situations. Only supports doublepair mode. See estarfm_job.

  • fitfc: Fit-FC is a three-step method consisting of regression model fitting (RM fitting), spatial filtering (SF) and residual compensation (RC). It requires a relatively low amount of computation time for prediction. Supports singlepair or a pseudo-doublepair mode(For predictions between two pair dates, predictions will be done twice, once for each of the pair dates). See fitfc_job. This is the default algorithm.

  • <num-list> must be lists of integer vectors. Example: list(c(1,3,3,7),c(4,2))

  • <range> must be strings. Either be a single number or have the format '[<float>,<float>]', '(<float>,<float>)', '[<float>,<float>' or '<float>,<float>]' where the comma and round brackets are optional, but square brackets are here actual characters. Especially for half-open intervals do not use unbalanced parentheses or escape them (maybe with two '\'). Additional whitespace can be added anywhere. Example: "(125,175)"

  • <range-list> must be strings that combine ranges in the form '<range> [<range> ...]', where the brackets mean that further intervals are optional. The different ranges are related as union. Example: "(125,175) [225,275]"

Examples

Run this code
# NOT RUN {
# Load required libraries
library(ImageFusion)
library(raster)
# Get filesnames of images with gaps
landsat_with_gaps <- list.files(system.file("landsat/unfilled",
                                            package = "ImageFusion"),
                                ".tif",
                                recursive = TRUE,
                                full.names = TRUE)
# Create output directory in temporary folder
out_dir <- paste0(tempdir(),"/Outputs/")
if(!dir.exists(out_dir)) dir.create(out_dir, recursive = TRUE)
# Interpolate into output directory
imginterp_task(filenames = landsat_with_gaps,
              dates = c(68,77,93,100),limit_days = 15,
               invalid_ranges = "[-inf,-1]",
               out_prefix = out_dir)
# Get filenames of interpolated images
landsat_without_gaps <- list.files(out_dir,pattern = ".tif$",full.names = TRUE)
# Count the number of NAs before and after the interpolation
sum(is.na(getValues(stack(landsat_with_gaps[2]))))
sum(is.na(getValues(stack(landsat_without_gaps[2]))))
# remove the output directory
unlink(out_dir,recursive = TRUE)


# }

Run the code above in your browser using DataLab