-
Notifications
You must be signed in to change notification settings - Fork 13
Add k.klaus #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add k.klaus #153
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
efaa75a
Constrain c1 and c2 positive
bmcafee f0e0870
Correct C calls
bmcafee a6a34ca
Undo C call updates
bmcafee e2d219a
Added k.klaus and k.klaus.base
bmcafee 62ef8c5
k.klaus documentation quick fix
bmcafee 9cc45bd
Merge pull request #1 from GLEON/main
bmcafee aa7ede0
Revert all MLE changes
bmcafee bbf60c9
Merge branch 'main' of https://github.com/bmcafee/LakeMetabolizer2
bmcafee a3d3ffd
Constrain MLE estimates to correct sign
bmcafee 52e08e0
Update indentation
bmcafee f924e55
Update k.klaus documentation
bmcafee ef0471a
Revert metab.mle changes; moving to separate PR
bmcafee 22b8909
Update k.klaus.base arguments in k.klaus
bmcafee 6da9a69
Remove redundant qualifier from k.klaus
bmcafee b248616
Rename logit_custom to logit.custom
bmcafee fdf93ff
Apply new logit.custom name
bmcafee aa559e3
Update k.klaus documentation in k.read.R
bmcafee 558a48c
Update k.klaus documentation in k.read.R
bmcafee 80affb8
Rename sin to spatial.int and update k.klaus documentation
bmcafee 1a57783
Removed exp model from k.klaus
bmcafee 007e1d9
Rebuild documentation
bmcafee 4d88791
Fix errors in k.klaus documentation
bmcafee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # ---Author: Bennett McAfee, 2026-06-08 --- | ||
| # Last update: 2026-06-08 | ||
|
|
||
| #'@export | ||
| k.klaus = function(ts.data, wnd.z, lake.area, spatial.int, method = c("linear", "power")){ | ||
|
|
||
| if(!has.vars(ts.data, 'wnd')){ | ||
| stop('k.klaus requires a "wnd" (wind speed) column in the supplied data') | ||
| } | ||
|
|
||
| wind = get.vars(ts.data, 'wnd') | ||
|
|
||
| k600 = k.klaus.base(wind[,2], wnd.z, lake.area, spatial.int, method = method) | ||
|
|
||
| return(data.frame(datetime=ts.data$datetime, k600=k600)) | ||
| } | ||
|
|
||
|
|
||
| #'@export | ||
| k.klaus.base <- function(wnd, wnd.z, lake.area, spatial.int, method = c("linear", "power")) { | ||
|
|
||
| method <- match.arg(method) | ||
|
|
||
| # converting m2 to km2 | ||
| lake.area <- lake.area / 1e6 | ||
|
|
||
| # Converting uz to u10 | ||
| if (wnd.z != 10){ | ||
| wnd <- wind.scale.base(wnd = wnd, wnd.z = wnd.z) | ||
| } | ||
|
|
||
| # helper logit function | ||
| logit.custom <- function(x){ | ||
| return(log(x / (1 - x))) | ||
| } | ||
|
|
||
| # sanity checks | ||
| if (any(spatial.int <= 0 | spatial.int >= 1)) { | ||
| stop("spatial.int must be between 0 and 1 (exclusive)") | ||
| } | ||
|
|
||
| if (method == "linear") { | ||
| k600 <- (0.328 * log10(lake.area) + 1.581) * wnd - 0.066 * logit.custom(spatial.int) + 1.266 | ||
| } else if (method == "power") { | ||
| k600 <- (0.281 * log10(lake.area) + 1.361) * (wnd ^ 1.097) - 0.072 * logit.custom(spatial.int) + 1.401 | ||
| } else if (method == "exp") { | ||
| # if (is.null(sdi)) { | ||
| # stop("sdi must be provided for exponential model") | ||
| # } | ||
| # k600 <- (-0.057 * logit.custom(spatial.int) + 2.366) * exp(wnd * (0.144 * log10(sdi) + 0.156)) | ||
| stop('The exponential model was removed per Klaus and Vachon (2020): "...[We] do not recommend using our | ||
| models that include SDI."') | ||
| } | ||
|
|
||
| k600 <- k600 * (24/100) # convert cm/hr to m/day | ||
|
|
||
| return(k600) | ||
| } | ||
|
|
||
|
|
||
| # -- References | ||
| # Klaus, Marcus, and Dominic Vachon. 2020. | ||
| # Challenges of Predicting Gas Transfer Velocity from Wind Measurements over Global Lakes. | ||
| # Aquatic Sciences 82 (3): 53. https://doi.org/10.1007/s00027-020-00729-9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.