Skip to content

Commit e420e5d

Browse files
committed
faster implementation of project_as_ppi()
1 parent 6d13305 commit e420e5d

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

R/project_as_ppi.R

+24-12
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ project_as_ppi.scan <- function(x, grid_size = 500, range_max = 50000,
9898
sample_polar <- function(param, grid_size, range_max, project, ylim, xlim) {
9999
# 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=""))
100100
proj4string <- CRS(paste("+proj=aeqd +lat_0=", attributes(param)$geo$lat,
101-
" +lon_0=", attributes(param)$geo$lon,
102-
" +units=m",
103-
sep = ""
101+
" +lon_0=", attributes(param)$geo$lon,
102+
" +units=m",
103+
sep = ""
104104
))
105105
bboxlatlon <- proj_to_wgs(
106106
c(-range_max, range_max),
@@ -124,9 +124,9 @@ sample_polar <- function(param, grid_size, range_max, project, ylim, xlim) {
124124
)
125125
cells.dim <- c(
126126
ceiling((max(bbox@coords[, "x"]) -
127-
min(bbox@coords[, "x"])) / grid_size),
127+
min(bbox@coords[, "x"])) / grid_size),
128128
ceiling((max(bbox@coords[, "y"]) -
129-
min(bbox@coords[, "y"])) / grid_size)
129+
min(bbox@coords[, "y"])) / grid_size)
130130
)
131131
}
132132
# define cartesian grid
@@ -138,18 +138,29 @@ sample_polar <- function(param, grid_size, range_max, project, ylim, xlim) {
138138
elev <- 0
139139
}
140140
# get scan parameter indices, and extract data
141+
# TODO: not all arguments present for cartesion_to_polar
141142
index <- polar_to_index(
142143
cartesian_to_polar(coordinates(gridTopo), elev),
143144
attributes(param)$geo$rscale,
144145
attributes(param)$geo$ascale
145146
)
146-
data <- data.frame(mapply(
147-
function(x, y) {
148-
safe_subset(param, x, y)
149-
},
150-
x = index$row,
151-
y = index$col
152-
))
147+
# set indices outside the scan's matrix to NA
148+
nrang <- dim(param)[1]
149+
nazim <- dim(param)[2]
150+
index$row[index$row>nrang]=NA
151+
index$col[index$col>nazim]=NA
152+
# convert 2D index to 1D index
153+
index=(index$col-1)*nrang+index$row
154+
data=as.data.frame(param[index])
155+
156+
# data <- data.frame(mapply(
157+
# function(x, y) {
158+
# safe_subset(param, x, y)
159+
# },
160+
# x = index$row,
161+
# y = index$col
162+
# ))
163+
153164
colnames(data) <- attributes(param)$param
154165
output <- SpatialGridDataFrame(
155166
grid = SpatialGrid(
@@ -162,6 +173,7 @@ sample_polar <- function(param, grid_size, range_max, project, ylim, xlim) {
162173
output
163174
}
164175

176+
165177
#' A wrapper for \code{\link{spTransform}}.
166178
#'
167179
#' @param lon Longitude

man/project_as_corrected_ppi.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)