Git Product home page Git Product logo

divemove's Introduction

diveMove

R build and check CRAN_Status_Badge CRAN_Downloads

diveMove is a GNU R package with tools to represent, visualize, filter, analyse, and summarize time-depth recorder (TDR) data. It also provides miscellaneous functions for handling location data.

Read ?diveMove for a quick overview of the major functionality. A vignette is also available by doing vignette("diveMove").

Dive analysis usually involves handling of large amounts of data, as new instruments allow for frequent sampling of variables over long periods of time. The aim of this package is to make this process more efficient for summarizing and extracting information gathered by time-depth recorders (TDRs, hereafter). The principal motivation for developing diveMove was to provide more flexibility during the various stages of analysis than is available in popular commercial software. This is achieved by making the results from intermediate calculations easily accessible, allowing the user to make his/her own summaries beyond the default choices the package provides.

Installation

Get the released version from CRAN:

install.packages("diveMove")

Or the development version from GitHub:

# install.packages("devtools")
devtools::install_github("spluque/diveMove")

Python users can access the package's functionality via scikit-diveMove.

divemove's People

Contributors

spluque avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

divemove's Issues

Error using calibrateDepth function

I have recently tried to use the calibrateDepth function on some time-depth recorder data collected on auks but have had this error returned for some of my files:

Error message:
Record is truncated at the beginning and at the end
1 phase detected
189 dives detected
Error in if (all(Ad1.maybe >= 0)) { :
Missing value where TRUE/FALSE needed

As far as I can tell, there are no errors in the files that I am trying to process.
If you are able to advise me on what might be going wrong here, that would be great!

Dive statistics incorrect?

Question on diveMove

Hi, the summary statistics for some dives appear to be strange-the beginning of the ascent time is listed as occurring before both the beginning and end of the descent time. It seems to always have this 5 minute offset. The times given don't seem to translate onto the plotTDR time and phases either. I can't work out what I've done to cause this or how to address this?

As an example this specific dive (number 445) says:
begdesc: 2016-07-23 08:05:00
enddesc : 2016-07-23 08:05:00
begasc: 2016-07-23 08:00:00

But when viewing the TTDR none of these numbers seem to match and the 'bottom phase' seems to be marked as DA/ A.

TTDR of dive 445:
image

I'm still working on optimizing the ZOC, but I don't think this would cause the issue? Sorry for the noob question and thanks so much in advance :)

sample data- example.csv
(more occur in the whole dataset)

ifile <- "example.csv"
tdrX <- readTDR(ifile, dateCol=6, timeCol=7, depthCol=11, concurrentCols=NULL,
                dtformat="%d-%b-%y %H:%M:%S", subsamp=
[example.csv](https://github.com/spluque/diveMove/files/9910111/example.csv)
300)

dcalib2 <-calibrateDepth(tdrX,
                        wet.thr = 3610,  # (seconds) At-sea phases shorter than this threshold will be considered as trivial wet.Delete periods of wet activity that are too short to be compared with other wet periods.
                        dive.thr = 7,    # (meters) threshold depth below which an underwater phase should be considered a dive.
                        zoc.method ="filter",  # see Luque and Fried (2011)
                        k = c(12, 240),  # (60 and 1200 minutes) Vector of moving window width integers to be applied sequentially.
                        probs = c(0.5, 0.05),   # Vector of quantiles to extract at each step indicated by k (so it must be as long as k)
                        depth.bounds = c(-5, 15),  # minimum and maximum depth to bound the search for the surface.
                        na.rm = TRUE)

stats<-diveStats(dcalib2)

filter(stats, begasc < begdesc)

plotTDR(dcalib2, diveNo=445

Edit
changing to smooth.spline appears to help with descent phase detection, however as this is for a loggerhead turtle I'm not sure if this is correct to do for all dives?

image

On a side note is there a way to interpolate the time the animal actually goes below a desired threshold and use this as the start of ascent time? You can see from the profile they start descending before the descent identification at ~66m, due to the low sampling frequency of 5m. Could I somehow estimate the time the turtle went below e.g. 7m using the getDiveDeriv() ?

Divephase DA?

Hi Sebastian, thanks for diveMove and the paper, it looks like it has excellent potential.
I'm trying to use it to analyse dive behaviour of tuna, which don't go to the surface exactly but often come shallow. I'm having a few problems which I'll file separately for neatness.

Please can you let me know what DA means for getDPhaseLab(dcalib)? The other 6 are explained in the paper:

descent = D
descent/bottom = DB
bottom = B
bottom/ascent = BA
ascent = A
DA??
X = surface

It would be great if these were listed in the details section of the function, for ease of access.

Thanks!

dive.activity meanings

Hi again,

Please could you let me know a little more what getDAct(dcalib)$dive.activity levels mean? FOr my result (with number of rows per category) I have:

L dry, 0
W wet, 587
U underwater (above dive depth), 21093
D diving, 21520
Z trivial wet animal activities, 0

U and D I understand, above and below dive.thr? So what is wet? And what does Z mean?

Thanks!

calibrateDepth detect n dives; diveStats report n-1 dives

calibrateDepth detect n dives; diveStats report n-1 dives

calibrateDepth reports the number of dives in the data. diveStats reports the statistics for all the dives. Often, the same number of dives are identified in calibrateDepth and diveStats.
However, with some data sets, calibrateDepth detect n dives and diveStats report n-1 dives. "Losing" one dive has consequences for my downstream analysis, so I am trying to understand this behavior. (Note: it always seems to be n-1, rather than another number).

Below I provide analysis code and two data files (one with 52 dives detected in calibrateDepth and diveStats; one with 60 dives detected in calibrateDepth and 59 reported in diveStats.

I am using diveMove_1.6.1 and R version 4.3.2 (2023-10-31 ucrt). Platform: x86_64-w64-mingw32/x64 (64-bit)

Thanks for a great package!

library(diveMove)

# read in one of the csv:
dat <- read.csv("./test_input2.csv")       # calibrateDepth =! diveStats
#dat <- read.csv("./test_input_fine2.csv")  # calibrateDepth = diveStats

dat$date.time = as.POSIXct(dat$date.time, format="%Y/%m/%d %H:%M:%S")

# now start creating the TDR dive object
filename = "Divedata"
  
# Choose a depth threshold (in m) and time threshold (in sec) to define a dive
# The time threshold is used to filter dives after DiveMove calculated dives.
depth.threshold = 3
  
tdr <- createTDR(time = dat$date.time, 
                   depth = dat$depth, 
                   speed = FALSE, 
                   dtime = 1,   #  sampling interval used in seconds
                   file = filename)
  
show(tdr)
  
# start detecting individual dives
tdr.calib <- calibrateDepth(tdr,
                              dive.thr = depth.threshold, # only select dives deeper than threshold
                              zoc.method='filter',
                              k=c(3, 5760),
                              probs=c(0.5, 0.02),
                              dry.thr=3600, 
                              wet.thr=60*5, 
                              interp.wet=FALSE, 
                              smooth.par=0.1,
                              knot.factor=20, 
                              descent.crit.q=0.01, ascent.crit.q=0.01,
                              na.rm=T)
  
tdr.dat = as.data.frame(tdr.calib@tdr)
head(tdr.dat)
  
# create dive summary metrics for each dive 
dive.stats <- diveStats(tdr.calib)        
head(dive.stats)
  
nrow(dive.stats)

test_input_fine2.csv
test_input2.csv

Progress Bar?

Hi again, last one!
Would it be possible to add a progress bar for whatever work is done after "n dives detected" is printed? Maybe this is just me and my big files but I figure I can't be the only one with archival tag data.

Thanks!

Error in diveStats when there are no dives

If you run diveStats on a tdr that doesn't have any dives you get the following error:
Error in do.call(rbind, by(td, dids, oneDiveStats, interval = interval)) : second argument must be a list

[Note: traceback doesn't provide a useful stack]

This code reproduces the error:

library('diveMove')
raw <- data.frame(time = seq(as.POSIXct('2015-09-25 09:00:01', tz = 'UTC'), 
                             as.POSIXct('2015-09-25 09:00:10', tz = 'UTC'), 
                             by = 'sec'), 
                  depth = 0)
tdr <- createTDR(raw$time, 
                 raw$depth, 
                 dtime = 1,
                 file = 'none')
calib <- calibrateDepth(tdr, 
                        wet.thr = .5, 
                        dive.thr = .5,
                        zoc.method = 'offset', 
                        offset = 0)
diveStats(calib)

This may seem like an esoteric error, but it becomes important when analyzing tags that record pressure in bursts. For example, CEFAS tags can be programmed to take .1s readings only when the tag is wet. It's impossible (I think) to use diveMove to analyze the entire data set when the records are in scattered pulses. Instead, it's easier to treat each burst as a separate unit for analysis. A non-trivial number of these records will have no dives in them.

I'm using try-catch as a workaround, but this seems like a bug worth fixing internally. Thanks for your good work - diveMove is a fantastic package!

calibrateDepth() error with `dive.model="unimodal"`

I have a file of 377882 rows of observations every 2 minutes.
With dive.thr=3 knot.factor = 20:

Record is truncated at the beginning and at the end
1 phases detected
5628 dives detected
Error: cannot allocate vector of size 87.2 Gb

With dive.thr=10 knot.factor = 3 (same dataset)

16667 dives detected
Error in validObject(.Object) : invalid class “diveModel” object: invalid object
for slot "ascent.crit" in class "diveModel": got class "logical", should be or
extend class "numeric"

I arbitrarily subsetted my data into just the first 43200 rows and that worked (same parameter settings, 3880 dives detected). But I'm hoping to loop through all my files (up to 400 eventually), some of which are even bigger. Can you think of a way around this big vector issue? If I loop createTDR and calibrateDepth through chunks of each file (e.g. a week of data at a time), that will break any dives going across those splits (not a HUGE problem but slightly annoying) but also the dive.id numbers will reset. Probably something I can code around.

https://drive.google.com/open?id=1Yfh92zXmI1ApPYohenDcCWSuLloyOpFe

Link to example above, then

tdrX <- createTDR(time = dfidedupe$DateTimeUTCmin5, depth = dfidedupe$Depth.m., dtime = 120, file = "divemovebigfile")
dcalib <- calibrateDepth(tdrX, dive.thr = 10,  zoc.method = "offset", offset = 0, knot.factor = 3)

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.