From dd6d353d81b041a44ce38d5ee78e7d7470fbfeb8 Mon Sep 17 00:00:00 2001 From: agchesebro <76024790+agchesebro@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:01:09 -0400 Subject: [PATCH 1/3] Batch resampling of a whole dataset --- .../RF_processing_saved_voltages.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/flattening_circuit/RF_processing_saved_voltages.jl b/examples/flattening_circuit/RF_processing_saved_voltages.jl index 3e0f9913..db0a2cb9 100644 --- a/examples/flattening_circuit/RF_processing_saved_voltages.jl +++ b/examples/flattening_circuit/RF_processing_saved_voltages.jl @@ -22,5 +22,15 @@ function resample_timeseries(data, dt=1) return new_data end +orig_sim_path = "/Users/achesebro/Downloads/all_sims/orig_sims/" +resampled_sim_path = "/Users/achesebro/Downloads/all_sims/resampled_sims/" -data = DataFrame(CSV.File("/Users/achesebro/Downloads/all_sims/sol_trial_1.csv")) +all_files = readdir(orig_sim_path) +for i ∈ eachindex(all_files) + orig_path = orig_sim_path * all_files[i] + resampled_path = resampled_sim_path * all_files[i] + orig_data = DataFrame(CSV.File(orig_path)) + collapse_data = collapse_timesteps(orig_data) + resampled_data = resample_timeseries(collapse_data, 1) + CSV.write(resampled_path, resampled_data) +end \ No newline at end of file From 87015b68a4bc86ba4f9e82086ff62f97bdd91d54 Mon Sep 17 00:00:00 2001 From: agchesebro <76024790+agchesebro@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:56:32 -0400 Subject: [PATCH 2/3] Create concatenated time series to convert to fMRI --- .../RF_processing_saved_voltages.jl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/flattening_circuit/RF_processing_saved_voltages.jl b/examples/flattening_circuit/RF_processing_saved_voltages.jl index db0a2cb9..e770278e 100644 --- a/examples/flattening_circuit/RF_processing_saved_voltages.jl +++ b/examples/flattening_circuit/RF_processing_saved_voltages.jl @@ -33,4 +33,19 @@ for i ∈ eachindex(all_files) collapse_data = collapse_timesteps(orig_data) resampled_data = resample_timeseries(collapse_data, 1) CSV.write(resampled_path, resampled_data) -end \ No newline at end of file +end + +concat_file_path = "/Users/achesebro/Downloads/all_sims/concatenated_sims.csv" +all_files = readdir(resampled_sim_path) +first_data = DataFrame(CSV.File(resampled_sim_path * all_files[1])) +all_data = first_data + +for i ∈ 2:lastindex(all_files) + next_data = DataFrame(CSV.File(resampled_sim_path * all_files[i])) + all_data = vcat(all_data, next_data) +end + +new_t = 0:lastindex(all_data.t)-1 +all_data.t .= collect(new_t) + +CSV.write(concat_file_path, all_data) \ No newline at end of file From ed0fe5a8f5ac43a2d41a22c73d1b56aba7b1f6b1 Mon Sep 17 00:00:00 2001 From: agchesebro <76024790+agchesebro@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:30:42 -0400 Subject: [PATCH 3/3] Extra helper functions --- .../RF_processing_saved_voltages.jl | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/examples/flattening_circuit/RF_processing_saved_voltages.jl b/examples/flattening_circuit/RF_processing_saved_voltages.jl index e770278e..6dc246f6 100644 --- a/examples/flattening_circuit/RF_processing_saved_voltages.jl +++ b/examples/flattening_circuit/RF_processing_saved_voltages.jl @@ -48,4 +48,28 @@ end new_t = 0:lastindex(all_data.t)-1 all_data.t .= collect(new_t) -CSV.write(concat_file_path, all_data) \ No newline at end of file +CSV.write(concat_file_path, all_data) + +all_data = CSV.read(concat_file_path, DataFrame) + +using DSP, Distributions, StatsBase + +function HRF(x,rtu=6.0,δ1=6.0,δ2=16.0,τ1=1.0,τ2=1.0,C=0.0) + return pdf.(Gamma(δ1,τ1),x)-pdf.(Gamma(δ2,τ2),x)/rtu + C +end + + +t_hrf = 0:0.001:32 +hrf = HRF.(t_hrf) + +hrf_data = DataFrame() + +for i ∈ names(all_data)[2:end] + next_data = all_data[:, i] + next_data = StatsBase.transform(fit(UnitRangeTransform, next_data), next_data) + conv_data = conv(next_data, hrf) + hrf_data[!, i] = conv_data +end + +hrf_path = "/Users/achesebro/Downloads/all_sims/hrf_sims.csv" +CSV.write(hrf_path, hrf_data)