agora.io.writer.Writer

class Writer(filename, flag=None, compression='gzip')[source]

Bases: BridgeH5

Class to transform data into compatible structures.

Attributes
cell_tree
meta_h5

Return metadata, defining it if necessary.

Methods

close()

Close the h5 file.

find_ids(existing, new)

Compare two tuple sets and return the intersection and difference (elements in the 'new' set not in 'existing').

get_consecutives(tree, nstepsback)

Receives a sorted tree and returns the keys of consecutive elements.

get_existing_ids(f, paths)

Fetch indices and convert them to a (nentries, nlevels) ndarray.

get_info_tree([fields])

Return traps, time points and labels for this position in the form of a tree in the hierarchy determined by the argument fields.

write(path[, data, meta, overwrite])

Write data and metadata to a particular path in the h5 file.

write_arraylike(f, path, data, **kwargs)

Write an iterable.

write_dset(f, path, data)

Write data in different ways depending on its type to an open h5 file.

write_index(f, path, pd_index, **kwargs)

Write a multi-index dataframe.

write_meta(f, path, attr, data)

Write metadata to an open h5 file.

write_pd(f, path, df, **kwargs)

Write a dataframe.

get_npairs

get_npairs_over_time

Initialise write.

Parameters
filename: str

Name of file to write into

flag: str, default=None

Flag to pass to the default file reader. If None the file remains closed.

compression: str, default=”gzip”

Compression method passed on to h5py writing functions (only used for dataframes and other array-like data).

Attributes
cell_tree
meta_h5

Return metadata, defining it if necessary.

Methods

close()

Close the h5 file.

find_ids(existing, new)

Compare two tuple sets and return the intersection and difference (elements in the 'new' set not in 'existing').

get_consecutives(tree, nstepsback)

Receives a sorted tree and returns the keys of consecutive elements.

get_existing_ids(f, paths)

Fetch indices and convert them to a (nentries, nlevels) ndarray.

get_info_tree([fields])

Return traps, time points and labels for this position in the form of a tree in the hierarchy determined by the argument fields.

write(path[, data, meta, overwrite])

Write data and metadata to a particular path in the h5 file.

write_arraylike(f, path, data, **kwargs)

Write an iterable.

write_dset(f, path, data)

Write data in different ways depending on its type to an open h5 file.

write_index(f, path, pd_index, **kwargs)

Write a multi-index dataframe.

write_meta(f, path, attr, data)

Write metadata to an open h5 file.

write_pd(f, path, df, **kwargs)

Write a dataframe.

get_npairs

get_npairs_over_time

__init__(filename, flag=None, compression='gzip')[source]

Initialise write.

Parameters
filename: str

Name of file to write into

flag: str, default=None

Flag to pass to the default file reader. If None the file remains closed.

compression: str, default=”gzip”

Compression method passed on to h5py writing functions (only used for dataframes and other array-like data).

Methods

__init__(filename[, flag, compression])

Initialise write.

close()

Close the h5 file.

find_ids(existing, new)

Compare two tuple sets and return the intersection and difference (elements in the 'new' set not in 'existing').

get_consecutives(tree, nstepsback)

Receives a sorted tree and returns the keys of consecutive elements.

get_existing_ids(f, paths)

Fetch indices and convert them to a (nentries, nlevels) ndarray.

get_info_tree([fields])

Return traps, time points and labels for this position in the form of a tree in the hierarchy determined by the argument fields.

get_npairs([nstepsback, tree])

get_npairs_over_time([nstepsback])

write(path[, data, meta, overwrite])

Write data and metadata to a particular path in the h5 file.

write_arraylike(f, path, data, **kwargs)

Write an iterable.

write_dset(f, path, data)

Write data in different ways depending on its type to an open h5 file.

write_index(f, path, pd_index, **kwargs)

Write a multi-index dataframe.

write_meta(f, path, attr, data)

Write metadata to an open h5 file.

write_pd(f, path, df, **kwargs)

Write a dataframe.

Attributes

cell_tree

meta_h5

Return metadata, defining it if necessary.

close()

Close the h5 file.

static find_ids(existing, new)[source]

Compare two tuple sets and return the intersection and difference (elements in the ‘new’ set not in ‘existing’).

static get_consecutives(tree, nstepsback)

Receives a sorted tree and returns the keys of consecutive elements.

static get_existing_ids(f, paths)[source]

Fetch indices and convert them to a (nentries, nlevels) ndarray.

get_info_tree(fields=('trap', 'timepoint', 'cell_label'))

Return traps, time points and labels for this position in the form of a tree in the hierarchy determined by the argument fields.

Note that it is compressed to non-empty elements and timepoints.

Default hierarchy is: - trap - time point - cell label

This function currently produces trees of depth 3, but it can easily be extended for deeper trees if needed (e.g. considering groups, chambers and/or positions).

Parameters
fields: list of strs

Fields to fetch from ‘cell_info’ inside the h5 file.

Returns
Nested dictionary where keys (or branches) are the upper levels and the leaves are the last element of :fields:.
property meta_h5: Dict[str, Any]

Return metadata, defining it if necessary.

Return type

Dict[str, Any]

write(path, data=None, meta={}, overwrite=None)[source]

Write data and metadata to a particular path in the h5 file.

Parameters
pathstr

Path inside h5 file into which to write.

dataIterable, optional
metadict, optional
overwrite: str, optional
static write_arraylike(f, path, data, **kwargs)[source]

Write an iterable.

write_dset(f, path, data)[source]

Write data in different ways depending on its type to an open h5 file.

static write_index(f, path, pd_index, **kwargs)[source]

Write a multi-index dataframe.

write_meta(f, path, attr, data)[source]

Write metadata to an open h5 file.

write_pd(f, path, df, **kwargs)[source]

Write a dataframe.