Closed kevinsorochan closed 2 years ago
After further investigation, I think this problem may arise when the oce object that is being manipulated is not sorted by time. That is the index for each observation is not linear with time. Not sure why I am running into this issue now....
In the processing example provided with the package we should make sure to include that sorting (I have used dplyr::arrange)
data <- ctd_roi_merge %>% dplyr::mutate(., avg_hr = time_ms / 3.6e+06)
data <- vpr_ctd_ymd(data, year)
data <- data %>% dplyr::arrange(., time_ms)
cat('Initial processing complete! \n') cat('\n')
Is this issue resolved by sorting the object by time? Or does it require more investigation? If so can you give an example? Thanks!
It appears that sorting the data by time prior to creating an oce object, in the workflow, did resolve this problem. An update is required in the example workflow or one of the processing functions in vprr to prevent this from happening.
I'm not sure if defaults in oce::ctdFindProfiles has been updated, but our usage of this function appears to be no longer effective. It was working really well until recently, I think. The moving average recommended below in oce documentation performs much better.
in ?ctdFindProfiles:
"the default value of smoother is smooth.spline(), and this works well for just a few profiles, but poorly for a tow-yo with a long sequence of profiles; in the latter case, it can be preferable to use simpler smoothers"
Example 2. Use a moving average to smooth pressure, instead of the
default smooth.spline() method. This might avoid a tendency of
the default scheme to miss some profiles in a long towyo.
movingAverage <- function(x, n = 11, ...) { f <- rep(1/n, n) stats::filter(x, f, ...) } casts <- ctdFindProfiles(towyo, smoother=movingAverage)