From bde3749395862cf8ecf78a73eb03e673f22ac562 Mon Sep 17 00:00:00 2001 From: BrianNGitahi <102825698+BrianNGitahi@users.noreply.github.com> Date: Wed, 1 Nov 2023 18:34:36 -0700 Subject: [PATCH] 01/11 --- __pycache__/s_functions.cpython-311.pyc | Bin 5830 -> 9034 bytes f_rate.py | 13 +-- s_functions.py | 112 +++++++++++++++++++++--- 3 files changed, 105 insertions(+), 20 deletions(-) diff --git a/__pycache__/s_functions.cpython-311.pyc b/__pycache__/s_functions.cpython-311.pyc index 32d5cf749a174b71311b4cd32ef99fa8bd819554..71308e5d91651c3a4c91fe79971591d2f6ab39aa 100644 GIT binary patch delta 3566 zcmc&1OKcn0aUc1XT>h4nOjELCCrjIjxQ?XOZmQO)Ek$yX_$S$klfrgtsFZd|)8$8g zyL2L&E+s&1m>>rkuRwALQk`5I$-$|5$|@r$9~y(IrK6!Hr&y1tsw@9(=Q_mY{L1EXqKqf6vsKoggQ zi$N`-NiYj(U0Mj16eK``ijEH5#wexJBd0aKe(mdtV;ACy#v|`0c5he7-K9uh9#2 zdcmR>9{Txbu5V$CJ%0h8-xqi#+{=I9?p+;ppCvAc83ejtDvO$1qo0VkD8vOGXV@`y z)&rVH^KQ3(OezO8N%L*B-joF~-8?)0)@L`U1v(d61Z*B<&^b!t=XtUlk1&8o$p7k% zRLWvGP!6WtkY1rFhQ2UxTxgJ)5`AN8^3okwL!2#S3#=h#lQVj@LDD4;EGQF~8iYCM ztCzmEk6TIP47D_vICeRiPwPr1uPVn1`B^=0vZR@T3>X?xl58deQ#P*@^BL2ql=gtE z**31^EGrlWCIW~HGK@n*Ea^aG-8Rlpd_&4+^2S_pR%b!9I)p$*5JnI|&;_93$?9o6 zuc>k)oVOEkx|xU#DbN2%kCG@4iQkU*A#=pYhusGm|n-LuT*>>Tfox`m;`_PZ# zPg>!lH9A_SqZS=q&)T8;^7HrPk>~HeQIp5(@_3C-)aispCvg4b;_0Q+3#Zp4A-H4t z#0T?MAYsu2+YN@ZrvR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_%I|Nce4N3<{Xhk4>>B4n|JcjR|YF#RU^4Y%2S5 r(RR(%npGmV=#u?4ZyRsxH+zc{Fwx}>zyXBeM1Ir+$alH_VNm=JaMHTI diff --git a/f_rate.py b/f_rate.py index 8f6d42e..6d60f67 100644 --- a/f_rate.py +++ b/f_rate.py @@ -30,17 +30,17 @@ def signal_vs_activity(firing_rates, bleach_time): guinea_neuron = simulate_neuron(70000,firing_rates[i]) # generate the nm_conc - guinea_nm_conc, guinea_b_conc, guinea_c_conc, guinea_nm_tot = simulate_nm_conc(guinea_neuron,nm_conc0=0,k_b=0.6, k_r=0.4,gamma=0.004) + guinea_nm_conc, guinea_b_conc, guinea_c_conc = simulate_nm_conc(guinea_neuron,nm_conc0=0,k_b=0.6, k_r=0.4,gamma=0.004) # then generate the signal - progression, progression_sub = simulate_fluorescence_signal(tau_d=bleach_time, tau_nm=bleach_time, tau_tissue=10e7, nm_conc=guinea_nm_conc) + progression, progression_sub = simulate_fluorescence_signal(tau_d=bleach_time, tau_nm=bleach_time, tau_tissue=10e9, nm_conc=guinea_nm_conc) # get the average of this signal and add it the original array # check for the subtracdted version and the one without the subtraction average_signals.append(np.average(progression[2])) average_signals_sub.append(np.average(progression_sub[3])) - + #print('at {}Hz the average signal is {}'.format(firing_rates[i], np.average(progression[2]))) return average_signals, average_signals_sub @@ -59,10 +59,10 @@ def plot_different_bleach(firing_rates,bleach_times, subtracted=1): for i in range(len(bleach_times)): # generate the average signal plot at the specific bleach time constant - average_signal_plot = signal_vs_activity(firing_rates,bleach_times[i]) + average_signals, average_signals_sub = signal_vs_activity(firing_rates,bleach_times[i]) # store the values in the array - average_signal_plots.append(average_signal_plot[subtracted]) + average_signal_plots.append(average_signals) # make the average signal plots at different bleach time constants @@ -72,6 +72,7 @@ def plot_different_bleach(firing_rates,bleach_times, subtracted=1): plt.xlabel('Firing rates(Hz)') plt.ylabel('Average df/f signal') + plt.ylim(0,0.01) plt.title('Signal vs activity plot') plt.legend(title='bleach time constants') plt.show() @@ -95,7 +96,7 @@ def plot_different_bleach(firing_rates,bleach_times, subtracted=1): # Check 2: -list_of_bleaches = np.logspace(5,7,5) +list_of_bleaches = np.logspace(4,20,6) plot_different_bleach(different_firing_rates,bleach_times=list_of_bleaches, subtracted=0) diff --git a/s_functions.py b/s_functions.py index 04a279f..a5ca92f 100644 --- a/s_functions.py +++ b/s_functions.py @@ -29,11 +29,11 @@ def simulate_neuron(n_timesteps, firing_rate, number=1): firing_neuron = firing_neuron.astype(int) - # # then make a plot of it! - # plt.plot(firing_neuron) - # plt.xlabel('timesteps') - # plt.ylabel('Neuron activity') - # plt.title('Neuron Activity over {} timesteps'.format(n_timesteps)) + # then make a plot of it! + plt.plot(firing_neuron) + plt.xlabel('timesteps') + plt.ylabel('Neuron activity') + plt.title('Neuron Activity ({}Hz) over {} timesteps'.format(firing_rate,n_timesteps)) # plt.show() @@ -41,11 +41,20 @@ def simulate_neuron(n_timesteps, firing_rate, number=1): n_spikes = np.size(np.nonzero(firing_neuron)) # print simulated neuron summary: - # print('Simulated neuron with {} spikes in {} timesteps ({} Hz).'.format(n_spikes, n_timesteps, firing_rate)) + #print('Simulated neuron with {} spikes in {} timesteps ({} Hz).'.format(n_spikes, n_timesteps, firing_rate)) return firing_neuron +# test 1 +# plt.figure(1) +# plt.subplot(2,1,1) +# firing_neuron = simulate_neuron(70000,1) +# plt.subplot(2,1,2) +# firing_neuron2 = simulate_neuron(70000,10) +# plt.tight_layout() +# plt.show() + # Function 2: takes in an array of neuron activity and gives corresponding [NM] @@ -96,12 +105,34 @@ def simulate_nm_conc(neuron_activity,nm_conc0, k_b,k_r,gamma): # then get the total nm concentration - both bound and unbound nm_tot = nm_conc + nm_b_conc + nm_r_conc + # plot [NM], [NM B] and [NM R] simulataneously + plt.plot(t,nm_conc, color = 'b', label='[NM]') + plt.plot(t,nm_b_conc, color = 'g', label='[NM B]') + plt.plot(t,nm_r_conc, color = 'r', label='[NM R]') + + + # label the axes and make legend + plt.xlabel('time (ms)') + + # # to zoom in on a plot + # plt.xlim(5000,15000) + + plt.ylabel('(Change in) Concentration -- arbitrary units') + plt.title('NM concentration across {} ms'.format(n_timesteps)) + plt.legend() + # return the array of the [NM], [NM B], and [NM R] - return nm_conc, nm_b_conc, nm_r_conc, nm_tot + return nm_conc, nm_b_conc, nm_r_conc -# output 2 -#nm_conc, nm_b_conc, nm_r_conc = simulate_nm_conc(firing_neuron,nm_conc0=0,k_b=0.6, k_r=0.4,gamma=0.004) +# test 2 +# plt.figure(2) +# plt.subplot(2,1,1) +# nm_conc, nm_b_conc, nm_r_conc = simulate_nm_conc(firing_neuron,nm_conc0=0,k_b=0.6, k_r=0.4,gamma=0.004) +# plt.subplot(2,1,2) +# nm_conc2, nm_b_conc2, nm_r_conc2 = simulate_nm_conc(firing_neuron2,nm_conc0=0,k_b=0.6, k_r=0.4,gamma=0.004) +# plt.tight_layout() +# plt.show() # Function 2.1: produces zoomed in plot def plot_nm_conc(nm,start,stop,colour='b', plotlabel = ''): @@ -122,7 +153,6 @@ def plot_nm_conc(nm,start,stop,colour='b', plotlabel = ''): - def simulate_fluorescence_signal(tau_d, tau_nm, tau_tissue, nm_conc, K_D = 1000, F_max = 45, F_min = 10, bline_len=5000): # autofluorescence @@ -141,7 +171,7 @@ def simulate_fluorescence_signal(tau_d, tau_nm, tau_tissue, nm_conc, K_D = 1000, f = bleach_tissue*f_tissue + (bleach_d*K_D*F_min + bleach_nm*nm_conc*F_max)/(K_D + nm_conc) - # fit an exponential to remove the bleachign trend + # fit an exponential to remove the bleaching trend # define an exponential function that we'll use as the basis for the fit def exp_decay(t,a,b): @@ -204,7 +234,7 @@ def exp_decay(t,a,b): # average value df_f_ave[i] = (f[i] - f0_ave)/f0_ave - f0_averages[i]=f0_ave + f0_averages[i] = f0_ave # define progression arrays for f, df, df/f progression = [] @@ -224,8 +254,62 @@ def exp_decay(t,a,b): return progression, progression_sub -# output 3 -#f_signal = simulate_flourescence_signal(K_D = 1000, F_max = 45, F_min = 10, nm_conc=nm_conc) + + + + +def plot_f_signal(progression, progression_sub): + + + # create timesteps array for the plot + n_timesteps = nm_conc.size + t = np.linspace(0,n_timesteps-1,n_timesteps) + + plt.figure(1) + plt.subplot(2,2,1) + plt.plot(t,progression[0], label='f') + plt.xlabel('time (ms)') + plt.ylabel('f') + plt.title('f vs time') + plt.legend() + + plt.subplot(2,2,2) + plt.plot(t,progression[1], label='df') + plt.xlabel('time (ms)') + plt.ylabel('df') + plt.title('df vs time (f0:median)') + plt.legend() + + plt.subplot(2,2,3) + plt.plot(t,progression[2], label = 'df/f') + plt.xlabel('time(ms)') + plt.ylabel(' df/f') + plt.title('df/f vs time (f0:median)') + plt.legend() + + plt.subplot(2,2,4) + plt.plot(t,progression[3], label = 'df/f') + plt.xlabel('time(ms)') + plt.ylabel(' df/f') + plt.title('df/f vs time (f0:average)') + plt.legend() + plt.suptitle('Progression from f to df/f', size = 16) + plt.tight_layout() + + + +# # output 3 +# progression, progression_sub = simulate_fluorescence_signal(tau_d=10e9,tau_nm=10e9, tau_tissue=10e9, nm_conc = nm_conc) +# progression2, progression_sub2 = simulate_fluorescence_signal(tau_d=10e9,tau_nm=10e9, tau_tissue=10e9, nm_conc = nm_conc2) + +# plot_f_signal(progression, progression_sub) +# print('average signal is {}'.format(np.average(progression[2]))) +# plt.show() +# plot_f_signal(progression2, progression_sub2) +# print('average signal is {}'.format(np.average(progression2[2]))) +# plt.show() + +