2222# ' @import terra ncdf4
2323# ' @importFrom utils menu
2424# '
25+ # ' @examples
26+ # ' file <- paste0(system.file("extdata",package="eva3dm"),"/wrf_column_o3_Boston.nc")
27+ # ' O3_column <- calculate_column(file,'o3', verbose = TRUE)
28+ # '
2529# ' @export
2630# '
2731
@@ -67,13 +71,13 @@ calculate_column <- function(file = file.choose(),
6771 for (i in 1 : (dim(Z )[3 ]- 1 )){
6872 dz [,,i ] = Z [,,i + 1 ] - Z [,,i ]
6973 }
70- }else if (length(dim(Z )) == 4 ){ # this is a version for 4d (XYZT)
71- dz <- array (0 ,c(dim(Z )[1 ],dim(Z )[2 ],dim(Z )[3 ]- 1 ,dim(Z )[4 ]))
72- for (i in 1 : (dim(Z )[3 ]- 1 )){
73- dz [,,i ,] = Z [,,i + 1 ,] - Z [,,i ,]
74+ }else if (length(dim(Z )) == 4 ){ # this is a version for 4d (XYZT) # nocov
75+ dz <- array (0 ,c(dim(Z )[1 ],dim(Z )[2 ],dim(Z )[3 ]- 1 ,dim(Z )[4 ])) # nocov
76+ for (i in 1 : (dim(Z )[3 ]- 1 )){ # nocov
77+ dz [,,i ,] = Z [,,i + 1 ,] - Z [,,i ,] # nocov
7478 }
7579 }else {
76- stop(' dimention not suported' )
80+ stop(' dimention not suported' ) # nocov
7781 }
7882 return (dz )
7983 }
@@ -86,10 +90,10 @@ calculate_column <- function(file = file.choose(),
8690 }
8791
8892 f4 <- function (x ){
89- x <- as.array(x )
90- x <- aperm(x , c(2 ,1 ,3 ,4 ))
91- x <- x [rev(seq_len(dim(x )[1 ])),,,]
92- return (x )
93+ x <- as.array(x ) # nocov
94+ x <- aperm(x , c(2 ,1 ,3 ,4 )) # nocov
95+ x <- x [rev(seq_len(dim(x )[1 ])),,,] # nocov
96+ return (x ) # nocov
9397 }
9498
9599 avo = 6.02E+23 # Avogadro s number
@@ -112,17 +116,17 @@ calculate_column <- function(file = file.choose(),
112116 flip_h = flip_v ,
113117 verbose = verbose , ... )
114118 VAR <- rast_to_netcdf(r )
115- }else if (length(dim(Temp )) == 4 ){
116- sds <- wrf_sds(file = file ,
117- name = name ,
118- flip_v = flip_v ,
119- flip_h = flip_v ,
120- verbose = verbose , ... )
121- VAR <- f4(sds )
122- }else if (length(dim(Temp )) < = 2 ){
123- stop(' insuficient meteorological input' ) # less data than needed / include more data
119+ }else if (length(dim(Temp )) == 4 ){ # nocov
120+ sds <- wrf_sds(file = file , # nocov
121+ name = name , # nocov
122+ flip_v = flip_v , # nocov
123+ flip_h = flip_v , # nocov
124+ verbose = verbose , ... ) # nocov
125+ VAR <- f4(sds ) # nocov
126+ }else if (length(dim(Temp )) < = 2 ){ # nocov
127+ stop(' insuficient meteorological input' ) # less data than needed / include more data # nocov
124128 }else {
125- stop(' meteorological input not suported' ) # dimension not supported / reduce data
129+ stop(' meteorological input not suported' ) # dimension not supported / reduce data # nocov
126130 }
127131
128132 P <- P1 + P2 # total pressure [pa]
@@ -138,26 +142,26 @@ calculate_column <- function(file = file.choose(),
138142 names(r ) <- paste0(name ,' _column' )
139143 time(r ) <- times_r [1 ]
140144 }
141- if (length(dim(VAR )) == 4 ){ # XLAT XLONG LEVEL TIME
142- times_r <- time(sds [,1 ])
143- make_rast <- function (i = 1 , x = sds ){
144- r <- sds [[i ,]]
145- r [] <- c(f3(VAR [,,,i ],1 ))
146- r <- sum(r , na.rm = TRUE )
147- names(r ) <- paste0(name ,' _column' )
148- return (r )
149- }
150- r_list <- lapply(X = 1 : length(times_r ),FUN = make_rast )
151- r <- terra :: rast(r_list )
152- time(r ) <- times_r
145+ if (length(dim(VAR )) == 4 ){ # XLAT XLONG LEVEL TIME # nocov
146+ times_r <- time(sds [,1 ]) # nocov
147+ make_rast <- function (i = 1 , x = sds ){ # nocov
148+ r <- sds [[i ,]] # nocov
149+ r [] <- c(f3(VAR [,,,i ],1 )) # nocov
150+ r <- sum(r , na.rm = TRUE ) # nocov
151+ names(r ) <- paste0(name ,' _column' ) # nocov
152+ return (r ) # nocov
153+ } # nocov
154+ r_list <- lapply(X = 1 : length(times_r ),FUN = make_rast ) # nocov
155+ r <- terra :: rast(r_list ) # nocov
156+ time(r ) <- times_r # nocov
153157 }
154158
155159 if (DU ){
156160 du = 2.687E+16 # Conversion constant: molecules cm-2 to DU
157161 r <- r / du
158162 units(r ) <- ' DU'
159163 }else {
160- units(r ) <- ' molecules cm-2'
164+ units(r ) <- ' molecules cm-2' # nocov
161165 }
162166 return (r )
163167}
0 commit comments