Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit74a6431

Browse files
author
Ilja J. Kocken
committed
update tests and README
1 parent347e294 commit74a6431

File tree

8 files changed

+206
-27
lines changed

8 files changed

+206
-27
lines changed

‎R/get_solution.R‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,19 @@ get_solution <- function(astronomical_solution = "full-ZB18a", quiet = FALSE, fo
105105
}
106106

107107
if (grepl("^La\\d{2}[a-z]?",astronomical_solution)) {
108-
cli::cli_warn(c(
108+
cli::cli_inform(c(
109109
"i"="Relying on {.pkg astrochron} to get solution {.q {astronomical_solution}}",
110-
"i"="We do not cache these results.",
111-
"!"="{.pkg astrochron} converts time from -kyr to ka by default."))
110+
"i"="We do not cache these results.",
111+
"!"="{.pkg astrochron} converts time from -kyr to ka by default."))
112112
rlang::check_installed("astrochron",
113113
reason="to use `astrochron::getLaskar()`")
114114
dat<-tibble::as_tibble(
115115
astrochron::getLaskar(sol= tolower(astronomical_solution),
116116
verbose=!quiet)
117117
)
118-
cli::cli_warn(c(
119-
"i"="Output has column names {.q {colnames(dat)}}"
120-
))
118+
cli::cli_alert_info(
119+
"Output has column names {.q {colnames(dat)}}"
120+
)
121121
return(dat)
122122
}
123123

