Skip to content

Commit

Permalink
thunder 1.1.3
Browse files Browse the repository at this point in the history
* cran fixes

* thundeR 1.1.3
  • Loading branch information
bczernecki authored Nov 10, 2023
1 parent 5d08ba2 commit 7398bf2
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: thunder
Type: Package
Title: Computation and Visualisation of Atmospheric Convective Parameters
Version: 1.1.2
Version: 1.1.3
Authors@R: c(person("Bartosz", "Czernecki",
email = "nwp@amu.edu.pl",
role = c("aut", "cre"), comment = c(ORCID = "0000-0001-6496-1386")),
Expand Down Expand Up @@ -47,7 +47,7 @@ Depends:
Suggests:
knitr,
rmarkdown,
testthat (>= 2.0.0)
testthat (>= 3.0.0)
LinkingTo: Rcpp
RoxygenNote: 7.2.3
Encoding: UTF-8
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# thundeR 1.1.3

* Adding new tests for thermodynamic indices failing with metPy 1.5, but working smoothly with thundeR and sharppy

# thundeR 1.1.2

* Allowing to keep NA values in `get_sounding()` which might be not harmful if missing data occur on higher altitudes for dew point temperatures
Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test-get_sounding.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("Downloading sounding profile", {

skip_on_cran() # skip on CRAN due to frequently being recognized as DDOS attack
profile = get_sounding(wmo_id = 12120,
yy = 2010,
mm = 8,
Expand All @@ -11,12 +11,12 @@ test_that("Downloading sounding profile", {
})

test_that("Sounding profile error", {

skip_on_cran() # skip on CRAN due to frequently being recognized as DDOS attack
expect_error(get_sounding(wmo_id = 99999,
yy = 2010,
mm = 8,
dd = 20,
hh = 12)
yy = 2010,
mm = 8,
dd = 20,
hh = 12)
)

})
3 changes: 1 addition & 2 deletions tests/testthat/test-sounding_compute.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ test_that("sounding_compute", {
res = sounding_compute(pressure, altitude, temp, dpt, wd, ws, accuracy = 1)
nams = length(unique(names(res)))
no_of_elements = length(res)
expect_equal(nams, no_of_elements) # the no. of parametrs should be > 100

expect_equal(nams, no_of_elements) # the no. of named parameters should be > 200
})
62 changes: 51 additions & 11 deletions tests/testthat/test-sounding_default.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,61 @@

context("Computation efficiency")
context("sounding_default and sounding_compute should be equal")

test_that("sounding_default should compute below 0.5s", {
test_that("sounding_default should return the same values as sounding_compute for thermodynamics", {
pressure <- c(1000, 855, 700, 500, 300, 100, 10)
altitude <- c(0, 1500, 2500, 6000, 8500, 12000, 25000)
temp <- c(25, 10, 0, -15, -30, -50, -92)
dpt <- c(20, 5, -5, -30, -55, -80, -99)
wd <- c(0, 90, 135, 180, 270, 350, 0)
ws <- c(5, 10, 20, 30, 40, 5, 0)
options(scipen = 999) # change formatting
t1 <- system.time(sounding_default(pressure, altitude, temp, dpt, wd, ws,
export_profile = 0,
accuracy = 2,
interpolate_step = 1000,
meanlayer_bottom_top = c(0, 500),
storm_motion = c(999, 999)))
t1 <- as.numeric(t1[3])
print(paste("Computation time for a single sounding:", t1, "s"))
expect_lt(t1, 60.0) # changed for valgrind compilator, which might be superslow in debugging mode
res_default = sounding_default(pressure, altitude, temp, dpt, wd, ws,
export_profile = 0,
accuracy = 2,
interpolate_step = 1000,
meanlayer_bottom_top = c(0, 500),
storm_motion = c(999, 999))
res_compute = sounding_compute(pressure, altitude, temp, dpt, wd, ws,
accuracy = 2,
interpolate_step = 1000,
meanlayer_bottom_top = c(0, 500),
storm_motion = c(999, 999))

indices_cape = grep(x = names(res_compute), "CAPE")
indices_cin = grep(x = names(res_compute), "CIN")

expect_equal(as.numeric(res_compute[indices_cape]), res_default[indices_cape])
expect_equal(as.numeric(res_compute[indices_cin]), res_default[indices_cin])
})



test_that("sounding_default should have CAPE 2k+ values for profile having CAPE=1 in MetPy", {
p = c(1009.57453125, 1000, 975, 950, 925, 900, 875, 850, 825, 800, 775, 750, 700, 650, 600, 550, 500, 450, 400,
350, 300, 250, 225, 200, 175, 150, 125, 100, 70, 50)
t = c(25.92, 25.07, 23.13, 21.55, 20.54, 19.39, 18.19, 16.96, 15.84, 14.75, 13.55, 12.3, 9.39, 6.73, 3.08, 0.01,
-4.14, -8.98, -14.8, -22.84, -32.18, -42.92, -48.6, -53.6, -57.96, -67.31, -72.61, -76.33, -75.49, -64.64)
alt = c(0, 84, 307, 534, 766, 1003, 1246, 1495, 1750, 2012, 2281, 2557, 3135, 3748, 4402, 5103, 5860, 6683, 7584,
8579, 9688, 10945, 11646, 12411, 13261, 14212, 15297, 16586, 18636, 20653)
q = c(24.13, 21.86, 21.28, 21.13, 20.07, 18.6, 17.6, 16.7, 15.79, 14.75, 13.55, 12.21, 8.52, 3.77, -4.53, -16.51,
-21.2, -23.21, -32.89, -40.98, -50.96, -59.87, -64.33, -66.62, -65.41, -75.21, -82.58, -85.87, -87.36, -86.24)
ws = runif(length(q))
wd = runif(length(q))

res_default = sounding_default(p, alt, t, q, wd, ws,
export_profile = 0,
accuracy = 2,
interpolate_step = 10,
meanlayer_bottom_top = c(0, 500),
storm_motion = c(999, 999))
res_compute = sounding_compute(p, alt, t, q, wd, ws,
accuracy = 2,
interpolate_step = 1000,
meanlayer_bottom_top = c(0, 500),
storm_motion = c(999, 999))

indices_cape = grep(x = names(res_compute), "SB_CAPE$")
expect_equal(as.numeric(res_compute[indices_cape]), res_default[indices_cape])
expect_gt(res_default[indices_cape], 2000)

})

0 comments on commit 7398bf2

Please sign in to comment.