Skip to content

Commit

Permalink
Merge pull request #2041 from zm711/rel-path-phy
Browse files Browse the repository at this point in the history
Allow relative path for `export_to_phy`
  • Loading branch information
alejoe91 authored Sep 27, 2023
2 parents c9b3d4b + 119335c commit 3826a2d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/spikeinterface/exporters/to_phy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def export_to_phy(
template_mode: str = "median",
dtype: Optional[npt.DTypeLike] = None,
verbose: bool = True,
use_relative_path: bool = False,
**job_kwargs,
):
"""
Expand Down Expand Up @@ -64,6 +65,9 @@ def export_to_phy(
Dtype to save binary data
verbose: bool
If True, output is verbose
use_relative_path : bool, default: False
If True and `copy_binary=True` saves the binary file `dat_path` in the `params.py` relative to `output_folder` (ie `dat_path=r'recording.dat'`). If `copy_binary=False`, then uses a path relative to the `output_folder`
If False, uses an absolute path in the `params.py` (ie `dat_path=r'path/to/the/recording.dat'`)
{}
"""
Expand Down Expand Up @@ -94,7 +98,7 @@ def export_to_phy(
used_sparsity = sparsity
else:
used_sparsity = ChannelSparsity.create_dense(waveform_extractor)
# convinient sparsity dict for the 3 cases to retrieve channl_inds
# convenient sparsity dict for the 3 cases to retrieve channl_inds
sparse_dict = used_sparsity.unit_id_to_channel_indices

empty_flag = False
Expand All @@ -106,7 +110,7 @@ def export_to_phy(
empty_flag = True
unit_ids = non_empty_units
if empty_flag:
warnings.warn("Empty units have been removed when being exported to Phy")
warnings.warn("Empty units have been removed while exporting to Phy")

if len(unit_ids) == 0:
raise Exception("No non-empty units in the sorting result, can't save to Phy.")
Expand Down Expand Up @@ -149,7 +153,15 @@ def export_to_phy(

# write params.py
with (output_folder / "params.py").open("w") as f:
f.write(f"dat_path = r'{str(rec_path)}'\n")
if use_relative_path:
if copy_binary:
f.write(f"dat_path = r'recording.dat'\n")
elif rec_path == "None":
f.write(f"dat_path = {rec_path}\n")
else:
f.write(f"dat_path = r'{str(Path(rec_path).relative_to(output_folder))}'\n")
else:
f.write(f"dat_path = r'{str(rec_path)}'\n")
f.write(f"n_channels_dat = {num_chans}\n")
f.write(f"dtype = '{dtype_str}'\n")
f.write(f"offset = 0\n")
Expand Down
5 changes: 3 additions & 2 deletions src/spikeinterface/qualitymetrics/misc_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,13 @@ def compute_synchrony_metrics(waveform_extractor, synchrony_sizes=(2, 4, 8), uni
continue
spike_complexity = complexity[np.isin(unique_spike_index, spikes_per_unit["sample_index"])]
for synchrony_size in synchrony_sizes:
synchrony_counts[synchrony_size][unit_id] += np.count_nonzero(spike_complexity >= synchrony_size)
synchrony_counts[synchrony_size][unit_index] += np.count_nonzero(spike_complexity >= synchrony_size)

# add counts for this segment
synchrony_metrics_dict = {
f"sync_spike_{synchrony_size}": {
unit_id: synchrony_counts[synchrony_size][unit_id] / spike_counts[unit_id] for unit_id in unit_ids
unit_id: synchrony_counts[synchrony_size][all_unit_ids.index(unit_id)] / spike_counts[unit_id]
for unit_id in unit_ids
}
for synchrony_size in synchrony_sizes
}
Expand Down

0 comments on commit 3826a2d

Please sign in to comment.