Generic ALF I/O module. Provides support for time-series reading and interpolation as per the specifications For a full overview of the scope of the format, see:

class*args, **kwargs)
append(b, inplace=False)

Appends one bunch to another, key by key :param bunch: :return: Bunch


Attempts to returns a pandas.DataFrame if all elements are arrays of the same length Returns the original bunch if it can’t

Test for consistency of dimensions as per ALF specs in a dictionary. Raises a Value Error.

Alf broadcasting rules: only accepts consistent dimensions for a given axis a dimension is consistent with another if it’s empty, 1, or equal to the other arrays dims [a, 1], [1, b] and [a, b] are all consistent, [c, 1] is not

Parameters:dico – dictionary containing data
Returns:status 0 for consistent dimensions, 1 for inconsistent dimensions

Converts an Bunch conforming to size conventions into a pandas Dataframe For 2-D arrays, stops at 10 columns per attribute :return: pandas Dataframe, object, attributes=None, **kwargs)

Test if ALF object and optionally specific attributes exist in the given path :param alfpath: str or pathlib.Path of the folder to look into :param object: str ALF object name :param attributes: list or list of strings for wanted attributes :return: bool. For multiple attributes, returns True only if all attributes are found Union[str, pathlib.Path]) → pathlib.Path

Returns the session path from any filepath if the date/number pattern is found
Checks if the syntax corresponds to a session path. Note that there is no physical check
about existence nor contents
Returns: str) → bool

Bool test for uuid version 4

Returns content of files. Designed for very generic file formats: so far supported contents are json, npy, csv, tsv, ssv, jsonable

Parameters:fil – file to read

:return:array/json/pandas dataframe depending on format, object=None, short_keys=False, **kwargs)

Reads all files (ie. attributes) sharing the same object. For example, if the file provided to the function is spikes.times, the function will load spikes.time, spikes.clusters, spikes.depths, spike.amps in a dictionary whose keys will be time, clusters, depths, amps Full Reference here: Simplified example: _namespace_object.attribute_timescale.part1.part2.extension

  • alfpath – any alf file pertaining to the object OR directory containing files
  • object – if a directory is provided and object is None, all valid ALF files returned
  • short_keys – by default, the output dictionary keys will be compounds of attributes, timescale and any eventual parts separated by a dot. Use True to shorten the keys to the attribute and timescale.

a dictionary of all attributes pertaining to the object


# Load spikes object spikes =‘/path/to/my/alffolder/’, ‘spikes’)

# Load trials object under the ibl namespace trials =, ‘trials’, namespace=’ibl’)

Load time-series from ALF format t, d = alf.read_ts(filename), dry=False)

Renames a file without the UUID and returns the new pathlib.Path object, dry=False)

Within a folder, recursive renaming of all files to remove UUID, dico)

Writes a meta data file matching a current alf file object. For example given an alf file clusters.ccfLocation.ssv this will write a dictionary in json format in clusters.ccfLocation.metadata.json Reserved keywords:

  • columns: column names for binary tables.
  • row: row names for binary tables.
  • unit
  • file_alf – full path to the alf object
  • dico – dictionary containing meta-data.

None, dico, object, parts=None, namespace=None, timescale=None)

Saves a dictionary in alf format using object as object name and dictionary keys as attribute names. Dimensions have to be consistent. Reference here: Simplified example: _namespace_object.attribute.part1.part2.extension

  • alfpath – path of the folder to save data to
  • dico – dictionary to save to npy; keys correspond to ALF attributes
  • object – name of the object to save
  • parts – extra parts to the ALF name
  • namespace – the optional namespace of the object
  • timescale – the optional timescale of the object

List of written files

example:‘/path/to/my/alffolder/’, spikes, ‘spikes’)