-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Pituitary gland example function #75
Merged
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
438c265
Add pituitary gland ODE
WolfByttner f023d0c
Add numba to requirements
WolfByttner 3732e38
Add docstring to pituitary gland function
WolfByttner 9e3aa2f
Add pituitary gland distribution function
WolfByttner cc14fbc
Merge branch 'master' into pituitary_gland
WolfByttner 394371a
Add brownian motion generator
WolfByttner 1e2f8ca
Add dt to Brownian
WolfByttner 84cd135
Add dt documentation to Brownian
WolfByttner 98acec4
Add latin hypercube pituitary gland sampler
WolfByttner 74461f7
Discard pituitary gland activation noise
WolfByttner 7fa1959
Remove deal parentheses
WolfByttner 298fbdb
Speed up brownian motion tests
WolfByttner ea72fdf
Let the user choose how much to trim from the pituitary gland
WolfByttner 82e4b44
Add commentary on the rhs equation pituitary_ode
WolfByttner 6f40773
Reduce sensitivity of brownian tests
WolfByttner fcf6b2b
Add non-JIT version of pituitary gland for test coverage
WolfByttner d4e71b3
Ignore numba-compiled line in pytest
WolfByttner 0041908
Speed up JIT (dispatching through function is slow)
WolfByttner 6459b74
Add comment explaining why coverage is suppressed on JIT code
WolfByttner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from numba import jit | ||
from scipy.integrate import odeint | ||
|
||
@jit | ||
def pituitary_ode(w, t, p): | ||
""" | ||
Defines the differential equations for the pituirary gland system. | ||
|
||
Arguments: | ||
w : vector of the state variables: | ||
w = [v, n, f, c] | ||
t : time | ||
p : vector of the parameters: | ||
p = [gk, gcal, gsk, gbk, gl, k] | ||
""" | ||
vca=60 | ||
vk=-75 | ||
vl=-50 | ||
Cm=10 | ||
vn=-5 | ||
vm=-20 | ||
vf=-20 | ||
sn=10 | ||
sm=12 | ||
sf=2 | ||
taun=30 | ||
taubk=5 | ||
ff=0.01 | ||
alpha=0.0015 | ||
ks=0.4 | ||
auto=0 | ||
cpar=0 | ||
noise=4.0 | ||
|
||
v, n, f, c = w | ||
|
||
gk, gcal, gsk, gbk, gl, kc = p | ||
|
||
cd=(1-auto)*c+auto*cpar | ||
|
||
phik=1/(1+exp((vn-v)/sn)) | ||
phif=1/(1+exp((vf-v)/sf)) | ||
phical=1/(1+exp((vm-v)/sm)) | ||
cinf=cd**2/(cd**2+ks**2) | ||
|
||
ica=gcal*phical*(v-vca) | ||
isk=gsk*cinf*(v-vk) | ||
ibk=gbk*f*(v-vk) | ||
ikdr=gk*n*(v-vk) | ||
ileak=gl*(v-vl) | ||
|
||
ikdrx=ikdr | ||
ibkx =ibk | ||
|
||
ik = isk + ibk + ikdr | ||
inoise = 0 # noise*w #TODO fix | ||
|
||
dv = -(ica+ik+inoise+ileak)/Cm | ||
dn = (phik-n)/taun | ||
df = (phif-f)/taubk | ||
dc = -ff*(alpha*ica+kc*c) | ||
return (dv, dn, df, dc) | ||
|
||
|
||
def compute_pituitary_gland_df_from_parameters(downsample_rate, | ||
gcal, gsk, gk, gbk, gl, kc, | ||
sample_id): | ||
""" | ||
Computes a Traja dataframe from the pituitary gland simulation. | ||
|
||
It is easier to discuss ion flow in term of conductances than resistances. | ||
If V / R = I, where V is the voltage, R is the resistance and I is the | ||
current, then V * C = I, where C = 1 / R is the conductance. | ||
|
||
Below we specify arguments in terms of maximum conductances, | ||
i.e. the maximum rate at which ion channels let ions through | ||
the cell walls. | ||
|
||
Arguments: | ||
downsample_rate : How much the dataframe will be downsampled (relative | ||
to the original simulation) | ||
gcal : The maximum calcium conductance | ||
gsk : The maximum s-potassiun conductance | ||
gk : The maximum potassium conductance | ||
gbk : The maximum b-potassium conductance | ||
gl : The maximum leak conductance | ||
kc : | ||
sample_id : The ID of this particular sample. Must be unique | ||
""" | ||
|
||
# Initial conditions | ||
v=-60. | ||
n=0.1 | ||
f=0.01 | ||
c=0.1 | ||
|
||
p = (gk, gcal, gsk, gbk, gl, kc) | ||
w0 = (v, n, f, c) | ||
abserr = 1.0e-8 | ||
relerr = 1.0e-6 | ||
|
||
t = np.arange(0, 5000, 0.05) | ||
#print("Generating gcal={}, gsk={}, gk={}, gbk={}, gl={}, kc={}".format(gcal, gsk, gk, gbk, gl, kc)) | ||
wsol = scipy.integrate.odeint(pituitary_ode, w0, t, args=(p,), atol=abserr, rtol=relerr) | ||
df = pd.DataFrame(wsol, columns=['v', 'n', 'f', 'c']) | ||
df['ID'] = sample_id | ||
df['gcal'] = gcal | ||
df['gsk'] = gsk | ||
df['gk'] = gk | ||
df['gbk'] = gbk | ||
df['gl'] = gl | ||
df['kc'] = kc | ||
df = df.iloc[::downsample_rate, :] | ||
#df = df.drop(columns=['t', 'ikdrx', 'ibkx']) | ||
|
||
return df |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not clear how this is different than
pituitary_ode
. Can we give it a shorter name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably leave out 'compute', and also 'df', since that is the return type. Maybe
simulate_pituitary_ode
?