Skip to content

Commit 61accbd

Browse files
author
cas
committed
Arrange assert statments in wrapper function to speed up calculation of wbgt.Liljegren
1 parent 24c6af4 commit 61accbd

File tree

16 files changed

+27
-77
lines changed

16 files changed

+27
-77
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: HeatStress
22
Type: Package
33
Title: Calculate heat stress indices
4-
Version: 1.0.4
4+
Version: 1.0.5
55
Date: 2017-03-03
66
Author: A. Casanueva
77
Maintainer: A.Casanueva <ana.casanueva@meteoswiss.ch>
@@ -12,3 +12,4 @@ Depends: R (>= 2.10.0)
1212
Suggests: testthat, assertthat
1313
Imports: stats
1414
Encoding: ISO-8859-1
15+

NEWS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ Changes in version 1.0.3
1212
* Change the interval to estimate Tg in `wbgt.Liljegren`.
1313

1414
Changes in version 1.0.4
15-
* Inclusion of more heat indices.
15+
* Inclusion of more heat indices.
16+
17+
Changes in version 1.0.5
18+
* Arrange assert statments in wrapper function to speed up calculation of wbgt.Liljegren.

R/calZenith.R

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
#'
2020
calZenith <- function(dates,lon,lat, hour=FALSE){
2121

22-
# assertion statements
23-
assertthat::assert_that(is.numeric(lon), msg="'lon' is not an integer")
24-
assertthat::assert_that(is.numeric(lat), msg="'lat' is not an integer")
25-
assertthat::assert_that(is.logical(hour), msg="'hour' should be logical")
26-
assertthat::assert_that(lon <= 180 & lon >=-180, msg="Invalid lon")
27-
assertthat::assert_that(lat <= 90 & lon >=-90, msg="Invalid lat")
28-
2922
# Internal constants used for conversion
3023
EQTIME1 <- 229.18
3124
EQTIME2 <- 0.000075

R/degToRad.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
degToRad <- function(angleDeg){
1212

13-
# assertion statements
14-
assertthat::assert_that(is.numeric(angleDeg), msg="'angleDeg' is not an integer")
15-
1613
degToRad <- pi * angleDeg / 180
1714
return(degToRad)
1815
}

R/diffusivity.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212

1313
diffusivity <- function(Tk, Pair){
1414

15-
# assertion statements
16-
assertthat::assert_that(is.numeric(Tk), msg="'Tk' is not an integer")
17-
assertthat::assert_that(Tk > 200, msg="'Tk' should be in Kelvin")
18-
assertthat::assert_that(is.numeric(Pair), msg="'Pair' is not an integer")
19-
2015
pcrit13 <- (36.4 * 218) ^ (1 / 3)
2116
tcrit512 <- (132 * 647.3) ^ (5 / 12)
2217
Tcrit12 <- (132 * 647.3) ^ 0.5

R/emis_atm.R

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313

1414
emis_atm <- function(Tk, RH){
1515

16-
# assertion statements
17-
assertthat::assert_that(is.numeric(Tk), msg="'Tk' is not an integer")
18-
assertthat::assert_that(is.numeric(RH), msg="'RH' is not an integer")
19-
assertthat::assert_that(Tk > 200, msg="'Tk' should be in Kelvin")
20-
assertthat::assert_that(RH >= 0 & RH <= 1, msg="'RH' should be [0,1]")
21-
2216
e <- RH * esat(Tk)
2317
emis_atm <- 0.575 * e ^ 0.143
2418
return(emis_atm)

R/esat.R

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
esat <- function(Tk){
1313

14-
# assertion statements
15-
assertthat::assert_that(is.numeric(Tk), msg="'Tk' is not an integer")
16-
assertthat::assert_that(Tk > 200, msg="'Tk' should be in Kelvin")
17-
1814
esat <- 6.1121 * exp(17.502 * (Tk - 273.15) / (Tk - 32.18))
1915
esat <- 1.004 * esat #correction for moist air, if pressure is not available; for pressure > 800 mb
2016

R/fTg.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
fTg <- function(tas, relh, Pair, wind, min.speed, radiation, propDirect,
1515
zenith, SurfAlbedo=0.4, tolerance=1e-4){
1616

17-
# assertion statements
18-
assertthat::assert_that(propDirect < 1, msg="'propDirect' should be [0,1]")
19-
17+
2018
# Physical constants
2119
stefanb <- 0.000000056696
2220
cp <- 1003.5 # heat capaticy at constant pressure of dry air
@@ -67,7 +65,7 @@ fTg <- function(tas, relh, Pair, wind, min.speed, radiation, propDirect,
6765
}
6866

6967
# Minimization (iteratively)
70-
opt <- optimize(fr, range(Tair-2, Tair+10),Tair,Pair, tol=tolerance)
68+
opt <- stats::optimize(fr, range(Tair-2, Tair+10),Tair,Pair, tol=tolerance)
7169
Tg <- opt$minimum - 273.15
7270

7371
return(Tg)

R/fTnwb.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
fTnwb <- function(tas, dewp, relh, Pair, wind, min.speed, radiation, propDirect,
2525
zenith, irad=1, SurfAlbedo=0.4, tolerance=1e-4){
2626

27-
# assertion statements
28-
assertthat::assert_that(propDirect < 1, msg="'propDirect' should be [0,1]")
2927

3028
# Physical constants
3129
stefanb <- 0.000000056696
@@ -101,7 +99,7 @@ fTnwb <- function(tas, dewp, relh, Pair, wind, min.speed, radiation, propDirect,
10199
}
102100

103101
# Minimization (iteratively)
104-
opt <- optimize(fr, range(Tdew-1, Tair+1),Tair,Pair, tol=tolerance)
102+
opt <- stats::optimize(fr, range(Tdew-1, Tair+1),Tair,Pair, tol=tolerance)
105103

106104
Tnwb <- opt$minimum - 273.15
107105

R/h_cylinder_in_air.R

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@
1616

1717
h_cylinder_in_air <- function(Tk, Pair, speed, min.speed, diam.wick){
1818

19-
# assertion statements
20-
assertthat::assert_that(is.numeric(Tk), msg="'Tk' is not an integer")
21-
assertthat::assert_that(Tk > 200, msg="'Tk' should be in Kelvin")
22-
assertthat::assert_that(is.numeric(Pair), msg="'Pair' is not an integer")
23-
assertthat::assert_that(is.numeric(speed), msg="'speed' is not an integer")
24-
assertthat::assert_that(is.numeric(min.speed), msg="'min.speed' is not an integer")
25-
assertthat::assert_that(is.numeric(diam.wick), msg="'diam.wick' is not an integer")
26-
assertthat::assert_that(diam.wick < 1, msg="'diam.wick' should be meters")
27-
2819
# Constants
2920
m.air <- 28.97
3021
r.gas <- 8314.34

0 commit comments

Comments
 (0)