From 7398bf28cca9bcb101114985df4a14fc43e85996 Mon Sep 17 00:00:00 2001 From: Bartosz Czernecki Date: Fri, 10 Nov 2023 23:36:35 +0100 Subject: [PATCH] thunder 1.1.3 * cran fixes * thundeR 1.1.3 --- DESCRIPTION | 4 +- NEWS.md | 4 ++ tests/testthat/test-get_sounding.R | 14 +++--- tests/testthat/test-sounding_compute.R | 3 +- tests/testthat/test-sounding_default.R | 62 +++++++++++++++++++++----- 5 files changed, 65 insertions(+), 22 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 70f7f6a..0196787 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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")), @@ -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 diff --git a/NEWS.md b/NEWS.md index fbcac1f..c5ca7d0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/tests/testthat/test-get_sounding.R b/tests/testthat/test-get_sounding.R index 3f43554..35d9705 100644 --- a/tests/testthat/test-get_sounding.R +++ b/tests/testthat/test-get_sounding.R @@ -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, @@ -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) ) - + }) diff --git a/tests/testthat/test-sounding_compute.R b/tests/testthat/test-sounding_compute.R index 2001361..d9a69ff 100644 --- a/tests/testthat/test-sounding_compute.R +++ b/tests/testthat/test-sounding_compute.R @@ -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 }) diff --git a/tests/testthat/test-sounding_default.R b/tests/testthat/test-sounding_default.R index 6951571..0d882bc 100644 --- a/tests/testthat/test-sounding_default.R +++ b/tests/testthat/test-sounding_default.R @@ -1,7 +1,7 @@ -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) @@ -9,13 +9,53 @@ test_that("sounding_default should compute below 0.5s", { 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) + +}) \ No newline at end of file