From f76666f9cec6740bc29a86178478390d2f50fe6c Mon Sep 17 00:00:00 2001 From: cbroz1 Date: Mon, 18 Sep 2023 11:50:40 -0700 Subject: [PATCH] WIP: minor edits --- src/spyglass/common/common_behav.py | 5 ++++- src/spyglass/common/common_lab.py | 2 +- src/spyglass/common/common_nwbfile.py | 3 ++- src/spyglass/data_import/insert_sessions.py | 8 +++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/spyglass/common/common_behav.py b/src/spyglass/common/common_behav.py index d26b2c0f6..d362f3a6c 100644 --- a/src/spyglass/common/common_behav.py +++ b/src/spyglass/common/common_behav.py @@ -507,7 +507,10 @@ def _no_transaction_make(self, key): for time in [pos_times[0][0], pos_times[-1][-1]] ] ): - matching_pos_intervals.append(pos_intervals) + matching_pos_intervals.append(pos_interval) + + if len(matching_pos_intervals) > 1: + break # Check that each pos interval was matched to only one epoch if len(matching_pos_intervals) != 1: diff --git a/src/spyglass/common/common_lab.py b/src/spyglass/common/common_lab.py index 56333b679..9be9d15b2 100644 --- a/src/spyglass/common/common_lab.py +++ b/src/spyglass/common/common_lab.py @@ -39,7 +39,7 @@ def insert_from_nwbfile(cls, nwbf): The NWB file with experimenter information. """ if isinstance(nwbf, str): - nwb_file_abspath = Nwbfile.get_abs_path(nwbf) + nwb_file_abspath = Nwbfile.get_abs_path(nwbf, new_file=True) nwbf = get_nwb_file(nwb_file_abspath) if nwbf.experimenter is None: diff --git a/src/spyglass/common/common_nwbfile.py b/src/spyglass/common/common_nwbfile.py index cfb66ab2d..1becbdf9e 100644 --- a/src/spyglass/common/common_nwbfile.py +++ b/src/spyglass/common/common_nwbfile.py @@ -78,7 +78,8 @@ def _get_file_name(cls, nwb_file_name: str) -> str: return query.fetch1("nwb_file_name") raise ValueError( - f"Found {len(query)} matches for {nwb_file_name}: \n{query}" + f"Found {len(query)} matches for {nwb_file_name} in Nwbfile table:" + + f" \n{query}" ) @classmethod diff --git a/src/spyglass/data_import/insert_sessions.py b/src/spyglass/data_import/insert_sessions.py index 5466b58a6..caee7682e 100644 --- a/src/spyglass/data_import/insert_sessions.py +++ b/src/spyglass/data_import/insert_sessions.py @@ -7,7 +7,7 @@ import pynwb from ..common import Nwbfile, get_raw_eseries, populate_all_common -from ..settings import raw_dir +from ..settings import debug_mode, raw_dir from ..utils.nwb_helper_fn import get_nwb_copy_filename @@ -50,7 +50,7 @@ def insert_sessions(nwb_file_names: Union[str, List[str]]): ) # file name for the copied raw data - out_nwb_file_name = get_nwb_copy_filename(nwb_file_abs_path.stem) + out_nwb_file_name = get_nwb_copy_filename(nwb_file_abs_path.name) # Check whether the file already exists in the Nwbfile table if len(Nwbfile() & {"nwb_file_name": out_nwb_file_name}): @@ -97,7 +97,9 @@ def copy_nwb_link_raw_ephys(nwb_file_name, out_nwb_file_name): out_nwb_file_name, new_file=True ) - if os.path.exists(out_nwb_file_name): + if os.path.exists(out_nwb_file_abs_path): + if debug_mode: + return out_nwb_file_abs_path warnings.warn( f"Output file {out_nwb_file_abs_path} exists and will be " + "overwritten."