From c5c696b18e49c1a9324d390183e758541fb659bb Mon Sep 17 00:00:00 2001 From: abuzarmahmood Date: Thu, 31 Jul 2025 14:48:26 +0000 Subject: [PATCH] feat: add user prompt for sampling rate if info.rhd file is missing Co-authored-by: aider (gpt-4o) --- blech_clust.py | 9 +++++++-- utils/blech_channel_profile.py | 10 +++++++--- utils/blech_reload_amp_digs.py | 9 +++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/blech_clust.py b/blech_clust.py index e26bf1fe..25cdd29b 100644 --- a/blech_clust.py +++ b/blech_clust.py @@ -288,8 +288,13 @@ def generate_processing_scripts(dir_name, blech_clust_dir, electrode_layout_fram print("\tOne file per SIGNAL Detected") # Use info file for port list calculation - info_file = np.fromfile(dir_name + '/info.rhd', dtype=np.dtype('float32')) - sampling_rate = int(info_file[2]) + info_file_path = os.path.join(dir_name, 'info.rhd') + if os.path.exists(info_file_path): + info_file = np.fromfile(info_file_path, dtype=np.dtype('float32')) + sampling_rate = int(info_file[2]) + else: + print("info.rhd file not found. Please enter the sampling rate manually:") + sampling_rate = int(input("Sampling rate (Hz): ")) # Read the time.dat file for use in separating out # the one file per signal type data diff --git a/utils/blech_channel_profile.py b/utils/blech_channel_profile.py index 00b064de..eebbafc6 100644 --- a/utils/blech_channel_profile.py +++ b/utils/blech_channel_profile.py @@ -38,9 +38,13 @@ def plot_channels(dir_path, qa_out_path, file_type): amp_files = glob.glob(os.path.join(dir_path, "amp*dat")) digin_files = glob.glob(os.path.join(dir_path, "dig*dat")) # Use info file for port list calculation - info_file = np.fromfile(os.path.join( - dir_path, 'info.rhd'), dtype=np.dtype('float32')) - sampling_rate = int(info_file[2]) + info_file_path = os.path.join(dir_path, 'info.rhd') + if os.path.exists(info_file_path): + info_file = np.fromfile(info_file_path, dtype=np.dtype('float32')) + sampling_rate = int(info_file[2]) + else: + print("info.rhd file not found. Please enter the sampling rate manually:") + sampling_rate = int(input("Sampling rate (Hz): ")) # Read the time.dat file for use in separating out the one file per signal type data num_recorded_samples = len(np.fromfile( os.path.join(dir_path, 'time.dat'), dtype=np.dtype('float32'))) diff --git a/utils/blech_reload_amp_digs.py b/utils/blech_reload_amp_digs.py index f0e2e256..837dd3a3 100644 --- a/utils/blech_reload_amp_digs.py +++ b/utils/blech_reload_amp_digs.py @@ -82,8 +82,13 @@ dig_in_list = sorted(dig_in_list) # Use info file for port list calculation -info_file = np.fromfile(dir_name + '/info.rhd', dtype=np.dtype('float32')) -sampling_rate = int(info_file[2]) +info_file_path = os.path.join(dir_name, 'info.rhd') +if os.path.exists(info_file_path): + info_file = np.fromfile(info_file_path, dtype=np.dtype('float32')) + sampling_rate = int(info_file[2]) +else: + print("info.rhd file not found. Please enter the sampling rate manually:") + sampling_rate = int(input("Sampling rate (Hz): ")) # Read the time.dat file for use in separating out # the one file per signal type data