Either create file path for saving a cube or parse the meta data from a cube

name_env_tif(
  x,
  dir_only = FALSE,
  skips = c("base"),
  prefixes = c("sat", "use"),
  file_type = c("\\.tif", "\\.nc"),
  parse = FALSE,
  fill_null = FALSE,
  x_null = 3,
  ...,
  context_defn = c("polygons", "filt_col", "level", "buffer"),
  cube_defn = c("period", "res"),
  source_defn = c("source", "collection"),
  layer_defn = c("layer", "start_date", "file_type"),
  make_name = TRUE
)

Arguments

x

Either dataframe with path(s) to parse (in column path), character vector of path(s) to search, or named list.

dir_only

Logical. Are full file paths provided (or required) or just a directory?

skips

Character. When parsing, skip (filter) any files with a match to skips

prefixes

Character. If x is a named list, any name prefixes to remove before matching to naming structure.

file_type

Character. e.g. "tif". More than one can be provided but if parse then file_type[1] is used for out_file file type.

parse

Logical. If FALSE an out_file path will be returned rather than parsed. Assumes the appropriately names columns are supplied in df.

fill_null

Logical. If TRUE, will fill up to x_null definitions with NULL (and issue a warning).

x_null

Numeric. Even if fill_null is TRUE, if there are more than x_null missing definitions, an error will be thrown.

make_name

Logical. If TRUE a column 'name' will be added to the output in a format suitable for use in model formulas.

Value

If !parse, tibble with (default) columns:

polygons

Vector layer originally used to define area of interest

filt_col

Column name from vector to filter to define area of interest

level

Level(s) of filt_col originally filtered to define area of interest

buffer

Any buffer around area of interest

period

Period represented within layer using ISO8601-compliant time period for regular data cubes. e.g., "P16D" for 16 days

res

Resolution of output raster in units of rasters crs

source

e.g. DEA is digital earth Austrlia

collection

e.g. ga_ls8c_ard_3 is landsat 8 collection in DEA

layer

Band or layer name

start_date

Start date for layer

file_type

File type of path.

path

Full (relative) path including file_type.

name

A name that should be safe to use in model formulas: paste0(layer, "__", gsub("-", "",start_date))

If !parse, df with additional column out_file

Examples


  #library(envRaster)

  out_dir <- file.path(system.file(package = "envRaster"), "examples")

  cube_dir <- fs::path(out_dir, "cube")

  settings <- list()

  # cube setup
  ## geographic extent
  settings$polygons <- "aoi"
  settings$filt_col <- NULL
  settings$level <- NULL
  settings$buffer <- 0
  # can be used in envFunc::make_aoi

  ## grain size
  settings$period <- "P3M"
  settings$sat_res <- 90

  ## source
  settings$source <- "DEA"
  settings$collection <- c("ga_ls9c_ard_3", "ga_ls8c_ard_3")

  ## directory
  settings$out_dir <- fs::path(cube_dir
                               , name_env_tif(settings
                                              , fill_null = TRUE
                                              , dir_only = TRUE
                                              )$out_dir
                               )
#> Warning: All of filt_col and level will be NULL

  fs::dir_create(settings$out_dir)

  # save settings
  rio::export(settings
              , fs::path(cube_dir, "settings.rds")
              )

  # go and make cube. e.g. examples in ?get_sat_data()
  tifs <- length(fs::dir_ls(settings$out_dir, regexp = "tif$"))

  if(!tifs) {

    source(fs::path(out_dir, "get_sat_data_ex.R"))

  }

  name_env_tif(settings$out_dir
               , parse = TRUE
               )
#> # A tibble: 4 × 13
#>   polygons filt_col level buffer period res   source collection layer start_date
#>   <chr>    <chr>    <chr> <chr>  <chr>  <chr> <chr>  <chr>      <chr> <chr>     
#> 1 aoi      ""       ""    0      P3M    90    DEA    ga_ls9c_a… ndvi  2022-12-01
#> 2 aoi      ""       ""    0      P3M    90    DEA    ga_ls9c_a… ndvi  2023-03-01
#> 3 aoi      ""       ""    0      P3M    90    DEA    ga_ls9c_a… ndvi  2023-06-01
#> 4 aoi      ""       ""    0      P3M    90    DEA    ga_ls9c_a… ndvi  2023-09-01
#> # ℹ 3 more variables: file_type <chr>, name <chr>, path <chr>