knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(prismaread)
The function to be used to import PRISMA L2 data (2B, 2C, 2D) is pr_convert
.
It takes as input the full path of a PRISMA L1 hdf5 image, an output folder name and format, and a series of switches allowing to decide which hyperspectral cubes and ancillary datasets should be crated.
In particular:
VNIR
and SWIR
logical arguments allow deciding if importing the VNIR and SWIR hyperspectral cubes; FULL
logical argument allows deciding if a complete VNIR+SWIR cube has to be created.In that case (FULL = TRUE
):
- the join_priority
keyword is used to decide if keeping bands from the "VNIR"
or the "SWIR" data cube in the wavelengths' region where they overlap;
- the PAN
, LATLON
and ANGLES
logical arguments
allow deciding which of the corresponding ancillary datasets should be created
(see the PRISMA manual for additional info);
- if working with L2B or L2C data,
the base_georef
logical argument allows deciding if a "base" georeferencing
in Lat/Lon WGS-84 based on the "GLT and Bowtie Correction" technique used
in ENVI and described here
is applied (if set to FALSE
, the original 1000 x 1000 datasets are
returned -- flipped to orient them "north/south" -- without projection.
If working with L2D, the output datasets are already georeferenced
(UTM projection), although accuracy of geolocation should be checked.
For example the following code accesses the input L2D file and saves the VNIR
and SWIR cubes and the PAN, ANGLES and CLOUD datasets.
See documentation of the pr_convert()
function
for info on available arguments.
IMPORTANT NOTE: to run this, you'd need to download the example data from
GitHub.
The data is about 1 GB, so it could take some time.
The data would be placed in subfolder testdata of the {prismaread}
installation folder.
l2d_he5_path <- file.path( system.file("testdata", package = "prismaread"), "PRS_L2D_STD_20200524103704_20200524103708_0001.he5" ) # Download and unzip using piggyback if necessary if (!file.exists(l2d_he5_path)) { message("Downloading test data - this may need a long time...") if (!requireNamespace("piggyback", quietly = TRUE)) { install.packages("piggyback") } l2d_zip_path <- file.path( system.file("testdata", package = "prismaread"), "PRS_L2D_STD_20200524103704_20200524103708_0001.zip" ) piggyback::pb_download( "PRS_L2D_STD_20200524103704_20200524103708_0001.zip", repo = "irea-cnr-mi/prismaread", dest = dirname(l2d_zip_path) ) piggyback::pb_track(glob = "inst/testdata/*.zip, inst/testdata/*.he5") unzip(l2d_zip_path, exdir = dirname(l2d_he5_path)) unlink(l2d_zip_path) } l2d_out_dir <- file.path(tempdir(), "prismaread/L2D") dir.create(dirname(l2d_out_dir), showWarnings = FALSE) # Save a full image, prioritising the VNIR spectrometer and save in ENVI format pr_convert( in_file = l2d_he5_path, out_folder = l2d_out_dir, out_format = "GTiff", VNIR = TRUE, SWIR = TRUE, LATLON = TRUE, ANGLES = TRUE )
Output files are saved in out_folder
according to conventions described
here and can then be accessed,
visualised and processed using standard R
syntax (e.g., with raster
or stars
).
list.files(l2d_out_dir) l2d_vnir_path <- file.path( l2d_out_dir, "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.tif" ) l2d_vnir <- raster::brick(l2d_vnir_path) l2d_vnir mapview::viewRGB(l2d_vnir, 40,30,20)
The function also saves in text files ancillary data related to: 1. wavelengths and fwhms of the different images: 2. hour and sun geometry at acquisition.
l2d_vnir_wvl <- read.table( file.path( l2d_out_dir, "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.wvl" ), header = TRUE ) DT::datatable(l2d_vnir_wvl)
The following code accesses the input file and saves the VNIR and SWIR cubes,
as well as a full hyperspectral cube and the ANGLES and LATLON datasets.
See pr_convert()
documentation for info on
available arguments.
# Save a full image, prioritising the SWIR spectrometer (default) # and saves in ENVI format. pr_convert( in_file = l2d_he5_path, out_folder = l2d_out_dir, out_format = "ENVI", VNIR = TRUE, SWIR = TRUE, FULL = TRUE, LATLON = TRUE, ANGLES = TRUE )
The selbands_vnir
and selbands_swir
arguments allow selecting only a specified subset of
PRISMA bands, by specifying an array of required wavelengths. For example, the following code
will create a 3-band VNIR cube, a 2-band SWIR and a 5-band FULL dataset, by selecting the
original PRISMA bands with wavelengths closer to the requested ones.
pr_convert( in_file = l2d_he5_path, out_folder = l2d_out_dir, out_format = "GTiff", VNIR = TRUE, SWIR = TRUE, selbands_vnir = c(450,550,650), selbands_swir = c(1000,1330), join_priority = "SWIR", FULL = TRUE, overwrite = T ) list.files(l2d_out_dir) l2dsel_vnir <- raster::brick( file.path( l2d_out_dir, "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.tif" ) ) l2dsel_vnir l2dsel_swir <- raster::stack( file.path( l2d_out_dir, "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_SWIR.tif" ) ) l2dsel_vnir
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.