1
- # ' Convert a vertical profile (\code{vp}) to a Data Frame
1
+ # ' Convert a vertical profile (`vp`) or time series of vertical profiles
2
+ # ' (`vpts`) to a data frame
2
3
# '
3
- # ' Converts a vertical profile to a Data Frame, and optionally adds information
4
- # ' on sunrise/sunset, day/night and derived quantities like migration
5
- # ' traffic rates.
4
+ # ' Converts a vertical profile (`vp`) or a time series of vertical profiles
5
+ # ' (`vpts`) to a data frame containing all quantities per datetime and height.
6
+ # ' Has options to include latitude/longitude/antenna height (parameter `geo`)
7
+ # ' and day/sunrise/sunset (parameter `suntime`).
6
8
# '
7
- # ' @param x An object of class \code{vp} .
8
- # ' @param row.names \code{ NULL} or a character vector giving the row names for
9
+ # ' @param x A `vp` or `vpts` object .
10
+ # ' @param row.names ` NULL` or a character vector giving the row names for
9
11
# ' the data frame. Missing values are not allowed. See [base::as.data.frame()].
10
- # ' @param optional If \code{ FALSE} then the names of the variables in the data
12
+ # ' @param optional Logical. If ` FALSE` then the names of the variables in the data
11
13
# ' frame are checked to ensure that they are syntactically valid variable names
12
- # ' and are not duplicated.
13
- # ' @param quantities An optional character vector with the names of the
14
- # ' quantities to include as columns in the data frame.
15
- # ' @param elev Sun elevation in degrees, see \link{sunrise}/\link{sunset}.
16
- # ' @param lat Radar latitude in decimal degrees. When set, overrides the
17
- # ' latitude stored in \code{x} in \link{sunrise}/\link{sunset} calculations
18
- # ' @param lon Radar longitude in decimal degrees. When set, overrides the
19
- # ' longitude stored in \code{x} in \link{sunrise}/\link{sunset} calculations.
20
- # ' @param suntime Logical, when \code{TRUE}, adds sunrise/sunset and day/night
21
- # ' information to each row.
22
- # ' @param geo Logical, when \code{TRUE}, adds latitude, longitude and antenna
23
- # ' height of the radar to each row.
14
+ # ' and are not duplicated. See [base::as.data.frame()].
15
+ # ' @param geo Logical. When `TRUE`, adds latitude (`lat`), longitude (`lon`) and
16
+ # ' antenna height of the radar (`height_antenna`) to each row.
17
+ # ' @param suntime Logical. When `TRUE`, adds whether it is daytime (`day`) and
18
+ # ' the datetime of `sunrise` and `sunset` to each row.
19
+ # ' @param lat Numeric. Radar latitude in decimal degrees. When set, overrides
20
+ # ' the latitude stored in `x` for [sunrise()]/[sunset()] calculations.
21
+ # ' @param lon Numeric. Radar longitude in decimal degrees. When set, overrides
22
+ # ' the longitude stored in `x` for [sunrise()]/[sunset()] calculations.
23
+ # ' @param elev Numeric. Sun elevation in degrees, used for
24
+ # ' [sunrise()]/[sunset()] calculations.
24
25
# ' @param ... Additional arguments to be passed to or from methods.
25
26
# '
26
- # ' @return An object of class \code{ data.frame} .
27
+ # ' @return A ` data.frame` object .
27
28
# '
28
29
# ' @export
29
30
# '
30
31
# ' @details
31
- # ' Note that only the " dens" quantity is thresholded for radial velocity
32
- # ' standard deviation by \link{ sd_vvp_threshold}. Note that this is different from the
33
- # ' default \link{ plot.vp}, \link{ plot.vpts} and \link{ get_quantity.vp}
34
- # ' functions, where quantities " eta", " dbz", "ff", "u", "v", "w", "dd" are
35
- # ' all thresholded by \link{ sd_vvp_threshold}
32
+ # ' Note that only the ` dens` quantity is thresholded for radial velocity
33
+ # ' standard deviation by [ sd_vvp_threshold()]. This is different from the
34
+ # ' default [ plot.vp()], [ plot.vpts()] and [ get_quantity()] functions, where
35
+ # ' quantities ` eta`, ` dbz`, `ff`, `u`, `v`, `w`, `dd` are all thresholded by
36
+ # ' [ sd_vvp_threshold()].
36
37
# '
37
38
# ' @examples
38
39
# ' # Load the example vertical profile
44
45
# ' # Print data.frame
45
46
# ' vp_df
46
47
# '
47
- # ' # Do not compute sunrise/sunset information
48
- # ' vp_df <- as.data.frame(vp, suntime = FALSE)
48
+ # ' # Load the example time series of vertical profiles
49
+ # ' vpts <- example_vpts
50
+ # '
51
+ # ' # Convert to a data.frame
52
+ # ' vpts_df <- as.data.frame(vpts)
53
+ # '
54
+ # ' # Print the first 5 rows of the data.frame
55
+ # ' vpts_df[1:5, ]
56
+ # '
57
+ # ' # Do not add lat/lon/height_antenna information
58
+ # ' vpts_df <- as.data.frame(vpts, geo = FALSE)
59
+ # '
60
+ # ' # Do not add day/sunrise/sunset information
61
+ # ' vpts_df <- as.data.frame(vpts, suntime = FALSE)
49
62
# '
50
63
# ' # Override the latitude/longitude information stored in the object when
51
64
# ' # calculating sunrise/sunset information
52
- # ' vp_df <- as.data.frame(vp, suntime = TRUE, lat = 50, lon = 4)
53
- as.data.frame.vp <- function (x , row.names = NULL , optional = FALSE ,
54
- quantities = names(x $ data ), suntime = TRUE ,
55
- geo = TRUE , elev = - 0.268 , lat = NULL ,
56
- lon = NULL , ... ) {
65
+ # ' vpts_df <- as.data.frame(vpts, lat = 50, lon = 4)
66
+ as.data.frame.vp <- function (x , row.names = NULL , optional = FALSE , geo = TRUE ,
67
+ suntime = TRUE , lat = NULL , lon = NULL ,
68
+ elev = - 0.268 , ... ) {
57
69
stopifnot(inherits(x , " vp" ))
58
70
if (! is.null(row.names )) {
59
71
if (is.character(row.names ) & length(row.names ) ==
60
72
length(x $ datetime ) * length(x $ height )) {
61
73
rownames(output ) <- row.names
62
74
} else {
63
- stop(paste (
64
- " `row.names` is not a character vector of length" ,
65
- length(x $ datetime ) * length(x $ height )
75
+ stop(paste0 (
76
+ " `row.names` is not a character vector of length " ,
77
+ length(x $ datetime ) * length(x $ data $ height ), " . "
66
78
))
67
79
}
68
80
}
@@ -72,14 +84,6 @@ as.data.frame.vp <- function(x, row.names = NULL, optional = FALSE,
72
84
if (is.null(lon )) {
73
85
lon <- x $ attributes $ where $ lon
74
86
}
75
- missing <- which(! (quantities %in% names(x $ data )))
76
- if (length(missing ) > 0 ) {
77
- stop(paste(
78
- paste(quantities [missing ], collapse = " " ),
79
- " not an available quantity, select one or more of" ,
80
- paste(names(x $ data ), collapse = " ," )
81
- ))
82
- }
83
87
# coerce data to a data frame
84
88
output <- as.data.frame(x $ data , optional = optional , ... )
85
89
# add height and datetime as a column
@@ -93,7 +97,7 @@ as.data.frame.vp <- function(x, row.names = NULL, optional = FALSE,
93
97
output $ lon <- lon
94
98
output $ height_antenna <- x $ attributes $ where $ height
95
99
}
96
- # override the lat,lon attributes in case of user-provided values
100
+ # override the lat, lon attributes in case of user-provided values
97
101
x $ attributes $ where $ lat <- lat
98
102
x $ attributes $ where $ lon <- lon
99
103
# add day
@@ -115,71 +119,21 @@ as.data.frame.vp <- function(x, row.names = NULL, optional = FALSE,
115
119
output
116
120
}
117
121
118
- # ' Convert a time series of vertical profiles (\code{vpts}) to a data frame
119
- # '
120
- # ' Converts vertical profile time series (objects of class \code{vpts}) to a
121
- # ' data Frame, and optionally adds information on sunrise/sunset, day/night
122
- # ' and derived quantities like migration traffic rates.
123
- # '
124
- # ' @param x An object of class \code{vpts}.
125
- # ' @param row.names \code{NULL} or a character vector giving the row names for
126
- # ' the data frame. Missing values are not allowed.
127
- # ' @param optional If \code{FALSE} then the names of the variables in the data
128
- # ' frame are checked to ensure that they are syntactically valid variable names
129
- # ' and are not duplicated.
130
- # ' @param quantities An optional character vector with the names of the
131
- # ' quantities to include as columns in the data frame.
132
- # ' @param elev Sun elevation in degrees, see \link{sunrise}/\link{sunset}.
133
- # ' @param lat Radar latitude in decimal degrees. When set, overrides the
134
- # ' latitude stored in \code{x} in \link{sunrise}/\link{sunset} calculations.
135
- # ' @param lon Radar longitude in decimal degrees. When set, overrides the
136
- # ' longitude stored in \code{x} in \link{sunrise}/\link{sunset} calculations.
137
- # ' @param suntime Logical, when TRUE, adds sunrise/sunset and day/night
138
- # ' information to each row.
139
- # ' @param geo Logical, when TRUE, adds latitude, longitude and antenna height
140
- # ' of the radar to each row.
141
- # ' @param ... Additional arguments to be passed to or from methods.
142
- # '
143
- # ' @return An object of class data.frame.
122
+ # ' @rdname as.data.frame.vp
144
123
# '
145
124
# ' @export
146
- # '
147
- # ' @details
148
- # ' Note that only the 'dens' quantity is thresholded for radial velocity
149
- # ' standard deviation by \link{sd_vvp_threshold}. Note that this is different from the
150
- # ' default \link{plot.vp}, \link{plot.vpts} and \link{get_quantity.vp}
151
- # ' functions, where quantities "eta", "dbz", "ff", "u", "v", "w", "dd" are all
152
- # ' thresholded by \link{sd_vvp_threshold}.
153
- # '
154
- # ' @examples
155
- # ' # Load the example time series of vertical profiles
156
- # ' vpts <- example_vpts
157
- # '
158
- # ' # Convert to a data.frame
159
- # ' vpts_df <- as.data.frame(vpts)
160
- # '
161
- # ' # Print the first 10 rows of the data.frame
162
- # ' vpts_df[1:10, ]
163
- # '
164
- # ' # Do not compute sunrise/sunset information
165
- # ' vpts_df <- as.data.frame(vpts, suntime = FALSE)
166
- # '
167
- # ' # Override the latitude/longitude information stored in the object when
168
- # ' # calculating sunrise/sunset information
169
- # ' vpts_df <- as.data.frame(vpts, suntime = TRUE, lat = 50, lon = 4)
170
- as.data.frame.vpts <- function (x , row.names = NULL , optional = FALSE ,
171
- quantities = names(x $ data ), suntime = TRUE ,
172
- geo = TRUE , elev = - 0.268 , lat = NULL ,
173
- lon = NULL , ... ) {
125
+ as.data.frame.vpts <- function (x , row.names = NULL , optional = FALSE , geo = TRUE ,
126
+ suntime = TRUE , lat = NULL , lon = NULL ,
127
+ elev = - 0.268 , ... ) {
174
128
stopifnot(inherits(x , " vpts" ))
175
129
if (! is.null(row.names )) {
176
130
if (is.character(row.names ) & length(row.names ) ==
177
131
length(x $ datetime ) * length(x $ height )) {
178
132
rownames(output ) <- row.names
179
133
} else {
180
- stop(paste (
181
- " ' row.names' is not a character vector of length" ,
182
- length(x $ datetime ) * length(x $ height )
134
+ stop(paste0 (
135
+ " ` row.names` is not a character vector of length " ,
136
+ length(x $ datetime ) * length(x $ height ), " . "
183
137
))
184
138
}
185
139
}
@@ -189,16 +143,8 @@ as.data.frame.vpts <- function(x, row.names = NULL, optional = FALSE,
189
143
if (is.null(lon )) {
190
144
lon <- x $ attributes $ where $ lon
191
145
}
192
- missing <- which(! (quantities %in% names(x $ data )))
193
- if (length(missing ) > 0 ) {
194
- stop(paste(
195
- paste(quantities [missing ], collapse = " " ),
196
- " not an available quantity, select one or more of" ,
197
- paste(names(x $ data ), collapse = " ," )
198
- ))
199
- }
200
146
# coerce data to a data frame
201
- output <- as.data.frame(lapply(x $ data [ quantities ] , c ),
147
+ output <- as.data.frame(lapply(x $ data , c ),
202
148
optional = optional , ...
203
149
)
204
150
# add height and datetime as a column
@@ -217,7 +163,7 @@ as.data.frame.vpts <- function(x, row.names = NULL, optional = FALSE,
217
163
output $ lon <- lon
218
164
output $ height_antenna <- x $ attributes $ where $ height
219
165
}
220
- # override the lat,lon attributes in case of user-provided values
166
+ # override the lat, lon attributes in case of user-provided values
221
167
x $ attributes $ where $ lat <- lat
222
168
x $ attributes $ where $ lon <- lon
223
169
# add day
0 commit comments