| Title: | Read and Export Tucker-Davis Technologies Data from R |
|---|---|
| Description: | Provides an R interface for reading Tucker-Davis Technologies (TDT) tank/block data through the Python 'tdt' package with reticulate, including Python-backed wrappers and explicit helpers for collecting data into ordinary R objects for downstream analysis. |
| Authors: | John Lee [aut, cre] |
| Maintainer: | John Lee <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.5 |
| Built: | 2026-05-19 16:52:52 UTC |
| Source: | https://github.com/nimh-dsst/tdtr |
tdt rangesPython tdt expects a 2 x N numeric matrix where row 1 is start time and
row 2 is stop time.
as_ranges(ranges)as_ranges(ranges)
ranges |
A numeric length-2 vector, a |
A numeric 2 x N matrix.
Coerce to a materialized TDT block
as_tdt_block(x, ...)as_tdt_block(x, ...)
x |
A |
... |
Passed to |
A materialized tdt_block.
Return epocs/events as a tibble
as_tibble_epocs(x, store = NULL)as_tibble_epocs(x, store = NULL)
x |
A |
store |
Optional epoc store name. |
A tibble with store, onset, offset, and value columns.
Return a bounded stream table
as_tibble_stream(x, stream, window = NULL, downsample = NULL, max_rows = NULL)as_tibble_stream(x, stream, window = NULL, downsample = NULL, max_rows = NULL)
x |
A |
stream |
Stream name. |
window |
Optional length-2 time window in seconds. |
downsample |
Optional integer stride. |
max_rows |
Optional maximum rows to return. |
A tibble with time, channel, and value columns.
Return block metadata
block_info(x)block_info(x)
x |
A |
A named list.
Collect a Python-backed TDT block into R
collect_block( x, streams = TRUE, epocs = TRUE, snips = FALSE, scalars = FALSE, stores = NULL, max_bytes_warn = 500 * 1024^2, quiet = FALSE )collect_block( x, streams = TRUE, epocs = TRUE, snips = FALSE, scalars = FALSE, stores = NULL, max_bytes_warn = 500 * 1024^2, quiet = FALSE )
x |
A |
streams |
If |
epocs |
If |
snips, scalars
|
Reserved for future collection of Python |
stores |
Optional stream names to collect. |
max_bytes_warn |
Warn before copying a Python array larger than this many bytes. |
quiet |
Suppress size warnings. |
A materialized tdt_block.
Collect epocs/events into R
collect_epocs(x, store = NULL, as = c("tibble", "list"))collect_epocs(x, store = NULL, as = c("tibble", "list"))
x |
A |
store |
Optional epoc store name. If |
as |
Return shape: |
A tibble or named list of tibbles.
Collect one stream into R
collect_stream( x, store, as = c("matrix", "numeric", "list"), include_time = FALSE, max_bytes_warn = 500 * 1024^2, quiet = FALSE )collect_stream( x, store, as = c("matrix", "numeric", "list"), include_time = FALSE, max_bytes_warn = 500 * 1024^2, quiet = FALSE )
x |
A |
store |
Stream store name. The sanitized Python key or original TDT store name may be used. |
as |
Return shape: |
include_time |
If |
max_bytes_warn |
Warn before copying a Python array larger than this many bytes. |
quiet |
Suppress size warnings. |
A matrix, numeric vector, or stream metadata list.
Return one epoc/event store
epoc(x, store)epoc(x, store)
x |
A |
store |
Epoc store name. |
One epoc object or tibble subset.
tdt
Filter TDT epocs through Python tdt
epoc_filter_py( data, epoc, values = NULL, modifiers = NULL, t = NULL, tref = FALSE, keepdata = TRUE, ... )epoc_filter_py( data, epoc, values = NULL, modifiers = NULL, t = NULL, tref = FALSE, keepdata = TRUE, ... )
data |
A |
epoc |
Epoc store name. |
values, modifiers, t, tref, keepdata
|
Arguments passed to Python
|
... |
Additional keyword arguments passed to Python |
A tdt_block_py wrapper.
Return epoc/event store names
epoc_names(x)epoc_names(x)
x |
A |
A character vector of epoc store names.
Return the epoc/event container or rows
epocs(x, store = NULL)epocs(x, store = NULL)
x |
A |
store |
Optional epoc store name. |
For materialized blocks, a tibble. For Python-backed blocks with no
store, the live Python epocs container.
Test whether an object is a materialized TDT block
is_tdt_block(x)is_tdt_block(x)
x |
Object to test. |
TRUE if x inherits from tdt_block, otherwise FALSE.
Create a materialized TDT block
new_tdt_block(info = list(), streams = list(), epocs = NULL)new_tdt_block(info = list(), streams = list(), epocs = NULL)
info |
Named list of block metadata. |
streams |
Named list of stream objects. |
epocs |
Epoc/event table. If |
A tdt_block object.
profile_tdt_memory() runs a small read workflow and records elapsed time,
R allocations reported by Rprofmem(), and Python allocations reported by
Python tracemalloc when available. Use reader arguments such as store,
channel, t1, t2, evtype, and ranges to test a bounded workflow
before scaling up to a larger block.
profile_tdt_memory( block_path, ..., stream = NULL, events = TRUE, summarize = TRUE, quiet = TRUE )profile_tdt_memory( block_path, ..., stream = NULL, events = TRUE, summarize = TRUE, quiet = TRUE )
block_path |
Path to a TDT block directory. |
... |
Arguments passed to |
stream |
Optional stream store to collect after the read. Leave |
events |
If |
summarize |
If |
quiet |
Suppress collection size warnings. |
The numbers are diagnostics, not portable benchmarks. They are most useful for comparing alternative reads on the same machine and Python environment.
A tibble with one row per profiled step.
Build time ranges from epoc/event onsets
ranges_from_epocs(epocs, pre, post, onset_col = "onset", drop_negative = TRUE)ranges_from_epocs(epocs, pre, post, onset_col = "onset", drop_negative = TRUE)
epocs |
A data frame with an onset column. |
pre |
Start offset in seconds relative to onset. Use a negative value for time before onset. |
post |
Stop offset in seconds relative to onset. |
onset_col |
Name of the onset column. |
drop_negative |
If |
A numeric 2 x N matrix.
tdt
Read a TDT block through Python tdt
read_block(block_path, ..., collect = FALSE)read_block(block_path, ..., collect = FALSE)
block_path |
Path to a TDT block/tank directory. |
... |
Extra keyword arguments passed to |
collect |
If |
read_block() normalizes read-time store filters against the block
header, so the stream names returned by stream_names() can also be used for
filtering. This matters for TDT stores whose original names are not valid
Python identifiers. For example, Python tdt filters a store originally
named 465A with store = "465A", but the returned stream is exposed under
the sanitized name _465A. read_block() accepts either spelling. Use
read_block_py() when you need Python tdt.read_block() store matching
exactly as implemented upstream.
A tdt_block_py wrapper or a materialized tdt_block.
tdt
This is the explicit Python-backed compatibility wrapper for
tdt.read_block(). It keeps Python objects live and does not copy stream
arrays into R unless a collection helper is called later.
read_block_py( block_path, bitwise = "", channel = 0, combine = NULL, headers = 0, nodata = FALSE, ranges = NULL, store = "", t1 = 0, t2 = 0, evtype = NULL, verbose = 0, sortname = "TankSort", export = NULL, scale = 1, dtype = NULL, outdir = NULL, prefix = NULL, outfile = NULL, dmy = FALSE, noepocauto = FALSE, ... )read_block_py( block_path, bitwise = "", channel = 0, combine = NULL, headers = 0, nodata = FALSE, ranges = NULL, store = "", t1 = 0, t2 = 0, evtype = NULL, verbose = 0, sortname = "TankSort", export = NULL, scale = 1, dtype = NULL, outdir = NULL, prefix = NULL, outfile = NULL, dmy = FALSE, noepocauto = FALSE, ... )
block_path |
Path to a TDT block/tank directory. |
bitwise, channel, combine, headers, nodata, ranges, store, t1, t2, evtype, verbose, sortname, export, scale, dtype, outdir, prefix, outfile, dmy, noepocauto
|
Arguments passed to Python |
... |
Additional keyword arguments passed to Python |
read_block_py() passes store directly to Python tdt.read_block(). For
stores whose returned names are sanitized by Python, such as _465A, pass the
original TDT store ID (465A) or use read_block() for tdtr's
header-based normalization.
A tdt_block_py wrapper.
Read an epoc/event CSV export
read_epocs_csv(path, ...)read_epocs_csv(path, ...)
path |
CSV file path. |
... |
Passed to |
A tibble with store, onset, offset, and value columns.
tdt
Read TDT SEV data through Python tdt
read_sev_py( sev_dir, channel = 0, event_name = "", t1 = 0, t2 = 0, fs = 0, ranges = NULL, verbose = 0, just_names = FALSE, export = NULL, scale = 1, dtype = NULL, outdir = NULL, prefix = NULL, ... )read_sev_py( sev_dir, channel = 0, event_name = "", t1 = 0, t2 = 0, fs = 0, ranges = NULL, verbose = 0, just_names = FALSE, export = NULL, scale = 1, dtype = NULL, outdir = NULL, prefix = NULL, ... )
sev_dir |
Path to a SEV directory or file. |
channel, event_name, t1, t2, fs, ranges, verbose, just_names, export, scale, dtype, outdir, prefix
|
Arguments passed to Python |
... |
Additional keyword arguments passed to Python |
A tdt_sev_py wrapper.
Read a stream CSV export
read_stream_csv(path, fs, name, channels = NULL, t0 = 0, ...)read_stream_csv(path, fs, name, channels = NULL, t0 = 0, ...)
path |
CSV file path. |
fs |
Sampling frequency. |
name |
Stream name. |
channels |
Optional channel labels. |
t0 |
Stream start time in seconds. |
... |
Passed to |
A materialized stream object.
Return one stream
stream(x, name)stream(x, name)
x |
A |
name |
Stream name. The sanitized Python key or original TDT store name may be used. |
A stream object. For Python-backed blocks this is a live Python stream object and does not copy stream data into R.
Return stream names
stream_names(x)stream_names(x)
x |
A |
A character vector of stream names.
Return the stream container
streams(x)streams(x)
x |
A |
A stream container. For Python-backed objects this may be a live Python object and does not copy stream arrays into R.
tdt is availableCheck whether Python tdt is available
tdt_available(initialize = TRUE)tdt_available(initialize = TRUE)
initialize |
If |
TRUE if reticulate can find Python tdt, otherwise FALSE.
tdtr
Show Python configuration for tdtr
tdt_config(initialize = FALSE)tdt_config(initialize = FALSE)
initialize |
If |
A list with reticulate, Python, and Python tdt availability fields.
tdtr includes a small raw TDT block from the official TDT example data so
examples, tests, and vignettes can exercise the reticulate-backed reader.
The files are stored in the same block layout used by TDT, under
inst/extdata.
tdtr_example_block_path(mustWork = TRUE)tdtr_example_block_path(mustWork = TRUE)
mustWork |
If |
A single path to the packaged Subject1-211115-094936 block.
Validate a materialized TDT block
validate_tdt_block(x)validate_tdt_block(x)
x |
Object to validate. |
x, invisibly.