-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtemperature_models.py
154 lines (121 loc) · 4.23 KB
/
temperature_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python
""" Ion channel temperature dependency models
This module contains functions and models for temperature dependence of
ion channels. Including generalised Eyring relation and Q10
formulation.
"""
import numpy as np
# Functions defined in Eyring plot
# x = 1 / T
# param A: ln(A / T)
# param B: B
# Assume conductance not function of temperature
def eyringA(x, m, c):
# Eyring param A in Eyring plot
return m * x + c
def eyringB(x, m, c):
# Eyring param B in Eyring plot
return m * x + c
def simpleeyringB(x, m):
# Simple Eyring param B in Eyring plot
return m * x
def eyringG(x, g):
# Eyring conductance in Eyring plot
return g * np.ones(x.shape)
def eyringT(param, T):
# Given temperature (T) and parameters of the functions in Eyring
# plot (param), return Eyring plots values:
# [conductance, ln(A/T), B, ...]
assert(len(param) == 9)
out = np.zeros(len(param))
x = 1. / T
out[0] = eyringG(x, param[0, 0])
for i in [1, 3, 5, 7]:
out[i] = eyringA(x, *param[i])
for i in [2, 4, 6, 8]:
out[i] = eyringB(x, *param[i])
return out
def q10A(x, m, c):
# Q10 param A in Eyring plot
return m / x + np.log(x) + c
def q10B(x, b):
# Q10 param B in Eyring plot
return b * np.ones(x.shape)
def q10G(x, g):
# Q10 conductance in Eyring plot
return g * np.ones(x.shape)
def q10T(param, T):
# Given temperature (T) and parameters of the functions in Eyring
# plot (param), return Eyring plots values:
# [conductance, ln(A/T), B, ...]
assert(len(param) == 9)
out = np.zeros(len(param))
x = 1. / T
out[0] = q10G(x, param[0, 0])
for i in [1, 3, 5, 7]:
out[i] = q10A(x, *param[i])
for i in [2, 4, 6, 8]:
out[i] = q10B(x, param[i, 0])
return out
# Functions to transform Eyring plot parameters to model parameters
def eyring_transform_to_model_param(param, temperature):
# param = [conductance, A, B, A, B, A, B, A, B]
# temperature in K
out = np.copy(param)
for i in [1, 3, 5, 7]:
out[i] = np.exp(out[i]) * temperature
return out
def eyring_transform_from_model_param(param, temperature):
# param = [conductance, A, B, A, B, A, B, A, B]
# temperature in K
out = np.copy(param)
for i in [1, 3, 5, 7]:
out[i] = np.log(out[i] / temperature)
return out
def eyring_transform_mean(param, n_param):
"""
Return mean of 1D mariginal of the `n_param`th parameter, where
`param` specifies the untransformed (normal) distribution
(mean, std).
"""
mean, std = param
if n_param in [1, 3, 5, 7]:
from scipy.stats import lognorm
# param A
return lognorm.mean(std, loc=0, scale=np.exp(mean))
else:
from scipy.stats import norm
# conductance or param B
return norm.mean(loc=mean, scale=std)
def eyring_transform_cdf(param, n_param, value):
"""
Evaluate CDF of 1D marginal of the `n_param`th parameter at value
`value`, given `param` to specify the untransformed (normal)
distribution (mean, std).
"""
mean, std = param
if n_param in [1, 3, 5, 7]:
from scipy.stats import lognorm
# param A
# before is the same as lognorm.cdf((value / np.exp(mean)), std)
return lognorm.cdf(value, std, loc=0, scale=np.exp(mean))
else:
from scipy.stats import norm
# conductance or param B
return norm.cdf(value, loc=mean, scale=std)
def eyring_transform_ppf(param, n_param, p):
"""
Return `theoretical quantile', also known as `percent point
function', that is the value from CDF of 1D mariginal of the
`n_param`th parameter that matches `p`, where `param` specifies
the untransformed (normal) distribution (mean, std).
"""
mean, std = param
if n_param in [1, 3, 5, 7]:
from scipy.stats import lognorm
# param A
return lognorm.ppf(p, std, loc=0, scale=np.exp(mean))
else:
from scipy.stats import norm
# conductance or param B
return norm.ppf(p, loc=mean, scale=std)