Completed
Push — master ( 0d6080...7e0de7 )
by Andrei
52s
created

hhn_dynamic_get_time()   A

Complexity

Conditions 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
1
"""!
2
3
@brief CCORE Wrapper for Hodgkin-Huxley oscillatory network for image segmentation.
4
5
@authors Andrei Novikov ([email protected])
6
@date 2014-2018
7
@copyright GNU Public License
8
9
@cond GNU_PUBLIC_LICENSE
10
    PyClustering is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
15
    PyClustering is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
20
    You should have received a copy of the GNU General Public License
21
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
@endcond
23
24
"""
25
26
from pyclustering.core.wrapper import *;
0 ignored issues
show
Unused Code introduced by
memmove was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_int16 was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
PATH_PYCLUSTERING_CCORE_LIBRARY was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
sizeof was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
PYFUNCTYPE was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
platform was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_char was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
os was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
alignment was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_voidp was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
create_string_buffer was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
DllCanUnloadNow was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_int32 was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
WINFUNCTYPE was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
pythonapi was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
memset was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ArgumentError was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_ubyte was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
DllGetClassObject was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_uint16 was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_ulong was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_int was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_short was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_uint was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
BigEndianStructure was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_byte was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
set_last_error was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
RTLD_LOCAL was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
CDLL was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
CFUNCTYPE was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
OleDLL was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
windll was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_uint32 was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_int64 was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
create_unicode_buffer was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
get_last_error was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
LittleEndianStructure was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_longdouble was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
kind was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_int8 was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Array was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_wchar was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
get_errno was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ccore_library_instance was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
SetPointerType was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
HRESULT was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
core_architecture was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Union was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
wstring_at was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_uint8 was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_char_p was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
WinError was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
PyDLL was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
FormatError was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
RTLD_GLOBAL was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_buffer was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_ulonglong was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
cdll was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_wchar_p was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_long was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
py_object was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_uint64 was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
addressof was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ARRAY was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
oledll was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
string_at was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_float was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
cast was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
core was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
byref was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
DEFAULT_MODE was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
set_errno was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
GetLastError was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
WinDLL was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
resize was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
pydll was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_ushort was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
sys was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_ssize_t was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
LibraryLoader was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
c_longlong was imported with wildcard, but is not used.
Loading history...
27
from pyclustering.core.pyclustering_package import pyclustering_package, package_extractor, package_builder;
28
29
30
class c_hhn_params(Structure):
31
    _fields_ = [
32
        ("nu",                  c_double),
33
        ("gNa",                 c_double),
34
        ("gK",                  c_double),
35
        ("gL",                  c_double),
36
        ("vNa",                 c_double),
37
        ("vK",                  c_double),
38
        ("vL",                  c_double),
39
        ("vRest",               c_double),
40
        ("Icn1",                c_double),
41
        ("Icn2",                c_double),
42
        ("Vsyninh",             c_double),
43
        ("Vsynexc",             c_double),
44
        ("alfa_inhibitory",     c_double),
45
        ("betta_inhibitory",    c_double),
46
        ("alfa_excitatory",     c_double),
47
        ("betta_excitatory",    c_double),
48
        ("w1",                  c_double),
49
        ("w2",                  c_double),
50
        ("w3",                  c_double),
51
        ("deltah",              c_double),
52
        ("threshold",           c_double),
53
        ("eps",                 c_double),
54
    ];
55
56
57
def hhn_create(size, params):
58
    c_params = c_hhn_params();
59
60
    c_params.nu                 = params.nu;
61
    c_params.gNa                = params.gNa;
62
    c_params.gK                 = params.gK;
63
    c_params.gL                 = params.gL;
64
    c_params.vNa                = params.vNa;
65
    c_params.vK                 = params.vK;
66
    c_params.vL                 = params.vL;
67
    c_params.vRest              = params.vRest;
68
    c_params.Icn1               = params.Icn1;
69
    c_params.Icn2               = params.Icn2;
70
    c_params.Vsyninh            = params.Vsyninh;
71
    c_params.Vsynexc            = params.Vsynexc;
72
    c_params.alfa_inhibitory    = params.alfa_inhibitory;
73
    c_params.betta_inhibitory   = params.betta_inhibitory;
74
    c_params.alfa_excitatory    = params.alfa_excitatory;
75
    c_params.betta_excitatory   = params.betta_excitatory;
76
    c_params.w1                 = params.w1;
77
    c_params.w2                 = params.w2;
78
    c_params.w3                 = params.w3;
79
    c_params.deltah             = params.deltah;
80
    c_params.threshold          = params.threshold;
81
    c_params.eps                = params.eps;
82
83
    ccore = load_core();
84
85
    ccore.hhn_create.restype = POINTER(c_void_p);
86
    hhn_network_pointer = ccore.hhn_create(c_size_t(size), pointer(c_params));
87
    return hhn_network_pointer;
88
89
90
def hhn_destroy(hhn_network_pointer):
91
    ccore = load_core();
92
    ccore.hhn_destroy(hhn_network_pointer);
93
94
95
def hhn_dynamic_create(collect_membrane, collect_active_cond_sodium, collect_inactive_cond_sodium, collect_active_cond_potassium):
96
    ccore = load_core();
97
98
    ccore.hhn_dynamic_create.restype = POINTER(c_void_p);
99
    hhn_dynamic_pointer = ccore.hhn_dynamic_create(c_bool(collect_membrane),
100
                                                   c_bool(collect_active_cond_sodium),
101
                                                   c_bool(collect_inactive_cond_sodium),
102
                                                   c_bool(collect_active_cond_potassium));
103
    return hhn_dynamic_pointer;
104
105
106
def hhn_dynamic_destroy(hhn_dynamic_pointer):
107
    ccore = load_core();
108
    ccore.hhn_dynamic_destroy(hhn_dynamic_pointer);
109
110
111
def hhn_simulate(hhn_network_pointer, steps, time, solution, stimulus, ccore_hhn_dynamic_pointer):
112
    ccore = load_core();
113
114
    c_stimulus = package_builder(stimulus, c_double).create();
115
    ccore.hhn_simulate(hhn_network_pointer,
116
                       c_size_t(steps),
117
                       c_double(time),
118
                       c_size_t(solution),
119
                       c_stimulus,
120
                       ccore_hhn_dynamic_pointer);
121
122
123
def hhn_dynamic_get_peripheral_evolution(ccore_hhn_dynamic_pointer, index_collection):
124
    ccore = load_core();
125
126
    ccore.hhn_dynamic_get_peripheral_evolution.restype = POINTER(pyclustering_package);
127
    dynamic_package = ccore.hhn_dynamic_get_peripheral_evolution(ccore_hhn_dynamic_pointer, c_size_t(index_collection));
128
129
    result = package_extractor(dynamic_package).extract();
130
    ccore.free_pyclustering_package(dynamic_package);
131
132
    return result;
133
134
135
def hhn_dynamic_get_central_evolution(ccore_hhn_dynamic_pointer, index_collection):
136
    ccore = load_core();
137
138
    ccore.hhn_dynamic_get_central_evolution.restype = POINTER(pyclustering_package);
139
    dynamic_package = ccore.hhn_dynamic_get_central_evolution(ccore_hhn_dynamic_pointer, c_size_t(index_collection));
140
141
    result = package_extractor(dynamic_package).extract();
142
    ccore.free_pyclustering_package(dynamic_package);
143
144
    return result;
145
146
147
def hhn_dynamic_get_time(ccore_hhn_dynamic_pointer):
148
    ccore = load_core();
149
150
    ccore.hhn_dynamic_get_time.restype = POINTER(pyclustering_package);
151
    dynamic_package = ccore.hhn_dynamic_get_time(ccore_hhn_dynamic_pointer);
152
153
    result = package_extractor(dynamic_package).extract();
154
    ccore.free_pyclustering_package(dynamic_package);
155
156
    return result;