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)
#> [1] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_ANG.avgs"
#> [2] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_ANG.tif"
#> [3] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_LATLON.tif"
#> [4] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_SWIR.tif"
#> [5] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_SWIR.tif.aux.xml"
#> [6] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_SWIR.wvl"
#> [7] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.tif"
#> [8] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.wvl"
#> [9] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO.ang"
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
#> class : RasterBrick
#> dimensions : 1236, 1290, 1594440, 63 (nrow, ncol, ncell, nlayers)
#> resolution : 30, 30 (x, y)
#> extent : 443887.5, 482587.5, 5006652, 5043732 (xmin, xmax, ymin, ymax)
#> crs : +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs
#> source : /tmp/Rtmp7WLDRw/prismaread/L2D/PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.tif
#> names : PRS_L2D_S//HCO_VNIR.1, PRS_L2D_S//HCO_VNIR.2, PRS_L2D_S//HCO_VNIR.3, PRS_L2D_S//HCO_VNIR.4, PRS_L2D_S//HCO_VNIR.5, PRS_L2D_S//HCO_VNIR.6, PRS_L2D_S//HCO_VNIR.7, PRS_L2D_S//HCO_VNIR.8, PRS_L2D_S//HCO_VNIR.9, PRS_L2D_S//CO_VNIR.10, PRS_L2D_S//CO_VNIR.11, PRS_L2D_S//CO_VNIR.12, PRS_L2D_S//CO_VNIR.13, PRS_L2D_S//CO_VNIR.14, PRS_L2D_S//CO_VNIR.15, ...
#> min values : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
#> max values : 0.8022889, 0.8009613, 0.8152743, 0.8303044, 0.8362554, 0.8429389, 0.7138476, 0.7174029, 0.7369955, 0.7782254, 0.8017395, 0.8200198, 0.8605936, 0.8861524, 0.9261769, ...
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)
#> [1] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_ANG.avgs"
#> [2] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_ANG.tif"
#> [3] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_FULL.tif"
#> [4] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_FULL.wvl"
#> [5] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_LATLON.tif"
#> [6] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_SWIR.tif"
#> [7] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_SWIR.wvl"
#> [8] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.tif"
#> [9] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.wvl"
#> [10] "PRS_L2D_STD_20200524103704_20200524103708_0001_HCO.ang"
l2dsel_vnir <- raster::brick(
file.path(
l2d_out_dir,
"PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.tif"
)
)
l2dsel_vnir
#> class : RasterBrick
#> dimensions : 1236, 1290, 1594440, 3 (nrow, ncol, ncell, nlayers)
#> resolution : 30, 30 (x, y)
#> extent : 443887.5, 482587.5, 5006652, 5043732 (xmin, xmax, ymin, ymax)
#> crs : +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs
#> source : /tmp/Rtmp7WLDRw/prismaread/L2D/PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.tif
#> names : PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.1, PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.2, PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.3
#> min values : 0, 0, 0
#> max values : 0.7138476, 0.9993133, 0.9482872
l2dsel_swir <- raster::stack(
file.path(
l2d_out_dir,
"PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_SWIR.tif"
)
)
l2dsel_vnir
#> class : RasterBrick
#> dimensions : 1236, 1290, 1594440, 3 (nrow, ncol, ncell, nlayers)
#> resolution : 30, 30 (x, y)
#> extent : 443887.5, 482587.5, 5006652, 5043732 (xmin, xmax, ymin, ymax)
#> crs : +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs
#> source : /tmp/Rtmp7WLDRw/prismaread/L2D/PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.tif
#> names : PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.1, PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.2, PRS_L2D_STD_20200524103704_20200524103708_0001_HCO_VNIR.3
#> min values : 0, 0, 0
#> max values : 0.7138476, 0.9993133, 0.9482872