pyNIBS 0.2024.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyNIBS-0.2024.8.dist-info/LICENSE +623 -0
- pyNIBS-0.2024.8.dist-info/METADATA +723 -0
- pyNIBS-0.2024.8.dist-info/RECORD +107 -0
- pyNIBS-0.2024.8.dist-info/WHEEL +5 -0
- pyNIBS-0.2024.8.dist-info/top_level.txt +1 -0
- pynibs/__init__.py +34 -0
- pynibs/coil.py +1367 -0
- pynibs/congruence/__init__.py +15 -0
- pynibs/congruence/congruence.py +1108 -0
- pynibs/congruence/ext_metrics.py +257 -0
- pynibs/congruence/stimulation_threshold.py +318 -0
- pynibs/data/configuration_exp0.yaml +59 -0
- pynibs/data/configuration_linear_MEP.yaml +61 -0
- pynibs/data/configuration_linear_RT.yaml +61 -0
- pynibs/data/configuration_sigmoid4.yaml +68 -0
- pynibs/data/network mapping configuration/configuration guide.md +238 -0
- pynibs/data/network mapping configuration/configuration_TEMPLATE.yaml +42 -0
- pynibs/data/network mapping configuration/configuration_for_testing.yaml +43 -0
- pynibs/data/network mapping configuration/configuration_modelTMS.yaml +43 -0
- pynibs/data/network mapping configuration/configuration_reg_isi_05.yaml +43 -0
- pynibs/data/network mapping configuration/output_documentation.md +185 -0
- pynibs/data/network mapping configuration/recommendations_for_accuracy_threshold.md +77 -0
- pynibs/data/neuron/models/L23_PC_cADpyr_biphasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L23_PC_cADpyr_monophasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_LBC_biphasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_LBC_monophasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_NBC_biphasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_NBC_monophasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_SBC_biphasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L4_SBC_monophasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L5_TTPC2_cADpyr_biphasic_v1.csv +1281 -0
- pynibs/data/neuron/models/L5_TTPC2_cADpyr_monophasic_v1.csv +1281 -0
- pynibs/expio/Mep.py +1518 -0
- pynibs/expio/__init__.py +8 -0
- pynibs/expio/brainsight.py +979 -0
- pynibs/expio/brainvis.py +71 -0
- pynibs/expio/cobot.py +239 -0
- pynibs/expio/exp.py +1876 -0
- pynibs/expio/fit_funs.py +287 -0
- pynibs/expio/localite.py +1987 -0
- pynibs/expio/signal_ced.py +51 -0
- pynibs/expio/visor.py +624 -0
- pynibs/freesurfer.py +502 -0
- pynibs/hdf5_io/__init__.py +10 -0
- pynibs/hdf5_io/hdf5_io.py +1857 -0
- pynibs/hdf5_io/xdmf.py +1542 -0
- pynibs/mesh/__init__.py +3 -0
- pynibs/mesh/mesh_struct.py +1394 -0
- pynibs/mesh/transformations.py +866 -0
- pynibs/mesh/utils.py +1103 -0
- pynibs/models/_TMS.py +211 -0
- pynibs/models/__init__.py +0 -0
- pynibs/muap.py +392 -0
- pynibs/neuron/__init__.py +2 -0
- pynibs/neuron/neuron_regression.py +284 -0
- pynibs/neuron/util.py +58 -0
- pynibs/optimization/__init__.py +5 -0
- pynibs/optimization/multichannel.py +278 -0
- pynibs/optimization/opt_mep.py +152 -0
- pynibs/optimization/optimization.py +1445 -0
- pynibs/optimization/workhorses.py +698 -0
- pynibs/pckg/__init__.py +0 -0
- pynibs/pckg/biosig/biosig4c++-1.9.5.src_fixed.tar.gz +0 -0
- pynibs/pckg/libeep/__init__.py +0 -0
- pynibs/pckg/libeep/pyeep.so +0 -0
- pynibs/regression/__init__.py +11 -0
- pynibs/regression/dual_node_detection.py +2375 -0
- pynibs/regression/regression.py +2984 -0
- pynibs/regression/score_types.py +0 -0
- pynibs/roi/__init__.py +2 -0
- pynibs/roi/roi.py +895 -0
- pynibs/roi/roi_structs.py +1233 -0
- pynibs/subject.py +1009 -0
- pynibs/tensor_scaling.py +144 -0
- pynibs/tests/data/InstrumentMarker20200225163611937.xml +19 -0
- pynibs/tests/data/TriggerMarkers_Coil0_20200225163443682.xml +14 -0
- pynibs/tests/data/TriggerMarkers_Coil1_20200225170337572.xml +6373 -0
- pynibs/tests/data/Xdmf.dtd +89 -0
- pynibs/tests/data/brainsight_niiImage_nifticoord.txt +145 -0
- pynibs/tests/data/brainsight_niiImage_nifticoord_largefile.txt +1434 -0
- pynibs/tests/data/brainsight_niiImage_niifticoord_mixedtargets.txt +47 -0
- pynibs/tests/data/create_subject_testsub.py +332 -0
- pynibs/tests/data/data.hdf5 +0 -0
- pynibs/tests/data/geo.hdf5 +0 -0
- pynibs/tests/test_coil.py +474 -0
- pynibs/tests/test_elements2nodes.py +100 -0
- pynibs/tests/test_hdf5_io/test_xdmf.py +61 -0
- pynibs/tests/test_mesh_transformations.py +123 -0
- pynibs/tests/test_mesh_utils.py +143 -0
- pynibs/tests/test_nnav_imports.py +101 -0
- pynibs/tests/test_quality_measures.py +117 -0
- pynibs/tests/test_regressdata.py +289 -0
- pynibs/tests/test_roi.py +17 -0
- pynibs/tests/test_rotations.py +86 -0
- pynibs/tests/test_subject.py +71 -0
- pynibs/tests/test_util.py +24 -0
- pynibs/tms_pulse.py +34 -0
- pynibs/util/__init__.py +4 -0
- pynibs/util/dosing.py +233 -0
- pynibs/util/quality_measures.py +562 -0
- pynibs/util/rotations.py +340 -0
- pynibs/util/simnibs.py +763 -0
- pynibs/util/util.py +727 -0
- pynibs/visualization/__init__.py +2 -0
- pynibs/visualization/para.py +4372 -0
- pynibs/visualization/plot_2D.py +137 -0
- pynibs/visualization/render_3D.py +347 -0
pynibs/tensor_scaling.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import warnings
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def ellipse_eccentricity( a , b ):
|
|
6
|
+
"""Calculates the eccentricity of an 2D ellipse with the
|
|
7
|
+
semi axis a and b. An eccentricity of 0 corresponds to a sphere and an
|
|
8
|
+
eccentricity of 1 means complete eccentric (line) with full restriction to
|
|
9
|
+
the other axis
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
a : float
|
|
14
|
+
First semi axis parameter
|
|
15
|
+
b : float
|
|
16
|
+
Second semi axis parameter
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
e : float
|
|
21
|
+
Eccentricity (0...1)
|
|
22
|
+
"""
|
|
23
|
+
return np.sqrt(1-(b/a)**2)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def rescale_lambda_centerized(D, s, tsc=False):
|
|
27
|
+
"""Rescales the eigenvalues of the matrix D
|
|
28
|
+
according to their eccentricity. The scale factor is between 0...1 a
|
|
29
|
+
scale factor of 0.5 would not alter the eigenvalues of the matrix D. A
|
|
30
|
+
scale factor of 0 would unify all eigenvalues to one value such that it
|
|
31
|
+
corresponds to a isotropic sphere. A scale factor of 1 alters the
|
|
32
|
+
eigenvalues in such a way that the resulting ellipsoid is fully
|
|
33
|
+
eccentric and anisotropic.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
D : nparray of float
|
|
38
|
+
(3, 3) Diffusion tensor.
|
|
39
|
+
s : float
|
|
40
|
+
Scale parameter [0 (iso) ... 0.5 (unaltered)... 1 (aniso)].
|
|
41
|
+
tsc : bool
|
|
42
|
+
Tensor singularity correction.
|
|
43
|
+
|
|
44
|
+
Returns
|
|
45
|
+
-------
|
|
46
|
+
Ds : np.ndarray of float
|
|
47
|
+
(3, 3) Scaled diffusion tensor.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
# print("Tensor scaling factor: " + str(s))
|
|
51
|
+
# check if tensor matrix contains any element > 0
|
|
52
|
+
if D.any():
|
|
53
|
+
|
|
54
|
+
# reformat data if necessary
|
|
55
|
+
reformat = 0
|
|
56
|
+
|
|
57
|
+
if D.ndim == 1 and D.size == 9:
|
|
58
|
+
D = np.reshape(D, (3, 3))
|
|
59
|
+
reformat = 1
|
|
60
|
+
|
|
61
|
+
# determine eigenvalues of original diffusion tensor matrix
|
|
62
|
+
l, v = np.linalg.eig(D)
|
|
63
|
+
l_idx = np.fliplr(np.argsort(l)[np.newaxis, :])[0]
|
|
64
|
+
l_idx_reverse = np.argsort(l_idx)
|
|
65
|
+
l = l[l_idx]
|
|
66
|
+
v = v[:, l_idx]
|
|
67
|
+
|
|
68
|
+
# calculate eccentricity e = [e12, e13, e23]
|
|
69
|
+
e = ellipse_eccentricity(np.array([l[0], l[0], l[1]]), np.array([l[1], l[2], l[2]]))
|
|
70
|
+
|
|
71
|
+
# calculate volume
|
|
72
|
+
# Vol_old = 4.0/3 * np.pi * L[0]*L[1]*L[2]
|
|
73
|
+
|
|
74
|
+
# scale eccentricity
|
|
75
|
+
if s < 0.5:
|
|
76
|
+
es = 2.0*e*s
|
|
77
|
+
elif s > 0.5:
|
|
78
|
+
es = 2.0*(1-e)*s+2*e-1
|
|
79
|
+
elif s < 0:
|
|
80
|
+
raise ValueError('ERROR: scale parameter s must not be smaller than 0!')
|
|
81
|
+
elif s > 1:
|
|
82
|
+
raise ValueError('ERROR: scale parameter s must not exceed 1!')
|
|
83
|
+
elif s == 0.5:
|
|
84
|
+
es = e
|
|
85
|
+
warnings.warn('Scale parameter s = 0.5 ... diffusion tensor matrix is unaltered!')
|
|
86
|
+
|
|
87
|
+
ls1 = 1
|
|
88
|
+
ls2 = np.sqrt(1 - es[0]**2)
|
|
89
|
+
ls3 = np.sqrt(1 - es[1]**2)
|
|
90
|
+
|
|
91
|
+
Ls = np.array([ls1, ls2, ls3])
|
|
92
|
+
|
|
93
|
+
# calculate scale factor for volume constraint
|
|
94
|
+
scale = (l[0]*l[1]*l[2])/(Ls[0]*Ls[1]*Ls[2])
|
|
95
|
+
|
|
96
|
+
# scale eigenvalues in order to fulfill volume constraint
|
|
97
|
+
Ls = scale**(1.0/3)*Ls
|
|
98
|
+
|
|
99
|
+
# compute scaled diffusion tensor matrix and reorder them
|
|
100
|
+
Ds = np.dot(np.dot(v[:, l_idx_reverse], np.diag(Ls[l_idx_reverse])), v[:, l_idx_reverse].T)
|
|
101
|
+
|
|
102
|
+
# reformat data back again to original format if input was like this
|
|
103
|
+
if reformat:
|
|
104
|
+
Ds = np.reshape(Ds, (9), order='F')
|
|
105
|
+
|
|
106
|
+
elif tsc:
|
|
107
|
+
Ds = np.array([1, 0, 0, 0, 1, 0, 0, 0, 1])
|
|
108
|
+
|
|
109
|
+
else:
|
|
110
|
+
Ds = D
|
|
111
|
+
|
|
112
|
+
return Ds
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def rescale_lambda_centerized_workhorse(D, s, tsc=False):
|
|
116
|
+
"""Rescales the eigenvalues of the matrix D
|
|
117
|
+
according to their eccentricity. The scale factor is between 0...1 a
|
|
118
|
+
scale factor of 0.5 would not alter the eigenvalues of the matrix D. A
|
|
119
|
+
scale factor of 0 would unify all eigenvalues to one value such that it
|
|
120
|
+
corresponds to a isotropic sphere. A scale factor of 1 alters the
|
|
121
|
+
eigenvalues in such a way that the resulting ellipsoid is fully
|
|
122
|
+
eccentric and anisotropic
|
|
123
|
+
|
|
124
|
+
Parameters
|
|
125
|
+
----------
|
|
126
|
+
D : ndarray of float
|
|
127
|
+
(n, 9) Diffusion tensor.
|
|
128
|
+
s : float
|
|
129
|
+
Scale parameter [0 (iso) ... 0.5 (unaltered)... 1 (aniso)].
|
|
130
|
+
tsc : bool
|
|
131
|
+
Tensor singularity correction.
|
|
132
|
+
|
|
133
|
+
Returns
|
|
134
|
+
-------
|
|
135
|
+
Ds : list of nparray of float
|
|
136
|
+
(3, 3) Scaled diffusion tensor
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
Ds = np.empty(D.shape)
|
|
140
|
+
|
|
141
|
+
for i in range(D.shape[0]):
|
|
142
|
+
Ds[i, :] = rescale_lambda_centerized(D[i, :], s, tsc)
|
|
143
|
+
|
|
144
|
+
return Ds
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<InstrumentMarkerList coordinateSpace="RAS">
|
|
3
|
+
<!--All positions are saved in the coordinate system of the corresponding medical data.
|
|
4
|
+
NIfTI image data are recommended using RAS system (x-axis increases from the left hand side to the right hand side of the patient,
|
|
5
|
+
y-axis increases from the posterior side to the anterior side of the patient and z-axis increases from the feet toward the head of the patient).-->
|
|
6
|
+
<InstrumentMarker alwaysVisible="false" index="0" selected="true">
|
|
7
|
+
<Marker additionalInformation="" color="#ff0000" description="test" set="true">
|
|
8
|
+
<Matrix4D data00="0.9013614031176984"
|
|
9
|
+
data01="0.2983920094889285" data02="-0.3138959024047658"
|
|
10
|
+
data03="-71.18429093438886" data10="0.38530408399367894"
|
|
11
|
+
data11="-0.8834528036471245"
|
|
12
|
+
data12="0.26659466328018544" data13="-79.95375674706612"
|
|
13
|
+
data20="-0.1977604402582455"
|
|
14
|
+
data21="-0.3612397546019023"
|
|
15
|
+
data22="-0.9112724377855788" data23="38.69342634326524"
|
|
16
|
+
data30="0.0" data31="0.0" data32="0.0" data33="1.0"/>
|
|
17
|
+
</Marker>
|
|
18
|
+
</InstrumentMarker>
|
|
19
|
+
</InstrumentMarkerList>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<TriggerMarkerList coordinateSpace="RAS" isOnlineReading="false" startTime="16:34:43.636">
|
|
3
|
+
<!--All positions are saved in the coordinate system of the corresponding medical data.
|
|
4
|
+
NIfTI image data are recommended using RAS system (x-axis increases from the left hand side to the right hand side of the patient,
|
|
5
|
+
y-axis increases from the posterior side to the anterior side of the patient and z-axis increases from the feet toward the head of the patient).-->
|
|
6
|
+
<ResponseParameters selectedResponseChannel="0">
|
|
7
|
+
<responseDescription id="response" maxValue="51200.0"
|
|
8
|
+
minValue="-51200.0" name="Response" unit="uV"/>
|
|
9
|
+
<responseDescription id="valueA" maxValue="200.0" minValue="0.0"
|
|
10
|
+
name="Value A (di/dt)" unit="A/us"/>
|
|
11
|
+
<responseDescription id="amplitudeA" maxValue="100.0"
|
|
12
|
+
minValue="0.0" name="Amplitude A" unit="%"/>
|
|
13
|
+
</ResponseParameters>
|
|
14
|
+
</TriggerMarkerList>
|