Skip to main content

ProjectStatus Version BuildStatus License PythonVersions

arfx is a family of commandline tools for copying sampled data in and out of ARF containers. ARF (https://github.com/melizalab/arf) is an open, portable file format for storing behavioral and neural data, based on HDF5.

installation

pip install arfx

or from source:

python setup.py install

use

The general syntax is arfx operation [options] files. The syntax is similar to tar. Operations are as follows:

  • -A: copy data from one container to another

  • -c: create a new container

  • -r: append data to the container

  • -t: list contents of the container

  • -x: extract entries from the container

  • -d: delete entries from the container

Options specify the target ARF file, verbosity, automatic naming schemes, and any metadata to be stored in the entry. Some important options include:

  • -f FILE: use ARF file FILE

  • -v: verbose output

  • -n NAME: name entries sequentially, using NAME as the base

  • -k key=value add metadata to the entries. The value is read as JSON if it parses as JSON, and taken as a plain string if it does not, so -k pen=1 stores a number while -k bird=C194 stores a string. Quote a value to keep it a string when it would otherwise be a number: -k animal='"397"'.

  • -T DATATYPE: specify the type of data

input files

arfx can read sampled data from pcm, wave, npy and mda files. Support for additional file formats can be added as plugins (see 4).

When adding data to an ARF container (-c and -r modes), the input files are specified on the command line, and added in the order given. By default, entries are given the same name as the input file, minus the extension; however, if the input file has more than one entry, they are given an additional numerical extension. To override this, the -n flag can be used to specify the base name; all entries are given sequential names based on this.

The -n, -a, -e, -p, -s, -T options are used to store information about the data being added to the file. The DATATYPE argument can be the numerical code or enumeration code (run arfx --help-datatypes for a list), and indicates the type of data in the entries. All of the entries created in a single run of arfx are given these values. The -u option tells arfx not to compress the data, which can speed up I/O operations slightly.

Currently only one sampled dataset per entry is supported. Clearly this does not encompass many use cases, but arfx is intended as a simple tool. More specialized import procedures can be easily written in Python using the arf library.

output files

The entries to be extracted (in -x mode) can be specified by name. If no names are specified, all the entries are extracted. All sampled datasets in each entry are extracted as separate channels, because they may have different sampling rates. Event datasets are not extracted.

By default the output files will be in wave format and will have names with the format entry_channel.wav. The -n argument can be used to customize the names and file format of the output files. The argument must be a template in the format defined by the python string module. Supported field names include entry, channel, and index, as well as the names of any HDF5 attributes stored on the entry or channel. The extension of the output template is used to determine the file format. Currently only wave is supported, but additional formats may be supplied as plugins (see below).

The metadata options are ignored when extracting files; any metadata present in the ARF container that is also supported by the target container is copied.

other operations

As with tar, the -t operation will list the contents of the archive. Each entry/channel is listed on a separate line in path notation.

The -A flag is used to copy the contents of one ARF file to another. The entries are copied without modification from the source ARF file(s) to the target container.

The -d (delete) operation uses the same syntax as the extract operation, but instead of extracting the entries, they are deleted. Because of limitations in the underlying HDF5 library, this does not free up the space; pass the -P option to repack the file afterwards and reclaim it. Repacking requires h5repack on the path.

The -U (update) operation can be used to add or update attributes of entries.

The --write-attr operation can be used to store the contents of text files in top-level attributes. The attributes have the name user_<filename>. The --read-attr operation can be used to read out those attributes. This is useful when data collection programs generate log or settings files that you want to store in the ARF file.

other utilities

This package comes with a few additional scripts that do fairly specific operations.

arfx-split

This script is used to reorganize very large recordings, possibly contained in multiple files, into manageable chunks. Each new entry is given an updated timestamp and attributes from the source entries. Only sampled datasets are processed.

Entries that are contiguous on the sample timeline will be spliced back together before chunking as long as there some internal track of the sample count, such as the jack_frame attribute recorded by jrecord. This is an unsigned 32-bit value that wraps roughly every 27 hours at typical audio sampling rates, triggering the start of a new entry in the ARF file.

  • –no-splice: chunk each source entry separately, as before

  • –frame-attr NAME: use a different attribute as the frame counter

  • –max-overlap SAMPLES: splice entries that overlap by up to this many samples, dropping the duplicates (default 4096). The overlapping samples are compared first, and entries whose data disagree there are left unspliced and reported, since the counter and the data cannot both be right.

arfx-oephys

Converts the output of an open-ephys recording (open-ephys binary format) into an ARF file. open-ephys stores its data in a big complex directory tree, which this script will navigate and store in an appropriately timestamped entry in the ARF file. Has not been tested with data from outside our lab. Example invocation:

arfx-oephys -T EXTRAC_HP -k experimenter=smm3rc -k bird=C194 -k pen=1 -k site=1 -k protocol=chorus -f C194_1_1.arf C194_2023-10-16_16-30-54_chorus/

We typically run this command before starting spike sorting to create a copy of the recording for archival.

From GUI 0.6 on, a session directory may hold more than one experimentN/recordingM. Each becomes its own entry, named for the session and its place within it, and each is timestamped from the wall-clock time in its own sync_messages.txt rather than from the session directory name, which gives only the start of the first recording. Older recordings have one recording per directory and no wall-clock time recorded, so they take the timestamp from the directory name.

arfx-collect-sampled

This script is used to export data into a flat binary structure. It collects sampled data across channels and entries into a single 2-D array. The output can be stored in a multichannel wav file or in a raw binary dat format (N samples by M channels), which is used by a wide variety of spike-sorting tools. We use this script if we ever have to re-sort a recording after deleting the original raw recording.

arfx-select

This is a pretty specialized script that takes in a table of segments defined by entry name and start/stop time and copies them to a new ARF file. It’s usually better to just write analysis code to directly access the desired data from the original file, but it can be useful as a first stage in exporting small segments of a recording to wave files for sharing or depositing.

extending arfx

Additional formats for reading and writing can be added using the Python setuptools plugin system. Plugins must be registered in the arfx.io entry point group, with a name corresponding to the extension of the file format handled by the plugin.

An arfx IO plugin is a class with the following required methods:

__init__(path, mode, **attributes): Opens the file at path. The mode argument specifies whether the file is opened for reading (r), writing (w), or appending (a). Must throw an IOError if the file does not exist or cannot be created, and a ValueError if the specified value for mode is not supported. The additional attributes arguments specify metadata to be stored in the file when created. arfx will pass all attributes of the channel and entry (e.g., channels, sampling_rate, units, and datatype) when opening a file for writing. This method may issue a ValueError if the caller fails to set a required attribute, or attempts to set an attribute inconsistent with the data format. Unsupported attributes should be ignored.

read(): Reads the contents of the opened file and returns the data in a format suitable for storage in an ARF file. Specifically, it must be an acceptable type for the arf.entry.add_data() method (see https://github.com/melizalab/arf for documentation).

write(data): Writes data to the file. Must issue an IOError if the file is opened in the wrong mode, and TypeError if the data format is not correct for the file format.

timestamp: A readable property giving the time point of the data. The value may be a scalar indicating the number of seconds since the epoch, or a two-element sequence giving the number of seconds and microseconds since the epoch. If this property is writable it will be set by arfx when writing data.

sampling_rate: A property indicating the sampling rate of the data in the file (or current entry), in units of Hz.

The class may also define the following methods and properties. If any property is not defined, it is assumed to have the default value defined below.

nentries: A readable property indicating the number of entries in the file. Default value is 1.

entry: A readable and writable integer-valued property corresponding to the index of the currently active entry in the file. Active means that the read() and write() methods will affect only that entry. Default is 0, and arfx will not attempt to change the property if nentries is 1.

version information

arfx uses semantic versioning. Its major version tracks the major version of the arf library it requires, so arfx 3.x requires arf>=3.0.0,<4.

That is not the same as the version of the ARF specification. The arf library versions independently of the format it implements — arf 3.0.0 ships against specification 2.2 — so neither number can be derived from the other. The specification version a file claims is stored in its arf_version attribute, and arf.supported_spec_versions() reports the range the installed library will read.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arfx-3.0.0.tar.gz (41.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arfx-3.0.0-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

Details for the file arfx-3.0.0.tar.gz.

File metadata

  • Download URL: arfx-3.0.0.tar.gz
  • Upload date:
  • Size: 41.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for arfx-3.0.0.tar.gz
Algorithm Hash digest
SHA256 9356a02f263944a6f32ee2ebf45eb49e4227bfabc9deb768b938e8a7b5b7c781
MD5 8b072fae88d423d72409905a45ec386e
BLAKE2b-256 cd9637cd3fa59bc3c42d1066a51064102d15278d3fa3ecc431f14f095f4940d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for arfx-3.0.0.tar.gz:

Publisher: publish-to-pypi.yml on melizalab/arfx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file arfx-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: arfx-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 43.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for arfx-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4422bdf19f6cebced3e1bed2b913c762cf362bf633f022a004e472a5a9987765
MD5 81dd4dc8f7546868894a85f4d85888a8
BLAKE2b-256 b906950d8d48461391b0191740cb89353c0520713ae323c0dafb6f2af93633e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for arfx-3.0.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on melizalab/arfx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 files

2.8.1

2 files

2.8.0

2 files

2.7.1

2 files

2.7.0

2 files

2.6.16

2 files

2.6.15

2 files

2.6.14

2 files

2.6.13

2 files

2.6.12

2 files

2.6.11

2 files

2.6.9

2 files

2.6.7

1 file

2.6.5

2 files

2.6.4

2 files

2.2.8

2 files

2.2.7

2 files

2.2.6

3 files

2.2.5

1 file

2.2.4

1 file

2.2.3

1 file

2.2.2

1 file

2.2.1

1 file

2.2.0

1 file

2.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page