Skip to content
Permalink
Browse files

faster implementation of project_as_ppi()

  • Loading branch information
adokter committed Apr 2, 2019
1 parent 6d13305 commit e420e5de9d5a6889104d3229f21950a81fd3c82d
Showing with 27 additions and 12 deletions.
  1. +24 −12 R/project_as_ppi.R
  2. +3 −0 man/project_as_corrected_ppi.Rd
@@ -98,9 +98,9 @@ project_as_ppi.scan <- function(x, grid_size = 500, range_max = 50000,
sample_polar <- function(param, grid_size, range_max, project, ylim, xlim) {
# proj4string=CRS(paste("+proj=aeqd +lat_0=",attributes(param)$geo$lat," +lon_0=",attributes(param)$geo$lon," +ellps=WGS84 +datum=WGS84 +units=m +no_defs",sep=""))
proj4string <- CRS(paste("+proj=aeqd +lat_0=", attributes(param)$geo$lat,
" +lon_0=", attributes(param)$geo$lon,
" +units=m",
sep = ""
" +lon_0=", attributes(param)$geo$lon,
" +units=m",
sep = ""
))
bboxlatlon <- proj_to_wgs(
c(-range_max, range_max),
@@ -124,9 +124,9 @@ sample_polar <- function(param, grid_size, range_max, project, ylim, xlim) {
)
cells.dim <- c(
ceiling((max(bbox@coords[, "x"]) -
min(bbox@coords[, "x"])) / grid_size),
min(bbox@coords[, "x"])) / grid_size),
ceiling((max(bbox@coords[, "y"]) -
min(bbox@coords[, "y"])) / grid_size)
min(bbox@coords[, "y"])) / grid_size)
)
}
# define cartesian grid
@@ -138,18 +138,29 @@ sample_polar <- function(param, grid_size, range_max, project, ylim, xlim) {
elev <- 0
}
# get scan parameter indices, and extract data
# TODO: not all arguments present for cartesion_to_polar
index <- polar_to_index(
cartesian_to_polar(coordinates(gridTopo), elev),
attributes(param)$geo$rscale,
attributes(param)$geo$ascale
)
data <- data.frame(mapply(
function(x, y) {
safe_subset(param, x, y)
},
x = index$row,
y = index$col
))
# set indices outside the scan's matrix to NA
nrang <- dim(param)[1]
nazim <- dim(param)[2]
index$row[index$row>nrang]=NA
index$col[index$col>nazim]=NA
# convert 2D index to 1D index
index=(index$col-1)*nrang+index$row
data=as.data.frame(param[index])

# data <- data.frame(mapply(
# function(x, y) {
# safe_subset(param, x, y)
# },
# x = index$row,
# y = index$col
# ))

colnames(data) <- attributes(param)$param
output <- SpatialGridDataFrame(
grid = SpatialGrid(
@@ -162,6 +173,7 @@ sample_polar <- function(param, grid_size, range_max, project, ylim, xlim) {
output
}


#' A wrapper for \code{\link{spTransform}}.
#'
#' @param lon Longitude

Some generated files are not rendered by default. Learn more.

0 comments on commit e420e5d

Please sign in to comment.
You can’t perform that action at this time.