@@ -189,7 +189,7 @@ get_ZB <- function(astronomical_solution = "full-ZB18a",
189189

190190
if (!quiet) {
191191
cli::cli_alert_info(c(
192-
"!"="The astronomical solution {.q {astronomical_solution}} has not been cached."
192+
"The astronomical solution {.q {astronomical_solution}} has not been cached."
193193
))
194194
}
195195

@@ -298,8 +298,9 @@ get_ZB <- function(astronomical_solution = "full-ZB18a",
298298
raw<- prepare_solution(raw,quiet=quiet)
299299
}else {
300300
if (grepl("^ZB23\\.R",astronomical_solution)) {
301-
cli::cli_inform(c("Downloading any of the ZB23.RXX solutions will take some time.",
302-
"Zip files are about 154 MB."))
301+
cli::cli_inform(c(
302+
"i"="Downloading any of the ZB23.RXX solutions will take some time.",
303+
"i"="Zip files are about 154 MB."))
303304
sure<-utils::askYesNo("Continue downloading and caching?")
304305
if (is.na(sure)) {
305306
cli::cli_abort("Cancelled by user.",call=NULL)
@@ -326,7 +327,7 @@ get_ZB <- function(astronomical_solution = "full-ZB18a",
326327
if (grepl("^ZB17|^ZB18|^ZB20",astronomical_solution)) {
327328
raw<-dplyr::mutate(raw,time=-.data$time)
328329
if (!quiet) {
329-
cli::cli_alert_warning(
330+
cli::cli_alert_info(
330331
"Flipped time for {.q {astronomical_solution}} so that it is in negative kyr."
331332
)
332333
}

‎README.Rmd‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ knitr::opts_chunk$set(
1111
fig.path = "man/figures/README-",
1212
out.width = "100%"
1313
)
14-
options(snvecR.cachedir = withr::local_tempdir(pattern = "snvecR"))
14+
pth <- withr::local_tempdir(pattern = "snvecR")
15+
withr::local_options(list(snvecR.cachedir = pth))
1516
```
1617

1718
#snvecR

‎README.md‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ sol <- get_solution("full-ZB18a")
6262
#> ℹ The astronomical solution "full-ZB18a" has not been cached.
6363
#> ℹ Reading 'full-ZB18a.dat' from website <http://www.soest.hawaii.edu/oceanography/faculty/zeebe_files/Astro/PrecTilt/OS/ZB18a/ems-plan3.dat>.
6464
#> ℹ Calculating helper columns.
65-
#> ℹ The cache directory is '/tmp/RtmpR5G9yC/snvecR43dce2ecdb925'.
65+
#> ℹ The cache directory is '/tmp/Rtmpya43uW/snvecR1942b47b14132e'.
6666
#> ℹ Saved astronomical solution with helper columns 'full-ZB18a.rds' to cache.
6767
#> ℹ Future calls to `get_solution("full-ZB18a")` will read from the cache.
6868
#> ! If you want to read from scratch, specify `force = TRUE`.
@@ -71,30 +71,32 @@ ZB18a <- get_solution("ZB18a-300")
7171
#> ℹ The astronomical solution "ZB18a-300" has not been cached.
7272
#> ℹ Reading 'ZB18a-300.dat' from website <http://www.soest.hawaii.edu/oceanography/faculty/zeebe_files/Astro/300Myr/ZB18a.dat>.
7373
#> ! Flipped time for "ZB18a-300" so that it is in negative kyr.
74-
#> ℹ The cache directory is '/tmp/RtmpR5G9yC/snvecR43dce2ecdb925'.
74+
#> ℹ The cache directory is '/tmp/Rtmpya43uW/snvecR1942b47b14132e'.
7575
#> ℹ Saved astronomical solution with helper columns 'ZB18a-300.rds' to cache.
7676
#> ℹ Future calls to `get_solution("ZB18a-300")` will read from the cache.
7777
#> ! If you want to read from scratch, specify `force = TRUE`.
7878
ZB20a<- get_solution("ZB20a")
7979
#> ℹ The astronomical solution "ZB20a" has not been cached.
8080
#> ℹ Reading 'ZB20a.dat' from website <http://www.soest.hawaii.edu/oceanography/faculty/zeebe_files/Astro/300Myr/ZB20a.dat>.
8181
#> ! Flipped time for "ZB20a" so that it is in negative kyr.
82-
#> ℹ The cache directory is '/tmp/RtmpR5G9yC/snvecR43dce2ecdb925'.
82+
#> ℹ The cache directory is '/tmp/Rtmpya43uW/snvecR1942b47b14132e'.
8383
#> ℹ Saved astronomical solution with helper columns 'ZB20a.rds' to cache.
8484
#> ℹ Future calls to `get_solution("ZB20a")` will read from the cache.
8585
#> ! If you want to read from scratch, specify `force = TRUE`.
8686
# a pre-computed precession-tilt solution (PT)
8787
ZB18a_1_1<- get_solution("PT-ZB18a(1,1)")
8888
#> ℹ The astronomical solution "PT-ZB18a(1.0000,1.0000)" has not been cached.
8989
#> ℹ Reading 'PT-ZB18a(1.0000,1.0000).dat' from website <http://www.soest.hawaii.edu/oceanography/faculty/zeebe_files/Astro/PrecTilt/ZB18a/asc/PT.De1.0000Td1.0000.dat>.
90-
#> ℹ The cache directory is '/tmp/RtmpR5G9yC/snvecR43dce2ecdb925'.
90+
#> ℹ The cache directory is '/tmp/Rtmpya43uW/snvecR1942b47b14132e'.
9191
#> ℹ Saved astronomical solution with helper columns 'PT-ZB18a(1.0000,1.0000).rds'
9292
#> to cache.
9393
#> ℹ Future calls to `get_solution("PT-ZB18a(1.0000,1.0000)")` will read from the
9494
#> cache.
9595
#> ! If you want to read from scratch, specify `force = TRUE`.
9696
```
9797

98+
<!-- we put this in a separate block so building the README is a little faster-->
99+
98100
```r
99101
# the 3.5 Gyr solutions, e.g. number 5
100102
ZB23.R05<- get_solution("ZB23.R05")
@@ -111,7 +113,9 @@ ZB23.R05 <- get_solution("ZB23.R05")
111113

112114
##Calculating Precession and Obliquity
113115

114-
Here’s the main function that does the work in action:
116+
Here’s the`snvec()` function that calculates climatic precession and
117+
obliquity from an orbital solution input and values for tidal
118+
dissipation (T<sub>d</sub>) and dynamical ellipticity (E<sub>d</sub>).
115119

116120
```r
117121
solution<- snvec(tend=-1000,# final timestep in kyr
@@ -120,7 +124,7 @@ solution <- snvec(tend = -1000, # final timestep in kyr
120124
astronomical_solution="full-ZB18a",# see ?full_ZB18a for details
121125
tres=-0.4# timestep resolution in kyr (so this is 400 years)
122126
)
123-
#> This is snvecR VERSION: 3.10.0.9000 2025-03-04
127+
#> This is snvecR VERSION: 3.10.0.9000 2025-03-05
124128
#> Richard E. Zeebe
125129
#> Ilja J. Kocken
126130
#>
@@ -136,15 +140,15 @@ solution <- snvec(tend = -1000, # final timestep in kyr
136140
#> • `atol` = 1e-05
137141
#> • `rtol` = 0
138142
#> • `solver` = "vode"
139-
#> ℹ started at "2025-03-04 16:12:43.23286"
143+
#> ℹ started at "2025-03-0512:04:56.589572"
140144
#> Final values:
141145
#> • s[1][2][3]: 0.404184487124565, -0.0537555129057148, and 0.913036138471423
142146
#> • s-error = |s|-1: -5.51290422495798e-05
143147
#> Final values:
144148
#> • obliquity: 0.413060472710089 rad
145149
#> • precession: -0.562357122261026 rad
146-
#> ℹ stopped at "2025-03-04 16:12:43.956671"
147-
#> ℹ total duration: 0.72
150+
#> ℹ stopped at "2025-03-0512:04:57.417171"
151+
#> ℹ total duration: 0.83
148152
```
149153

150154
To quickly save out the results for further study to CSV[^1]:
@@ -182,6 +186,14 @@ solution |>
182186

183187
<imgsrc="man/figures/README-plot-1.png"width="100%" />
184188

189+
#Contributing
190+
191+
Contributions are more than welcome! If something doesn’t work the way
192+
you expect and you don’t know how to fix it,[write an
193+
issue](https://github.com/japhir/snvecR/issues). If you do know how to
194+
fix it, feel free to[create a pull
195+
request](https://github.com/japhir/snvecR/pulls)!
196+
185197
#References
186198

187199
Zeebe, R. E., & Lourens, L. J. (2019). Solar System chaos and the

‎tests/testthat/_snaps/get_solution.md‎

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#get_solution() can load eccentricity solutions
1515

1616
Code
17-
head(get_solution(astronomical_solution = "ZB20b", quiet = TRUE, force = TRUE))
17+
head(get_solution(astronomical_solution = "ZB17a", quiet = TRUE, force = TRUE))
1818
Output
1919
# A tibble: 6 x 3
2020
time ecc inc
@@ -26,6 +26,71 @@
2626
5 -6.4 0.0188 6.84
2727
6 -8 0.0192 6.70
2828

29+
---
30+
31+
Code
32+
head(get_solution(astronomical_solution = "ZB18a-100", quiet = TRUE, force = TRUE))
33+
Output
34+
# A tibble: 6 x 3
35+
time ecc inc
36+
<dbl> <dbl> <dbl>
37+
1 0 0.0167 7.15
38+
2 -1.6 0.0173 7.11
39+
3 -3.2 0.0179 7.04
40+
4 -4.8 0.0184 6.95
41+
5 -6.4 0.0188 6.84
42+
6 -8 0.0192 6.70
43+
44+
---
45+
46+
Code
47+
head(get_solution(astronomical_solution = "ZB18a-300", quiet = TRUE, force = TRUE))
48+
Output
49+
# A tibble: 6 x 3
50+
time ecc inc
51+
<dbl> <dbl> <dbl>
52+
1 0 0.0167 7.15
53+
2 -1.6 0.0173 7.11
54+
3 -3.2 0.0179 7.04
55+
4 -4.8 0.0184 6.95
56+
5 -6.4 0.0188 6.84
57+
6 -8 0.0192 6.70
58+
59+
---
60+
61+
Code
62+
head(get_solution(astronomical_solution = "ZB20a", quiet = TRUE, force = TRUE))
63+
Output
64+
# A tibble: 6 x 3
65+
time ecc inc
66+
<dbl> <dbl> <dbl>
67+
1 0 0.0167 7.15
68+
2 -1.6 0.0173 7.11
69+
3 -3.2 0.0179 7.04
70+
4 -4.8 0.0184 6.95
71+
5 -6.4 0.0188 6.84
72+
6 -8 0.0192 6.70
73+
74+
---
75+
76+
Code
77+
head(get_solution(astronomical_solution = "La10d", quiet = TRUE, force = TRUE))
78+
Message
79+
i Relying on astrochron to get solution "La10d"
80+
i We do not cache these results.
81+
! astrochron converts time from -kyr to ka by default.
82+
i Output has column names "Time_ka" and "ecc_LA10d"
83+
Output
84+
# A tibble: 6 x 2
85+
Time_ka ecc_LA10d
86+
<dbl> <dbl>
87+
1 0 0.0167
88+
2 1 0.0172
89+
3 2 0.0175
90+
4 3 0.0178
91+
5 4 0.0182
92+
6 5 0.0185
93+
2994
#get_solution() can load full solutions
3095

3196
Code
@@ -108,10 +173,10 @@
108173
Message
109174
i The astronomical solution "ZB23.R01" has not been cached.
110175
i Reading 'ZB23.R01.dat' from website <http://www.soest.hawaii.edu/oceanography/faculty/zeebe_files/Astro/3.5Gyr/ZB23-N64-eiop/ZB23.R01.eiop.dat.zip>.
111-
Downloading any of the ZB23.RXX solutions will take some time.
112-
Zip files are about 154 MB.
176+
iDownloading any of the ZB23.RXX solutions will take some time.
177+
iZip files are about 154 MB.
113178
Output
114-
Continue downloading and caching {.q {astronomical_solution}}? (Yes/no/cancel)
179+
Continue downloading and caching? (Yes/no/cancel)
115180
Message
116181
i The cache directory is 'transformed-for-CI'.
117182
i Saved astronomical solution with helper columns 'ZB23.R01.rds' to cache.

‎tests/testthat/_snaps/snvec.md‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#snvec() works
22

33
Code
4-
print(dplyr::select(snvec(tend = -49, ed = 1, td = 0, tres = -1,quiet =TRUE, output ="all"),
5-
tidyselect::all_of(c("time", "sx", "sy", "sz", "epl", "phi", "lpx", "cp"))), n = 50)
4+
print(dplyr::select(snvec(tend = -49, ed = 1, td = 0, tres = -1,os_ref_frame ="HCI", quiet =TRUE,
5+
output = "all"),tidyselect::all_of(c("time", "sx", "sy", "sz", "epl", "phi", "lpx", "cp"))), n = 50)
66
Output
77
# A tibble: 50 x 8
88
time sx sy sz epl phi lpx cp
@@ -58,3 +58,63 @@
5858
49 -48 0.376 -0.171 0.911 0.426 -0.867 1.30 0.0137
5959
50 -49 0.424 -0.0836 0.902 0.426 -0.631 1.07 0.0126
6060

61+
---
62+
63+
Code
64+
print(dplyr::select(snvec(tend = -49, ed = 1, td = 0, tres = -1, quiet = TRUE, os_ref_frame = "J2000",
65+
output = "all"), tidyselect::all_of(c("time", "sx", "sy", "sz", "epl", "phi", "lpx", "cp"))), n = 50)
66+
Output
67+
# A tibble: 50 x 8
68+
time sx sy sz epl phi lpx cp
69+
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
70+
1 0 0 0.509 0.861 0.409 0 0.477 0.00767
71+
2 -1 -0.0962 0.497 0.862 0.409 0.239 0.183 0.00312
72+
3 -2 -0.187 0.464 0.866 0.409 0.478 -0.112 -0.00195
73+
4 -3 -0.267 0.410 0.872 0.409 0.717 -0.405 -0.00703
74+
5 -4 -0.332 0.338 0.881 0.408 0.957 -0.697 -0.0117
75+
6 -5 -0.378 0.254 0.890 0.406 1.20 -0.994 -0.0155
76+
7 -6 -0.402 0.161 0.901 0.405 1.44 -1.29 -0.0180
77+
8 -7 -0.404 0.0659 0.913 0.403 1.68 -1.58 -0.0190
78+
9 -8 -0.382 -0.0267 0.924 0.401 1.92 -1.87 -0.0183
79+
10 -9 -0.339 -0.111 0.934 0.399 2.16 -2.17 -0.0160
80+
11 -10 -0.277 -0.182 0.943 0.396 2.41 -2.46 -0.0122
81+
12 -11 -0.200 -0.236 0.951 0.393 2.65 -2.76 -0.00735
82+
13 -12 -0.112 -0.269 0.957 0.391 2.90 -3.05 -0.00175
83+
14 -13 -0.0198 -0.280 0.960 0.388 -3.14 2.93 0.00404
84+
15 -14 0.0722 -0.268 0.961 0.386 -2.89 2.64 0.00948
85+
16 -15 0.158 -0.234 0.959 0.383 -2.64 2.34 0.0141
86+
17 -16 0.232 -0.179 0.956 0.381 -2.38 2.04 0.0174
87+
18 -17 0.290 -0.109 0.951 0.380 -2.13 1.75 0.0192
88+
19 -18 0.329 -0.0263 0.944 0.378 -1.88 1.45 0.0192
89+
20 -19 0.345 0.0629 0.936 0.377 -1.62 1.15 0.0175
90+
21 -20 0.338 0.153 0.928 0.377 -1.37 0.860 0.0144
91+
22 -21 0.309 0.239 0.921 0.377 -1.11 0.565 0.0101
92+
23 -22 0.259 0.315 0.913 0.378 -0.858 0.272 0.00500
93+
24 -23 0.191 0.375 0.907 0.379 -0.604 -0.0193 -0.000354
94+
25 -24 0.110 0.417 0.902 0.381 -0.350 -0.307 -0.00547
95+
26 -25 0.0202 0.437 0.899 0.383 -0.0976 -0.594 -0.00999
96+
27 -26 -0.0720 0.435 0.898 0.385 0.154 -0.878 -0.0135
97+
28 -27 -0.161 0.409 0.898 0.388 0.404 -1.16 -0.0158
98+
29 -28 -0.242 0.362 0.900 0.391 0.653 -1.43 -0.0168
99+
30 -29 -0.309 0.297 0.904 0.394 0.900 -1.70 -0.0165
100+
31 -30 -0.358 0.216 0.908 0.397 1.15 -1.97 -0.0151
101+
32 -31 -0.386 0.126 0.914 0.400 1.39 -2.24 -0.0126
102+
33 -32 -0.392 0.0304 0.920 0.403 1.63 -2.50 -0.00944
103+
34 -33 -0.374 -0.0639 0.925 0.405 1.87 -2.75 -0.00584
104+
35 -34 -0.335 -0.152 0.930 0.408 2.11 -3.01 -0.00202
105+
36 -35 -0.275 -0.228 0.934 0.410 2.35 -3.26 0.00172
106+
37 -36 -0.199 -0.288 0.937 0.412 2.59 -3.50 0.00519
107+
38 -37 -0.110 -0.329 0.938 0.413 2.83 -3.74 0.00818
108+
39 -38 -0.0141 -0.348 0.937 0.414 3.07 -3.99 0.0107
109+
40 -39 0.0838 -0.344 0.935 0.415 -2.98 2.06 0.0124
110+
41 -40 0.178 -0.317 0.932 0.415 -2.74 1.82 0.0135
111+
42 -41 0.263 -0.269 0.927 0.414 -2.51 1.59 0.0138
112+
43 -42 0.335 -0.202 0.920 0.414 -2.27 1.36 0.0134
113+
44 -43 0.388 -0.121 0.914 0.412 -2.03 1.12 0.0123
114+
45 -44 0.421 -0.0294 0.907 0.411 -1.80 0.895 0.0107
115+
46 -45 0.431 0.0669 0.900 0.409 -1.56 0.658 0.00842
116+
47 -46 0.418 0.163 0.894 0.406 -1.32 0.426 0.00572
117+
48 -47 0.382 0.252 0.889 0.404 -1.07 0.188 0.00262
118+
49 -48 0.327 0.330 0.886 0.401 -0.832 -0.0503 -0.000713
119+
50 -49 0.255 0.392 0.884 0.398 -0.589 -0.291 -0.00414
120+

‎tests/testthat/test-get_solution.R‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_that("get_solution() bad inputs throw errors", {
44
expect_error(get_solution(astronomical_solution="hoi"))
55
expect_error(get_solution(astronomical_solution="full-La11"))
66
expect_error(get_solution(astronomical_solution=data.frame(x=1,y=5)))# this runs via prepare_solution
7+
expect_error(get_solution(astronomical_solution="ZB18a"))
78
})
89

910
test_that("get_solution() can return a dataframe", {
@@ -26,9 +27,20 @@ test_that("get_solution() can load eccentricity solutions", {
2627
pth<-withr::local_tempdir(pattern="snvecR")
2728
withr::local_options(list(snvecR.cachedir=pth,width=150))
2829

29-
expect_snapshot(head(get_solution(astronomical_solution="ZB20b",
30+
expect_snapshot(head(get_solution(astronomical_solution="ZB17a",
3031
quiet=TRUE,force=TRUE)))
3132

33+
expect_snapshot(head(get_solution(astronomical_solution="ZB18a-100",
34+
quiet=TRUE,force=TRUE)))
35+
36+
expect_snapshot(head(get_solution(astronomical_solution="ZB18a-300",
37+
quiet=TRUE,force=TRUE)))
38+
39+
expect_snapshot(head(get_solution(astronomical_solution="ZB20a",
40+
quiet=TRUE,force=TRUE)))
41+
42+
expect_snapshot(head(get_solution(astronomical_solution="La10d",
43+
quiet=TRUE,force=TRUE)))
3244
})
3345

3446
test_that("get_solution() can load full solutions", {

‎tests/testthat/test-globals.R‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test_that("cachedir() works", {
2+
expect_type(snvecR:::cachedir(),"character")
3+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp