7 Commits 96b7936088 ... 2b90c392d4

Author SHA1 Message Date
  vogdb 2b90c392d4 Merge branch 'master' of https://gin.g-node.org/asanin/epilepsy-potassium-calculation 4 years ago
  vogdb 3763f19085 setup.py 4 years ago
  vogdb f44fcdd708 move standalone tools to a separate package 4 years ago
  vogdb c55d91a19a disable the cut in optimized phi calculations 4 years ago
  vogdb 895c812643 fix graphics 4 years ago
  vogdb 1546d6df64 add center point to recording 4 years ago
  vogdb 490e61285a delete obsolete 4 years ago

+ 12 - 8
epileptor/display_0d.py

@@ -5,6 +5,8 @@ from mpl_toolkits.axes_grid1.inset_locator import inset_axes
 import matplotlib.patches as patches
 from epileptor import util
 
+font = {'size': 20}
+matplotlib.rc('font', **font)
 
 def plot_data(dt, state_list, title):
     state_dict = {}
@@ -33,7 +35,7 @@ def plot_data(dt, state_list, title):
         # V = state_dict['V']
 
         ax.set_ylabel('mV')
-        ax.set_title('A', loc='left')
+        ax.set_title('a', loc='left')
         # ax.plot(t_ms[l:r], V[l:r], 'r', label='$V$')
         ax.plot(t_range_ms[l:r], U[l:r], '#009900', label='$U$')
         ax.legend()
@@ -57,7 +59,7 @@ def plot_data(dt, state_list, title):
             return
         uu = state_dict['uu']
 
-        ax.set_title('B', loc='left')
+        ax.set_title('b', loc='left')
         ax.set_ylabel('$u$(pA)')
         ax.plot(t_range_ms[l:r], uu[l:r], 'k')
 
@@ -68,7 +70,7 @@ def plot_data(dt, state_list, title):
         xD = state_dict['xD']
 
         ax.set_ylabel(r'$\nu$(Hz)')
-        ax.set_title('D', loc='left')
+        ax.set_title('d', loc='left')
         ax.plot(t_range_ms[l:r], nu[l:r], 'k', label=r'$\nu$')
         ax_r = ax.twinx()
         ax_r.plot(t_range_ms[l:r], xD[l:r], 'm', label='$x^D$')
@@ -85,7 +87,7 @@ def plot_data(dt, state_list, title):
         INaKpump = state_dict['INaKpump']
 
         ax.set_ylabel('mM')
-        ax.set_title('C', loc='left')
+        ax.set_title('c', loc='left')
         ax.plot(t_range_ms[l:r], K[l:r], 'b', label='$[K]_o$')
         ax.plot(t_range_ms[l:r], Na[l:r], 'r', label='$[Na]_i$')
         ax_r = ax.twinx()
@@ -100,7 +102,7 @@ def plot_data(dt, state_list, title):
         phi = state_dict['phi']
         ax.set_xlabel('t(s)')
         ax.set_ylabel(r'$\varphi$(Hz)')
-        ax.set_title('E', loc='left')
+        ax.set_title('e', loc='left')
         ax.plot(t_range_ms[l:r], phi[l:r])
 
     def has_phi():
@@ -149,7 +151,8 @@ def plot_data(dt, state_list, title):
         nrows = 4
         if has_phi():
             nrows += 1
-        fig, axes = plt.subplots(nrows, 1, sharex='all')
+        fig, axes = plt.subplots(nrows, 1, sharex='all', figsize=(10,8))
+        plt.subplots_adjust(hspace=0.6)
         set_sec_formatter(axes)
 
         plot_UV(axes[0], left_nt, right_nt)
@@ -159,9 +162,10 @@ def plot_data(dt, state_list, title):
         if has_phi():
             plot_phi(axes[4], left_nt, right_nt)
 
-        plt.tight_layout()
+        # plt.tight_layout()
         plt.savefig('media/{}'.format(title))
         plt.gcf().clear()
 
     # plot_with_zoom(40, 70)
-    plot_no_zoom(10, 80)
+    # plot_no_zoom(10, 80)
+    plot_no_zoom(0, 299)

+ 1 - 1
epileptor/display_2d.py

@@ -19,7 +19,7 @@ from epileptor.points import Points, Point
 def parse_cmd_args():
     parser = argparse.ArgumentParser(description='')
     parser.add_argument('-d', help='data filepath')
-    parser.add_argument('-i', help='image extension', default='png')
+    parser.add_argument('-i', help='image extension', default='svg')
     args = parser.parse_args()
     return args.d, args.i
 

+ 2 - 1
epileptor/phi_2d.py

@@ -22,7 +22,7 @@ class PhiSolver:
 
     def ode_step(self, nu, cut_idx):
         # self.phi_prev, _ = self.iterative_step(nu, 1e-8, self.phi_prev)
-        self.phi_prev, _ = calculate(self.sigma, nu, 1e-8, self.phi_prev, cut_idx)
+        self.phi_prev, _ = calculate(self.sigma, nu, 1e-8, self.phi_prev)
         return self.phi_prev
         # return self.inverse_step(nu)
 
@@ -303,6 +303,7 @@ class PhiSolver:
 
 
 if __name__ == "__main__":
