From 74569d7ca3e5118264d31605b3d1248137527186 Mon Sep 17 00:00:00 2001 From: Cai Wingfield Date: Fri, 18 Oct 2024 14:39:02 +0100 Subject: [PATCH] Specify data sample rate, and warn user if function will be resampled --- dataset_config/dataset3.yaml | 3 ++- dataset_config/dataset4.1.yaml | 1 + dataset_config/dataset4.yaml | 1 + kymata/gridsearch/plain.py | 8 +++----- kymata/invokers/run_gridsearch.py | 12 ++++++++++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/dataset_config/dataset3.yaml b/dataset_config/dataset3.yaml index 6ad0a77c..e0f5e3de 100644 --- a/dataset_config/dataset3.yaml +++ b/dataset_config/dataset3.yaml @@ -25,8 +25,9 @@ participants: [ ] number_of_runs: 2 # number of runs <- 15-minute recording block from scanner repetitions_per_runs: 2 # number of repetitions per run <- repeated stimulus presentations per run -stimulus_length: 400 # seconds +stimulus_length: 400 # seconds mri_structural_type: "T1" # T1 | flash +sample_rate: 1000 # Hz # Preprocessing pipeline emeg_machine_used_to_record_data: 'vectorview' diff --git a/dataset_config/dataset4.1.yaml b/dataset_config/dataset4.1.yaml index 7f724a9d..585d10b7 100755 --- a/dataset_config/dataset4.1.yaml +++ b/dataset_config/dataset4.1.yaml @@ -13,6 +13,7 @@ number_of_runs: 4 # number of runs repetitions_per_runs: 2 # number of repetitions per run stimulus_length: 400 # seconds mri_structural_type: "T1" # T1 | flash +sample_rate: 1000 # Hz # Preprocessing pipeline emeg_machine_used_to_record_data: 'triux' diff --git a/dataset_config/dataset4.yaml b/dataset_config/dataset4.yaml index 76f7a0c6..37601166 100755 --- a/dataset_config/dataset4.yaml +++ b/dataset_config/dataset4.yaml @@ -34,6 +34,7 @@ number_of_runs: 4 # number of runs repetitions_per_runs: 2 # number of repetitions per run stimulus_length: 400 # seconds mri_structural_type: "T1" # T1 | flash +sample_rate: 1000 # Hz # Preprocessing pipeline emeg_machine_used_to_record_data: 'triux' diff --git a/kymata/gridsearch/plain.py b/kymata/gridsearch/plain.py index 602ec11a..be514e8b 100755 --- a/kymata/gridsearch/plain.py +++ b/kymata/gridsearch/plain.py @@ -29,8 +29,8 @@ def do_gridsearch( emeg_t_start: float, # ms stimulus_shift_correction: float, # seconds/second stimulus_delivery_latency: float, # seconds + emeg_sample_rate: float, # Hertz plot_location: Optional[Path] = None, - emeg_sample_rate: int = 1000, # Hertz n_derangements: int = 1, seconds_per_split: float = 1, n_splits: int = 400, @@ -60,7 +60,7 @@ def do_gridsearch( stimulus_delivery_latency (float): Correction offset for stimulus delivery in seconds. plot_location (Optional[Path], optional): Path to save the plot of the top five channels of the grid search. If None, plotting is skipped. Default is None. - emeg_sample_rate (int, optional): The sample rate of the EMEG data in Hertz. Default is 1000 Hz. + emeg_sample_rate (float, optional): The sample rate of the EMEG data in Hertz. n_derangements (int, optional): Number of derangements (random permutations) used to create the null distribution. Default is 1. seconds_per_split (float, optional): Duration of each split in seconds. Default is 0.5 seconds. @@ -142,9 +142,7 @@ def do_gridsearch( * seconds_per_split * (1 + stimulus_shift_correction) ) # splits, stretched by the shift correction - + round( - stimulus_delivery_latency * emeg_sample_rate - ) # correct for stimulus delivery latency delay + + round(stimulus_delivery_latency * emeg_sample_rate) # correct for stimulus delivery latency delay ) for i in range(n_splits) ] diff --git a/kymata/invokers/run_gridsearch.py b/kymata/invokers/run_gridsearch.py index a4b8bd91..4a1e675a 100755 --- a/kymata/invokers/run_gridsearch.py +++ b/kymata/invokers/run_gridsearch.py @@ -214,6 +214,8 @@ def main(): function_path = Path(base_dir, args.function_path) _logger.info(f"Loading functions from {str(function_path)}") + emeg_sample_rate = float(dataset_config.get("sample_rate", 1000)) + for function_name in args.function_name: _logger.info(f"Running gridsearch on {function_name}") function = load_function( @@ -223,8 +225,13 @@ def main(): bruce_neurons=(5, 10), sample_rate=args.function_sample_rate, ) - if args.resample is not None and args.function_sample_rate != args.resample: - function = function.resampled(args.resample) + + # Resample function to match target sample rate if specified, else emeg sample rate + function_resample_rate = args.resample if args.resample is not None else emeg_sample_rate + if function.sample_rate != function_resample_rate: + _logger.info(f"Function sample rate ({function.sample_rate} Hz) doesn't match target sample rate " + f"({function_resample_rate} Hz). Function will be resampled to match.") + function.resampled(function_resample_rate) es = do_gridsearch( emeg_values=emeg_values, @@ -235,6 +242,7 @@ def main(): n_derangements=args.n_derangements, n_splits=args.n_splits, n_reps=n_reps, + emeg_sample_rate=emeg_sample_rate, start_latency=args.start_latency, plot_location=args.save_plot_location, emeg_t_start=args.emeg_t_start,