Skip to content

Commit

Permalink
01/11
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianNGitahi committed Nov 2, 2023
1 parent ce8270c commit bde3749
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 20 deletions.
Binary file modified __pycache__/s_functions.cpython-311.pyc
Binary file not shown.
13 changes: 7 additions & 6 deletions f_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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)


Expand Down
112 changes: 98 additions & 14 deletions s_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,32 @@ 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()


# check exactly how many spikes were produced: to see if it works
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]
Expand Down Expand Up @@ -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 = ''):
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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 = []
Expand All @@ -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()





Expand Down

0 comments on commit bde3749

Please sign in to comment.