+    # Just local testing of the module.
     from epileptor import params_2d as params
     from mpl_toolkits.mplot3d import Axes3D
     import matplotlib.pyplot as plt

+ 4 - 3
epileptor/phi_2d_iterative.py

@@ -6,7 +6,8 @@ import numpy as np
 
 # pythran export calculate(float64, float64[][], float64, float64[][])
 @jit
-def calculate(sigma, nu, l2_target, phi_init, cut_idx=None):
+# def calculate(sigma, nu, l2_target, phi_init, cut_idx=None):
+def calculate(sigma, nu, l2_target, phi_init):
     l2_norm = 1
     iterations = 0
     b = nu * sigma
@@ -31,8 +32,8 @@ def calculate(sigma, nu, l2_target, phi_init, cut_idx=None):
                         b[i, j]
                 )
 
-        if cut_idx:
-            phi[cut_idx] = 0
+        # if cut_idx:
+        #     phi[cut_idx] = 0
 
         l2_norm_num = 0
         l2_norm_div = 0

+ 0 - 57
epileptor/phi_2d_iterative.pyx

@@ -1,57 +0,0 @@
-# experimental cython module.
-# WARNING! Do not use it.
-
-import numpy as np
-cimport numpy as cnp
-
-def calculate(double sigma, cnp.ndarray[cnp.float64_t, ndim=2] nu, double l2_target, cnp.ndarray[cnp.float64_t, ndim=2] phi_init):
-    cdef double l2_norm = 1
-    cdef unsigned int iterations = 0
-    cdef double[:,:] b = np.multiply(nu, sigma)
-    cdef double[:,:] phi = np.empty_like(nu)
-    # phi[:,:] = phi_init[:,:]
-    cdef double[:,:] phi_prev = np.empty_like(phi)
-
-    cdef unsigned int i, j, m, n
-    cdef double l2_norm_num, l2_norm_div
-    m = len(nu)
-    n = len(nu[0])
-    cdef double sigma4 = 1. / (4. + sigma)
-
-    while l2_norm > l2_target:
-        for i in range(0, m):
-            for j in range(0, n):
-                phi_prev[i, j] = phi[i, j]
-        for i in range(1, m - 1):
-            # i - rows
-            for j in range(1, n - 1):
-                # j - columns
-                phi[i, j] = sigma4 * (
-                        phi_prev[i - 1, j] + phi_prev[i + 1, j] + phi_prev[i, j - 1] + phi_prev[i, j + 1] +
-                        b[i, j]
-                )
-        for i in range(0, m):
-            phi[i, 0] = phi[i, 1]
-            phi[i, n - 1] = phi[i, n - 2]
-        for j in range(0, n):
-            phi[0, j] = phi[1, j]
-            phi[m - 1, j] = phi[m - 2, j]
-
-        phi[0, 0] = phi[1, 1]
-        phi[-1, 0] = phi[-2, 1]
-        phi[0, -1] = phi[1, -2]
-        phi[-1, -1] = phi[-2, -2]
-
-        l2_norm_num = 0
-        l2_norm_div = 0
-        for i in range(0, m):
-            # i - rows
-            for j in range(0, n):
-                l2_norm_num += (phi[i, j] - phi_prev[i, j]) ** 2
-                l2_norm_div += phi_prev[i, j] ** 2
-        l2_norm_div = max(l2_norm_div, 1e-6)
-        l2_norm = l2_norm_num ** 0.5 / l2_norm_div ** 0.5
-
-        iterations += 1
-
-    return phi, iterations

epileptor/Kwave_noise_compare.py → epileptor/standalone_tools_for_analysis/Kwave_noise_compare.py


+ 0 - 0
epileptor/standalone_tools_for_analysis/__init__.py


epileptor/convergence.py → epileptor/standalone_tools_for_analysis/convergence.py


epileptor/velocity.py → epileptor/standalone_tools_for_analysis/velocity.py


+ 1 - 1
epileptor/state_recorder.py

@@ -24,7 +24,7 @@ class StateRecorder:
         if x_nh == y_nh == 40:
             points = Points(Point(20, 20), Point(20, 24), Point(24, 20), Point(20, 35))
         if x_nh == y_nh == 80:
-            points = Points(Point(40, 46), Point(40, 56), Point(40, 66), Point(40, 76))
+            points = Points(Point(40, 40), Point(40, 46), Point(40, 56), Point(40, 66), Point(40, 76))
         if x_nh == 4 and y_nh == 100:
             points = Points(Point(2, 10), Point(2, 90))
         return points

+ 24 - 0
setup.py

@@ -0,0 +1,24 @@
+from setuptools import setup, find_packages
+
+with open('README.md') as f:
+    README = f.read()
+
+setup(
+    name='epilepsy-potassium-calculation',
+    install_requires=[
+        'matplotlib',
+        'scipy',
+        'numpy>=1.15',
+        'numba',
+        'pyyaml',
+    ],
+    packages=find_packages(),
+    version='0.0.1',
+    author='',
+    author_email='vozdhb@gmail.com',
+    description='',
+    long_description=README,
+    long_description_content_type='text/markdown',
+    url='https://gin.g-node.org/asanin/epilepsy-potassium-calculation.git',
+    classifiers=[]
+)