Skip to content

Commit

Permalink
Added option to not output the spike traces
Browse files Browse the repository at this point in the history
Because they can be very heavy
  • Loading branch information
DradeAW committed Feb 26, 2024
1 parent 344f148 commit d80aa4c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/MEArec/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def save_template_generator(tempgen, filename=None, verbose=True):
print("\nSaved templates in", filename, "\n")


def save_recording_generator(recgen, filename=None, verbose=False):
def save_recording_generator(recgen, filename=None, verbose=False, include_spike_traces: bool = True):
"""
Save recordings to disk.
Expand All @@ -572,6 +572,8 @@ def save_recording_generator(recgen, filename=None, verbose=False):
Path to .h5 file
verbose : bool
If True output is verbose
include_spike_traces: bool, default=True
If True, will include the spike traces (can be heavy)
"""
filename = Path(filename)
if not filename.parent.is_dir():
Expand All @@ -580,12 +582,12 @@ def save_recording_generator(recgen, filename=None, verbose=False):
with h5py.File(filename, "w") as f:
f.attrs["mearec_version"] = mearec_version
f.attrs["date"] = datetime.now().strftime("%y-%m-%d %H:%M:%S")
save_recording_to_file(recgen, f)
save_recording_to_file(recgen, f, include_spike_traces=include_spike_traces)
if verbose:
print("\nSaved recordings in", filename, "\n")


def save_recording_to_file(recgen, f, path=""):
def save_recording_to_file(recgen, f, path="", include_spike_traces: bool = True):
"""
Save recordings to file handler.
Expand All @@ -595,6 +597,8 @@ def save_recording_to_file(recgen, f, path=""):
RecordingGenerator object to be saved
filename : _io.TextIOWrapper
File handler
include_spike_traces: bool, default=True
If True, will include the spike traces (can be heavy)
"""
save_dict_to_hdf5(recgen.info, f, path + "info/")
if len(recgen.voltage_peaks) > 0:
Expand All @@ -605,7 +609,7 @@ def save_recording_to_file(recgen, f, path=""):
f.create_dataset(path + "recordings", data=recgen.recordings)
if recgen.gain_to_uV is not None:
f["recordings"].attrs["gain_to_uV"] = recgen.gain_to_uV
if len(recgen.spike_traces) > 0:
if len(recgen.spike_traces) > 0 and include_spike_traces:
f.create_dataset(path + "spike_traces", data=recgen.spike_traces)
if len(recgen.spiketrains) > 0:
for ii in range(len(recgen.spiketrains)):
Expand Down

0 comments on commit d80aa4c

Please sign in to comment.