# \donttest{
# Locate and read the polar volume example file
pvolfile <- system.file("extdata", "volume.h5", package = "bioRad")
# load polar volume
pvol <- read_pvolfile(pvolfile)
# Read the corresponding vertical profile example
data(example_vp)
# Calculate the range-corrected ppi on a 50x50 pixel raster
ppi <- integrate_to_ppi(pvol, example_vp, nx = 50, ny = 50)
# Plot the vertically integrated reflectivity (VIR) using a
# 0-2000 cm^2/km^2 color scale
plot(ppi, zlim = c(0, 2000))
# Calculate the range-corrected ppi on finer 2000m x 2000m pixel raster
ppi <- integrate_to_ppi(pvol, example_vp, res = 2000)
# Plot the vertically integrated density (VID) using a
# 0-200 birds/km^2 color scale
plot(ppi, param = "VID", zlim = c(0, 200))
# Download a basemap and map the ppi
if (all(sapply(c("ggspatial","prettymapr", "rosm"), requireNamespace, quietly = TRUE))) {
map(ppi)
# First define the raster
template_raster <- raster::raster(
raster::extent(12, 13, 56, 57),
crs = sp::CRS("+proj=longlat")
)
# Project the ppi on the defined raster
ppi <- integrate_to_ppi(pvol, example_vp, raster = template_raster)
# Extract the raster data from the ppi object
raster::brick(ppi$data)
# Calculate the range-corrected ppi on an even finer 500m x 500m pixel raster,
# cropping the area up to 50000 meter from the radar
ppi <- integrate_to_ppi(
pvol, example_vp, res = 500,
xlim = c(-50000, 50000), ylim = c(-50000, 50000)
)
plot(ppi, param = "VID", zlim = c(0, 200))
# To calculate a range-corrected map assuming a constant altitude
# profile maintained relative to ground height:
if(requireNamespace("elevatr", quietly = TRUE)){
# define a radar-centred grid (azimuthal equidistant, radar at the center):
pvol |>
get_scan(.5) |>
scan_to_raster(param = "DBZH") |>
terra::rast() -> radar_grid
# download elevation data and resample onto that grid. `expand`
# over-requests so the full grid is covered;
data_dem <- terra::project(
terra::rast(elevatr::get_elev_raster(radar_grid, z = 5, expand = 100000)), radar_grid)
# set heights below sea level to zero.
data_dem[data_dem < 0] <- 0
# add an informative name
names(data_dem) <- "HGHT"
# add DEM data to the polar volume:
pvol_ground <- add_param(pvol, data_dem, "HGHT")
# compute a profile relative to ground:
vp_ground <- calculate_vp(pvol_ground, n_layer = 60, h_layer = 50, height_reference = "ground")
# apply the range correction:
ppi_ground <- integrate_to_ppi(pvol_ground, vp_ground, height_reference = "ground",
raster = data_dem)
}
}
# }
Run the code above in your browser using DataLab