cogpy.io.ecog_io

ECoG file I/O: load, save, and convert grid ECoG recordings.

Note

Lab-internal module. Assumes the binary .dat + XML metadata layout used in the Bhatt Lab. Not part of the stable public API — external users should prefer cogpy.io.converters.

Provides helpers that read raw binary (.dat) and Zarr files into xarray.DataArray objects with standardised (AP, ML, time) dimensions and an fs attribute. Large files are loaded as dask-backed arrays so they stay out of RAM until needed.

Matrix convention note

Python (C-order / row-major) stacks as (AP, ML):

sigx_flat = sigx.stack(ch=("AP", "ML"))   # time, ch=(AP, ML)

MATLAB (F-order / column-major) stacks as (ML, AP):

sigx_flat = sigx.stack(ch=("ML", "AP"))   # time, ch=(ML, AP)

Functions that accept external arrays (e.g. from_arr()) let you specify axis indices so both conventions are handled.

Functions

assert_ecog(sigx)

Validate that sigx has the expected ECoG schema (dims + fs).

da_to_zarr(output_file, sigx, **kwargs)

Write a DataArray to Zarr with a dask progress bar.

ds_to_zarr(output_file, ds, **kwargs)

Write a Dataset to Zarr with a dask progress bar.

from_arr(arr, time_ax, ap_ax, ml_ax)

Converts a numpy array to an xarray.DataArray and selects a time slice.

from_file(dat_file[, xml_file, metadata, ...])

Creates a memory-mapped (dask) array from a .dat file, reshaped to (num_channels, num_samples).

load_ecog_npix(DATA_FILE, XML_FILE, ...[, ...])

Load a combined ECoG + Neuropixels binary and split into two arrays.

oephys_load(directory[, nsamples])

Load the first nsamples from an Open Ephys recording directory.

save_dat(arr, dat_file[, extension, dtype])

Save a NumPy array to a flat binary .dat file.

separate_ecog_npix(DATA_FILE, XML_FILE, ...)

Split a combined ECoG + Neuropixels file and save each to Zarr.

to_zarr(output_file, obj, **kwargs)

Write a DataArray or Dataset to Zarr (dispatches by type).

zarr_to_dat(zarr_file, dat_file)

Convert a Zarr ECoG file to flat binary .dat.