read_caim_raw: Read a canopy image from a raw file

View source: R/read_caim_raw.R

read_caim_rawR Documentation

Read a canopy image from a raw file

Description

Read unprocessed sensor data from a camera RAW file and split the signal by spectral band according to the in-camera color filter array (CFA). Use this to obtain images with precise radiometry.

Usage

read_caim_raw(path, only_blue = FALSE, offset_value = NULL)

Arguments

path

character vector of length one. Path to a file with raw data (including file extension).

only_blue

logical vector of length one. If TRUE, return only the blue/cyan band.

offset_value

numeric vector of length one. Optional black level offsets to replace black_level_per_channel metadata obtained with rawpy.

Details

Uses Python rawpy through reticulate to access sensor data and black-level metadata. Optionally extracts only the blue/cyan band.

Value

Numeric terra::SpatRaster:

  • single-layer if only_blue = TRUE.

  • multi-layer if only_blue = FALSE, with one layer per color per CFA color (e.g., R, G, B).

Layers are named according to metadata in the raw file.

Check Python Accessibility

To ensure that R can access a Python installation, run the following test:

reticulate::py_eval("1+1")

If R can access Python successfully, you will see 2 in the console. If not, you will receive instructions on how to install Python.

Create a Virtual Environment

After passing the Python accessibility test, create a virtual environment using the following command:

reticulate::virtualenv_create()

Install rawpy

Install the rawpy package within the virtual environment:

reticulate::py_install("rawpy")

For RStudio Users

If you are an RStudio user who works with projects, you will need a .Renviron file in the root of each project. To create a .Renviron file, follow these steps:

  • Create a "New Blank File" named ".Renviron" (without an extension) in the project's root directory.

  • Run bellow code:

path <- file.path(reticulate::virtualenv_root(),
reticulate::virtualenv_list(), "Scripts", "python.exe")
paste("RETICULATE_PYTHON =", path)

  • Copy/paste the line from the console (the string between the quotes) into the .Renviron file. This is an example ⁠RETICULATE_PYTHON = ~/.virtualenvs/r-reticulate/Scripts/python.exe⁠

  • Do not forget to save the changes

By following these steps, users can easily set up their environment to access raw data efficiently, but it is not the only way of doing it, you might know an easier or better one.

See the help page of read_caim() and fisheye_to_equidistant() as a complement to this help page. Further details about raw files can be found in \insertCiteDiaz2024;textualrcaiman.

References

\insertAllCited

See Also

read_caim()

Examples

## Not run: 
file_name <- tempfile(fileext = ".NEF")
download.file("https://osf.io/s49py/download", file_name, mode = "wb")

# Geometric and radiometric corrections -----------------------------------
zenith_colrow <- c(1290, 988)/2
diameter <- 756
z <- zenith_image(diameter, lens("Nikon_FCE9"))
a <- azimuth_image(z)
m <- !is.na(z)
caim <- read_caim_raw(file_name, only_blue = TRUE)
caim <- crop_caim(caim, zenith_colrow - diameter/2, diameter, diameter)
caim <- correct_vignetting(caim, z, c(0.0638, -0.101))
caim <- fisheye_to_equidistant(caim, z, a, m, radius = 300,
                               k = 1, p = 1, rmax = 100)

## End(Not run)

rcaiman documentation built on Sept. 9, 2025, 5:42 p.m.