Skip to content
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

adpFlagPastBoundary() should have an option for no smoothing #2294

Open
richardsc opened this issue Feb 11, 2025 · 3 comments
Open

adpFlagPastBoundary() should have an option for no smoothing #2294

richardsc opened this issue Feb 11, 2025 · 3 comments
Labels

Comments

@richardsc
Copy link
Collaborator

I've used the (relatively new) function adpFlagPastBoundary() a few times for trimming upward-looking ADCP data, to remove the bins near and beyond the surface. (sidenote, it requires a little hacking, to create a br/bottomrange field from the pressure time series because generally the instrument wouldn't be tracking the surface as in the downward-looking vessel-mounted configuration). It works well, but one thing I noticed is that the df argument (that feeds a smoothing spline) is required. For large/rapidly sampled datasets this operation can take a long time, and can also result in excessive trimming if the df is set too low.

I would propose that it would be better if either:

  1. There could be an option to not do any smoothing, or
  2. In addition to being able to specify no smoothing, perhaps the behaviour should be as in other oce functions (e.g. ctdDecimate()) where the method can be a user-specified function (which would allow simple boxcar filters, etc).

Thoughts?

@richardsc richardsc added the adp label Feb 11, 2025
@dankelley
Copy link
Owner

I like the idea of letting users specify a function.

@dankelley
Copy link
Owner

dankelley commented Feb 13, 2025

Here's a mockup. The way a user could set things up is at the definition of Ys below. I don't think that's too daunting for users, especially because it would be documented.

png("0.png")
library(oce)
process <- function(x, y, s) {
    if (missing(s)) {
        smooth.spline(x, y, df = 20)$y
    } else {
        s(x, y)
    }
}
n <- 100
set.seed(20250213)
x <- seq(0, 1, length.out = n)
y <- (x - 0.2) * (x - 0.6) + rnorm(n, sd = 0.05)
plot(x, y)

Y <- process(x, y)
lines(x, Y, col = 2, lwd = 2)

Ys <- process(x, y, \(x, y) smooth.spline(x, y, nknots = length(x)/5)$y)
lines(x, Ys, col = 4, lwd = 2)
legend("top", lwd = 2, col = c(2, 4), legend = c(
    "default (spline with df=20)",
    "user (spline with knots=n/5)"
))

Image

dankelley added a commit that referenced this issue Feb 13, 2025
@dankelley
Copy link
Owner

commit 7176768 of "develop" has code that might solve this issue. I have not tested it, though. All I did was to hack in some code, and rewrite the docs.

Maybe @richardsc can take a look. Since I've done no testing at all, please be on the lookout for problems and maybe also take a look at the diff in code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants