<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><title>Find Profiles Within a Tow-Yow ctd Record — ctdFindProfiles • oce</title><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"><script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/font-awesome-6.4.2/css/all.min.css" rel="stylesheet"><link href="../deps/font-awesome-6.4.2/css/v4-shims.min.css" rel="stylesheet"><script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Find Profiles Within a Tow-Yow ctd Record — ctdFindProfiles"><meta name="description" content="Examine the pressure record looking for extended periods of either ascent or descent, and return
either indices to these events or a vector of CTD records containing the events."><meta property="og:description" content="Examine the pressure record looking for extended periods of either ascent or descent, and return
either indices to these events or a vector of CTD records containing the events."></head><body>
    <a href="#main" class="visually-hidden-focusable">Skip to contents</a>


    <nav class="navbar navbar-expand-lg fixed-top bg-light" data-bs-theme="light" aria-label="Site navigation"><div class="container">

    <a class="navbar-brand me-2" href="../index.html">oce</a>

    <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">1.8-4</small>


    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div id="navbar" class="collapse navbar-collapse ms-3">
      <ul class="navbar-nav me-auto"><li class="active nav-item"><a class="nav-link" href="../reference/index.html">Reference</a></li>
<li class="nav-item dropdown">
  <button class="nav-link dropdown-toggle" type="button" id="dropdown-articles" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Articles</button>
  <ul class="dropdown-menu" aria-labelledby="dropdown-articles"><li><a class="dropdown-item" href="../articles/A_oce.html">1. Introduction to Oce</a></li>
    <li><a class="dropdown-item" href="../articles/B_ctd.html">2. Analysis of CTD data</a></li>
    <li><a class="dropdown-item" href="../articles/C_adp.html">3. Analysis of acoustic-Doppler data</a></li>
    <li><a class="dropdown-item" href="../articles/D_map_projections.html">4. Using map projections</a></li>
    <li><a class="dropdown-item" href="../articles/E_flags.html">5. Dealing with data-quality flags</a></li>
    <li><a class="dropdown-item" href="../articles/F_subclassing.html">6. Subclassing oce objects</a></li>
    <li><a class="dropdown-item" href="../articles/G_altering_defaults.html">7. Altering oce Defaults</a></li>
    <li><a class="dropdown-item" href="../articles/H_tides.html">8. Tidal Analysis</a></li>
  </ul></li>
<li class="nav-item"><a class="nav-link" href="../news/index.html">Changelog</a></li>
      </ul><ul class="navbar-nav"><li class="nav-item"><form class="form-inline" role="search">
 <input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="../search.json"></form></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/dankelley/oce/" aria-label="GitHub"><span class="fa fab fa-github fa-lg"></span></a></li>
      </ul></div>


  </div>
</nav><div class="container template-reference-topic">
<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">

      <h1>Find Profiles Within a Tow-Yow ctd Record</h1>
      <small class="dont-index">Source: <a href="https://github.com/dankelley/oce/blob/HEAD/R/ctd.R" class="external-link"><code>R/ctd.R</code></a></small>
      <div class="d-none name"><code>ctdFindProfiles.Rd</code></div>
    </div>

    <div class="ref-description section level2">
    <p>Examine the pressure record looking for extended periods of either ascent or descent, and return
either indices to these events or a vector of CTD records containing the events.</p>
    </div>

    <div class="section level2">
    <h2 id="ref-usage">Usage<a class="anchor" aria-label="anchor" href="#ref-usage"></a></h2>
    <div class="sourceCode"><pre class="sourceCode r"><code><span><span class="fu">ctdFindProfiles</span><span class="op">(</span></span>
<span>  <span class="va">x</span>,</span>
<span>  cutoff <span class="op">=</span> <span class="fl">0.5</span>,</span>
<span>  minLength <span class="op">=</span> <span class="fl">10</span>,</span>
<span>  <span class="va">minHeight</span>,</span>
<span>  smoother <span class="op">=</span> <span class="va">smooth.spline</span>,</span>
<span>  direction <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"descending"</span>, <span class="st">"ascending"</span><span class="op">)</span>,</span>
<span>  <span class="va">breaks</span>,</span>
<span>  arr.ind <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>  <span class="va">distinct</span>,</span>
<span>  debug <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/options.html" class="external-link">getOption</a></span><span class="op">(</span><span class="st">"oceDebug"</span><span class="op">)</span>,</span>
<span>  <span class="va">...</span></span>
<span><span class="op">)</span></span></code></pre></div>
    </div>

    <div class="section level2">
    <h2 id="arguments">Arguments<a class="anchor" aria-label="anchor" href="#arguments"></a></h2>


<dl><dt id="arg-x">x<a class="anchor" aria-label="anchor" href="#arg-x"></a></dt>
<dd><p>a <a href="ctd-class.html">ctd</a> object.</p></dd>


<dt id="arg-cutoff">cutoff<a class="anchor" aria-label="anchor" href="#arg-cutoff"></a></dt>
<dd><p>criterion on pressure difference; see “Details”. If not
provided, this defaults to 0.5.</p></dd>


<dt id="arg-minlength">minLength<a class="anchor" aria-label="anchor" href="#arg-minlength"></a></dt>
<dd><p>lower limit on number of points in candidate profiles. If
not
provided, this defaults to 10.</p></dd>


<dt id="arg-minheight">minHeight<a class="anchor" aria-label="anchor" href="#arg-minheight"></a></dt>
<dd><p>lower limit on height of candidate profiles. If not
provided, this defaults to 0.1 times the pressure span.</p></dd>


<dt id="arg-smoother">smoother<a class="anchor" aria-label="anchor" href="#arg-smoother"></a></dt>
<dd><p>The smoothing function to use for identifying down/up
casts. The default is <code>smooth.spline</code>, which performs well for
a small number of cycles; see “Examples” for a method that is
better for a long tow-yo. The return value from <code>smoother</code> must
be either a list containing an element named <code>y</code> or something
that can be coerced to a vector with <code><a href="https://rdrr.io/r/base/vector.html" class="external-link">as.vector()</a></code>. To
turn smoothing off, so that cycles in pressure are determined by
simple first difference, set <code>smoother</code> to <code>NULL</code>.</p></dd>


<dt id="arg-direction">direction<a class="anchor" aria-label="anchor" href="#arg-direction"></a></dt>
<dd><p>String indicating the travel direction to be selected.</p></dd>


<dt id="arg-breaks">breaks<a class="anchor" aria-label="anchor" href="#arg-breaks"></a></dt>
<dd><p>optional integer vector indicating the indices of last
datum in each profile stored within <code>x</code>. Thus, the first profile
in the return value will contain the <code>x</code> data from indices 1
to <code>breaks[1]</code>.  If <code>breaks</code> is given, then all
other arguments except <code>x</code> are ignored. Using <code>breaks</code>
is handy in cases where other schemes fail, or when the author
has independent knowledge of how the profiles are strung together
in <code>x</code>.</p></dd>


<dt id="arg-arr-ind">arr.ind<a class="anchor" aria-label="anchor" href="#arg-arr-ind"></a></dt>
<dd><p>logical value indicating whether the array indices should be
returned; the alternative is to return a vector of ctd objects.</p></dd>


<dt id="arg-distinct">distinct<a class="anchor" aria-label="anchor" href="#arg-distinct"></a></dt>
<dd><p>An optional string indicating how to identify profiles
by unique values. Use <code>"location"</code>
to find profiles by a change in longitude and latitude, or use the name of any
of item in the <code>data</code> slot in <code>x</code>. In these cases, all the
other arguments except <code>x</code> are ignored. However, if <code>distinct</code>
is not supplied, the other arguments are handled as described above.</p></dd>


<dt id="arg-debug">debug<a class="anchor" aria-label="anchor" href="#arg-debug"></a></dt>
<dd><p>an integer specifying whether debugging information is
to be printed during the processing. This is a general parameter that
is used by many <code>oce</code> functions. Generally, setting <code>debug=0</code>
turns off the printing, while higher values suggest that more information
be printed. If one function calls another, it usually reduces the value of
<code>debug</code> first, so that a user can often obtain deeper debugging
by specifying higher <code>debug</code> values.</p></dd>


<dt id="arg--">...<a class="anchor" aria-label="anchor" href="#arg--"></a></dt>
<dd><p>Optional extra arguments that are passed to the smoothing function, <code>smoother</code>.</p></dd>

</dl></div>
    <div class="section level2">
    <h2 id="value">Value<a class="anchor" aria-label="anchor" href="#value"></a></h2>
    <p>If <code>arr.ind=TRUE</code>, a data frame with columns <code>start</code> and <code>end</code>, the indices
of the downcasts.  Otherwise, a vector of <code>ctd</code> objects. In this second case,
the station names are set to a form like <code>"10/3"</code>, for the third profile within an
original ctd object with station name <code>"10"</code>, or to <code>"3"</code>, if the original
ctd object had no station name defined.</p>
    </div>
    <div class="section level2">
    <h2 id="details">Details<a class="anchor" aria-label="anchor" href="#details"></a></h2>
    <p>The method works by examining the pressure record.  First, this is smoothed using
<code>smoother()</code> (see “Arguments”), and then the result is first-differenced
using <code><a href="https://rdrr.io/r/base/diff.html" class="external-link">diff()</a></code>.  Median values of the positive and
negative first-difference values are then multiplied by <code>cutoff</code>.  This establishes criteria
for any given point to be in an ascending profile, a descending profile, or a non-profile.
Contiguous regions are then found, and those that have fewer than <code>minLength</code> points are
discarded.  Then, those that have pressure ranges less than <code>minHeight</code> are discarded.</p>
<p>Caution: this method is not well-suited to all datasets. For example, the default
value of <code>smoother</code> is <code><a href="https://rdrr.io/r/stats/smooth.spline.html" class="external-link">smooth.spline()</a></code>, 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 (see “Examples”). Also, depending
on the sampling protocol, it is often necessary to pass the resultant profiles through
<code><a href="ctdTrim.html">ctdTrim()</a></code>, to remove artifacts such as an equilibration phase, etc.
Generally, one is well-advised to use the present function for a quick look at the data,
relying on e.g. <code><a href="plotScan.html">plotScan()</a></code> to identify profiles visually, for a final product.</p>
    </div>
    <div class="section level2">
    <h2 id="sample-of-usage">Sample of Usage<a class="anchor" aria-label="anchor" href="#sample-of-usage"></a></h2>


<div class="sourceCode"><pre><code><span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://dankelley.github.io/oce/">oce</a></span><span class="op">)</span></span>
<span><span class="co"># These examples cannot be tested, because they are based on</span></span>
<span><span class="co"># data objects that are not provided with oce.</span></span>
<span></span>
<span><span class="co"># Example 1. Find profiles within a towyo file, as can result</span></span>
<span><span class="co"># if the CTD is cycled within the water column as the ship</span></span>
<span><span class="co"># moves.</span></span>
<span><span class="va">profiles</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/ctdFindProfiles.html">ctdFindProfiles</a></span><span class="op">(</span><span class="va">towyo</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Example 2. Use a moving average to smooth pressure, instead of the</span></span>
<span><span class="co"># default smooth.spline() method. This might avoid a tendency of</span></span>
<span><span class="co"># the default scheme to miss some profiles in a long towyo.</span></span>
<span><span class="va">movingAverage</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">x</span>, <span class="va">n</span> <span class="op">=</span> <span class="fl">11</span>, <span class="va">...</span><span class="op">)</span></span>
<span><span class="op">{</span></span>
<span>    <span class="va">f</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/rep.html" class="external-link">rep</a></span><span class="op">(</span><span class="fl">1</span><span class="op">/</span><span class="va">n</span>, <span class="va">n</span><span class="op">)</span></span>
<span>    <span class="fu">stats</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/r/stats/filter.html" class="external-link">filter</a></span><span class="op">(</span><span class="va">x</span>, <span class="va">f</span>, <span class="va">...</span><span class="op">)</span></span>
<span><span class="op">}</span></span>
<span><span class="va">casts</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/ctdFindProfiles.html">ctdFindProfiles</a></span><span class="op">(</span><span class="va">towyo</span>, smoother<span class="op">=</span><span class="va">movingAverage</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Example 3: glider data read into a ctd object. Chop</span></span>
<span><span class="co"># into profiles by looking for pressure jumps exceeding</span></span>
<span><span class="co"># 10 dbar.</span></span>
<span><span class="va">breaks</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/diff.html" class="external-link">diff</a></span><span class="op">(</span><span class="va">gliderAsCtd</span><span class="op">[[</span><span class="st">"pressure"</span><span class="op">]</span><span class="op">]</span><span class="op">)</span> <span class="op">&gt;</span> <span class="fl">10</span><span class="op">)</span></span>
<span><span class="va">profiles</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/ctdFindProfiles.html">ctdFindProfiles</a></span><span class="op">(</span><span class="va">gliderAsCtd</span>, breaks<span class="op">=</span><span class="va">breaks</span><span class="op">)</span></span></code></pre></div>

    </div>
    <div class="section level2">
    <h2 id="see-also">See also<a class="anchor" aria-label="anchor" href="#see-also"></a></h2>
    <div class="dont-index"><p>The documentation for <a href="ctd-class.html">ctd</a> explains the structure
of CTD objects, and also outlines the other functions dealing with them.</p>
<p>Other things related to ctd data:
<code><a href="CTD_BCD2014666_008_1_DN.ODF.gz.html">CTD_BCD2014666_008_1_DN.ODF.gz</a></code>,
<code><a href="sub-sub-ctd-method.html">[[,ctd-method</a></code>,
<code>[[&lt;-,ctd-method</code>,
<code><a href="as.ctd.html">as.ctd</a>()</code>,
<code><a href="cnvName2oceName.html">cnvName2oceName</a>()</code>,
<code><a href="ctd.html">ctd</a></code>,
<code><a href="ctd-class.html">ctd-class</a></code>,
<code><a href="ctd.cnv.gz.html">ctd.cnv.gz</a></code>,
<code><a href="ctdDecimate.html">ctdDecimate</a>()</code>,
<code><a href="ctdFindProfilesRBR.html">ctdFindProfilesRBR</a>()</code>,
<code><a href="ctdRaw.html">ctdRaw</a></code>,
<code><a href="ctdRepair.html">ctdRepair</a>()</code>,
<code><a href="ctdTrim.html">ctdTrim</a>()</code>,
<code><a href="ctd_aml_type1.csv.gz.html">ctd_aml_type1.csv.gz</a></code>,
<code><a href="ctd_aml_type3.csv.gz.html">ctd_aml_type3.csv.gz</a></code>,
<code><a href="d200321-001.ctd.gz.html">d200321-001.ctd.gz</a></code>,
<code><a href="d201211_0011.cnv.gz.html">d201211_0011.cnv.gz</a></code>,
<code><a href="handleFlags-ctd-method.html">handleFlags,ctd-method</a></code>,
<code><a href="initialize-ctd-method.html">initialize,ctd-method</a></code>,
<code><a href="initializeFlagScheme-ctd-method.html">initializeFlagScheme,ctd-method</a></code>,
<code><a href="oceNames2whpNames.html">oceNames2whpNames</a>()</code>,
<code><a href="oceUnits2whpUnits.html">oceUnits2whpUnits</a>()</code>,
<code><a href="plot-ctd-method.html">plot,ctd-method</a></code>,
<code><a href="plotProfile.html">plotProfile</a>()</code>,
<code><a href="plotScan.html">plotScan</a>()</code>,
<code><a href="plotTS.html">plotTS</a>()</code>,
<code><a href="read.ctd.html">read.ctd</a>()</code>,
<code><a href="read.ctd.aml.html">read.ctd.aml</a>()</code>,
<code><a href="read.ctd.itp.html">read.ctd.itp</a>()</code>,
<code><a href="read.ctd.odf.html">read.ctd.odf</a>()</code>,
<code><a href="read.ctd.odv.html">read.ctd.odv</a>()</code>,
<code><a href="read.ctd.saiv.html">read.ctd.saiv</a>()</code>,
<code><a href="read.ctd.sbe.html">read.ctd.sbe</a>()</code>,
<code><a href="read.ctd.ssda.html">read.ctd.ssda</a>()</code>,
<code><a href="read.ctd.woce.html">read.ctd.woce</a>()</code>,
<code><a href="read.ctd.woce.other.html">read.ctd.woce.other</a>()</code>,
<code><a href="setFlags-ctd-method.html">setFlags,ctd-method</a></code>,
<code><a href="subset-ctd-method.html">subset,ctd-method</a></code>,
<code><a href="summary-ctd-method.html">summary,ctd-method</a></code>,
<code><a href="woceNames2oceNames.html">woceNames2oceNames</a>()</code>,
<code><a href="woceUnit2oceUnit.html">woceUnit2oceUnit</a>()</code>,
<code><a href="write.ctd.html">write.ctd</a>()</code></p></div>
    </div>
    <div class="section level2">
    <h2 id="author">Author<a class="anchor" aria-label="anchor" href="#author"></a></h2>
    <p>Dan Kelley and Clark Richards</p>
    </div>

  </main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
    </nav></aside></div>


    <footer><div class="pkgdown-footer-left">
  <p>Developed by Dan Kelley, Clark Richards.</p>
</div>

<div class="pkgdown-footer-right">
  <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.1.0.9000.</p>
</div>

    </footer></div>





  </body></html>

