IO API
read_nwb(path, mode='a', return_io=False)
Read an NWB file.
Parameters:
-
path(str) –Path to the NWB file.
-
mode(str, default:'a') –File read mode (i.e. read/write/append). Defaults to "a".
-
return_io(bool, default:False) –Return IO object alongside the NWB file object. Defaults to False.
Returns:
-
NWBFile(NWBFile | tuple[NWBFile, NWBHDF5IO]) –NWB file object.
-
NWBHDF5IO(NWBFile | tuple[NWBFile, NWBHDF5IO]) –IO object (if return_io=True).
Source code in src/mesoscopy/io.py
write_nwb(path, nwbfile, mode='w', io=None, **kwargs)
Write an NWB file.
Parameters:
-
path(str) –Path to the NWB file.
-
nwbfile(NWBFile) –NWB file object.
-
mode(str, default:'w') –File write mode (i.e. write/append). Defaults to "w".
-
io(NWBHDF5IO, default:None) –An already open IO object to write through. When given, the file is not reopened and
pathandmodeare ignored. Defaults to None. -
**kwargs(Any, default:{}) –Parameters passed to NWBHDF5IO.write.
Source code in src/mesoscopy/io.py
read_h5(path)
Read an HDF5 file.
Parameters:
-
path(str) –Path to the HDF5 file.
Returns:
-
File–h5py.File: HDF5 file object.
write_h5(path, data, compression='lzf', attributes={})
Write a dictionary to an HDF5 file.
Parameters:
-
path(str) –Path to the HDF5 file.
-
data(dict) –Dictionary containing datasets to write in {'dataset_name': data_array} format.
-
compression(str, default:'lzf') –Compression method for the datasets. Defaults to "lzf".
-
attributes(dict, default:{}) –Attributes to write to the HDF5 file. Defaults to {}.
Returns:
-
str(str) –Path to the written HDF5 file.
Example
data = {"dataset1": np.array([1, 2, 3]), "dataset2": np.array([[1, 2], [3, 4]])} write_h5("output.h5", data)
Source code in src/mesoscopy/io.py
write_npz(path, data)
Write a dictionary to an NPZ file.
Parameters:
-
path(str) –Path to the NPZ file.
-
data(dict) –Dictionary containing arrays to write in {'array_name': array} format.
Returns:
-
str(str) –Path to the written NPZ file.
Example
data = {"array1": np.array([1, 2, 3]), "array2": np.array([[1, 2], [3, 4]])} write_npz("output.npz", data)
Source code in src/mesoscopy/io.py
store_interim(array, interim_path, compute=True, chunks=500)
Store an array in an interim Zarr file.
Parameters:
-
array(Dask or Numpy Array) –Dask or Numpy array to persist on disk.
-
interim_path(str) –Path to the interim Zarr file. The .zarr extension is added automatically.
-
compute(bool, default:True) –Whether to compute the array before storing, applies only to Dask arrays. Defaults to True.
-
chunks(int, default:500) –Chunk size for the Zarr file. Defaults to 500.
Returns:
-
Array–Zarr Array: Persistent Zarr array object
Source code in src/mesoscopy/io.py
load_deltaf(path, nwb=False)
Load preprocessed dF/F from an HDF5 or NWB file.
Parameters:
-
path(str) –Path to the preprocessed file.
-
nwb(bool, default:False) –Whether the file is an NWB file. Defaults to False.
Returns:
-
tuple[str, ndarray, ndarray]–tuple[str, np.ndarray, np.ndarray]: Session identifier, dF/F series, and timestamps.
Source code in src/mesoscopy/io.py
read_points(path)
Read a landmark points file.
Coordinates are read as (x, y) tuples, i.e. (column, row).
Parameters:
-
path(str) –Path to the points file.
Returns:
-
dict[str, tuple[float, float]]–dict[str, tuple[float, float]]: Dictionary with the landmark names as keys and their (x, y) coordinates
Raises:
-
ValueError–If the file format is unsupported.
Source code in src/mesoscopy/io.py
read_regressors(path)
Read a regressor file in NPZ or HDF5 format.
Parameters:
-
path(str) –Path to the regressor file.
Returns:
-
tuple[ndarray, list[str], ndarray]–tuple[np.ndarray, list[str], np.ndarray]: Regressor matrix, list of regressor labels, and trial indexes.
Raises:
-
ValueError–If the file format is unsupported.
Source code in src/mesoscopy/io.py
read_nuisance_regressors(path)
Read an external nuisance regressor file in NPZ or HDF5 format.
Parameters:
-
path(str) –Path to the nuisance regressor file.
Returns:
-
ndarray–tuple[np.ndarray, list[str], np.ndarray]: Nuisance regressor matrix of shape (n_samples, n_regressors),
-
list[str]–list of regressor labels, and the timestamps (n_samples,) the regressors were recorded at.
Raises:
-
ValueError–If the file format is unsupported.
Source code in src/mesoscopy/io.py
write_points(path, points)
Write a dictionary of landmark points to a CSV file.
Coordinates are written as (x, y) tuples, i.e. (column, row).
Parameters:
-
path(str) –Path to output CSV file.
-
points(dict[str, tuple[float, float]]) –Dictionary with the landmark names as keys and their (x, y) coordinates