@@ -98,9 +98,9 @@ project_as_ppi.scan <- function(x, grid_size = 500, range_max = 50000,
98
98
sample_polar <- function (param , grid_size , range_max , project , ylim , xlim ) {
99
99
# 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=""))
100
100
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 = " "
104
104
))
105
105
bboxlatlon <- proj_to_wgs(
106
106
c(- range_max , range_max ),
@@ -124,9 +124,9 @@ sample_polar <- function(param, grid_size, range_max, project, ylim, xlim) {
124
124
)
125
125
cells.dim <- c(
126
126
ceiling((max(bbox @ coords [, " x" ]) -
127
- min(bbox @ coords [, " x" ])) / grid_size ),
127
+ min(bbox @ coords [, " x" ])) / grid_size ),
128
128
ceiling((max(bbox @ coords [, " y" ]) -
129
- min(bbox @ coords [, " y" ])) / grid_size )
129
+ min(bbox @ coords [, " y" ])) / grid_size )
130
130
)
131
131
}
132
132
# define cartesian grid
@@ -138,18 +138,29 @@ sample_polar <- function(param, grid_size, range_max, project, ylim, xlim) {
138
138
elev <- 0
139
139
}
140
140
# get scan parameter indices, and extract data
141
+ # TODO: not all arguments present for cartesion_to_polar
141
142
index <- polar_to_index(
142
143
cartesian_to_polar(coordinates(gridTopo ), elev ),
143
144
attributes(param )$ geo $ rscale ,
144
145
attributes(param )$ geo $ ascale
145
146
)
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
+
153
164
colnames(data ) <- attributes(param )$ param
154
165
output <- SpatialGridDataFrame(
155
166
grid = SpatialGrid(
@@ -162,6 +173,7 @@ sample_polar <- function(param, grid_size, range_max, project, ylim, xlim) {
162
173
output
163
174
}
164
175
176
+
165
177
# ' A wrapper for \code{\link{spTransform}}.
166
178
# '
167
179
# ' @param lon Longitude
0 commit comments