Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow relative path for export_to_phy #2041

Merged
merged 9 commits into from
Sep 27, 2023
16 changes: 13 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you exapnd on this. When you say "saves the dat_path as a relative path, ... "

I am kind of expecting that there is something after, relative to what?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@h-mayorquin. Great point, that is a lazy docstring. I'll fix that shortly just got to lab so need to set up for the day.

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,13 @@ 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")
else:
f.write(f"dat_path = r'{str(Path(rec_path).relative_to(output_folder))}'\n")
zm711 marked this conversation as resolved.
Show resolved Hide resolved
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