EOGrady21 / vprr

Video Plankton Recorder Data Processing
https://eogrady21.github.io/vprr/
Other
2 stars 1 forks source link

ctd_cast() no longer working properly #25

Closed kevinsorochan closed 2 years ago

kevinsorochan commented 3 years ago

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)

kevinsorochan commented 3 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)

ADD ADDITIONAL VARIABLES

add avg hr, sigma T, and depth

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')

EOGrady21 commented 2 years ago

Is this issue resolved by sorting the object by time? Or does it require more investigation? If so can you give an example? Thanks!

kevinsorochan commented 2 years ago

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.