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.
Files changed (107) hide show
  1. pyNIBS-0.2024.8.dist-info/LICENSE +623 -0
  2. pyNIBS-0.2024.8.dist-info/METADATA +723 -0
  3. pyNIBS-0.2024.8.dist-info/RECORD +107 -0
  4. pyNIBS-0.2024.8.dist-info/WHEEL +5 -0
  5. pyNIBS-0.2024.8.dist-info/top_level.txt +1 -0
  6. pynibs/__init__.py +34 -0
  7. pynibs/coil.py +1367 -0
  8. pynibs/congruence/__init__.py +15 -0
  9. pynibs/congruence/congruence.py +1108 -0
  10. pynibs/congruence/ext_metrics.py +257 -0
  11. pynibs/congruence/stimulation_threshold.py +318 -0
  12. pynibs/data/configuration_exp0.yaml +59 -0
  13. pynibs/data/configuration_linear_MEP.yaml +61 -0
  14. pynibs/data/configuration_linear_RT.yaml +61 -0
  15. pynibs/data/configuration_sigmoid4.yaml +68 -0
  16. pynibs/data/network mapping configuration/configuration guide.md +238 -0
  17. pynibs/data/network mapping configuration/configuration_TEMPLATE.yaml +42 -0
  18. pynibs/data/network mapping configuration/configuration_for_testing.yaml +43 -0
  19. pynibs/data/network mapping configuration/configuration_modelTMS.yaml +43 -0
  20. pynibs/data/network mapping configuration/configuration_reg_isi_05.yaml +43 -0
  21. pynibs/data/network mapping configuration/output_documentation.md +185 -0
  22. pynibs/data/network mapping configuration/recommendations_for_accuracy_threshold.md +77 -0
  23. pynibs/data/neuron/models/L23_PC_cADpyr_biphasic_v1.csv +1281 -0
  24. pynibs/data/neuron/models/L23_PC_cADpyr_monophasic_v1.csv +1281 -0
  25. pynibs/data/neuron/models/L4_LBC_biphasic_v1.csv +1281 -0
  26. pynibs/data/neuron/models/L4_LBC_monophasic_v1.csv +1281 -0
  27. pynibs/data/neuron/models/L4_NBC_biphasic_v1.csv +1281 -0
  28. pynibs/data/neuron/models/L4_NBC_monophasic_v1.csv +1281 -0
  29. pynibs/data/neuron/models/L4_SBC_biphasic_v1.csv +1281 -0
  30. pynibs/data/neuron/models/L4_SBC_monophasic_v1.csv +1281 -0
  31. pynibs/data/neuron/models/L5_TTPC2_cADpyr_biphasic_v1.csv +1281 -0
  32. pynibs/data/neuron/models/L5_TTPC2_cADpyr_monophasic_v1.csv +1281 -0
  33. pynibs/expio/Mep.py +1518 -0
  34. pynibs/expio/__init__.py +8 -0
  35. pynibs/expio/brainsight.py +979 -0
  36. pynibs/expio/brainvis.py +71 -0
  37. pynibs/expio/cobot.py +239 -0
  38. pynibs/expio/exp.py +1876 -0
  39. pynibs/expio/fit_funs.py +287 -0
  40. pynibs/expio/localite.py +1987 -0
  41. pynibs/expio/signal_ced.py +51 -0
  42. pynibs/expio/visor.py +624 -0
  43. pynibs/freesurfer.py +502 -0
  44. pynibs/hdf5_io/__init__.py +10 -0
  45. pynibs/hdf5_io/hdf5_io.py +1857 -0
  46. pynibs/hdf5_io/xdmf.py +1542 -0
  47. pynibs/mesh/__init__.py +3 -0
  48. pynibs/mesh/mesh_struct.py +1394 -0
  49. pynibs/mesh/transformations.py +866 -0
  50. pynibs/mesh/utils.py +1103 -0
  51. pynibs/models/_TMS.py +211 -0
  52. pynibs/models/__init__.py +0 -0
  53. pynibs/muap.py +392 -0
  54. pynibs/neuron/__init__.py +2 -0
  55. pynibs/neuron/neuron_regression.py +284 -0
  56. pynibs/neuron/util.py +58 -0
  57. pynibs/optimization/__init__.py +5 -0
  58. pynibs/optimization/multichannel.py +278 -0
  59. pynibs/optimization/opt_mep.py +152 -0
  60. pynibs/optimization/optimization.py +1445 -0
  61. pynibs/optimization/workhorses.py +698 -0
  62. pynibs/pckg/__init__.py +0 -0
  63. pynibs/pckg/biosig/biosig4c++-1.9.5.src_fixed.tar.gz +0 -0
  64. pynibs/pckg/libeep/__init__.py +0 -0
  65. pynibs/pckg/libeep/pyeep.so +0 -0
  66. pynibs/regression/__init__.py +11 -0
  67. pynibs/regression/dual_node_detection.py +2375 -0
  68. pynibs/regression/regression.py +2984 -0
  69. pynibs/regression/score_types.py +0 -0
  70. pynibs/roi/__init__.py +2 -0
  71. pynibs/roi/roi.py +895 -0
  72. pynibs/roi/roi_structs.py +1233 -0
  73. pynibs/subject.py +1009 -0
  74. pynibs/tensor_scaling.py +144 -0
  75. pynibs/tests/data/InstrumentMarker20200225163611937.xml +19 -0
  76. pynibs/tests/data/TriggerMarkers_Coil0_20200225163443682.xml +14 -0
  77. pynibs/tests/data/TriggerMarkers_Coil1_20200225170337572.xml +6373 -0
  78. pynibs/tests/data/Xdmf.dtd +89 -0
  79. pynibs/tests/data/brainsight_niiImage_nifticoord.txt +145 -0
  80. pynibs/tests/data/brainsight_niiImage_nifticoord_largefile.txt +1434 -0
  81. pynibs/tests/data/brainsight_niiImage_niifticoord_mixedtargets.txt +47 -0
  82. pynibs/tests/data/create_subject_testsub.py +332 -0
  83. pynibs/tests/data/data.hdf5 +0 -0
  84. pynibs/tests/data/geo.hdf5 +0 -0
  85. pynibs/tests/test_coil.py +474 -0
  86. pynibs/tests/test_elements2nodes.py +100 -0
  87. pynibs/tests/test_hdf5_io/test_xdmf.py +61 -0
  88. pynibs/tests/test_mesh_transformations.py +123 -0
  89. pynibs/tests/test_mesh_utils.py +143 -0
  90. pynibs/tests/test_nnav_imports.py +101 -0
  91. pynibs/tests/test_quality_measures.py +117 -0
  92. pynibs/tests/test_regressdata.py +289 -0
  93. pynibs/tests/test_roi.py +17 -0
  94. pynibs/tests/test_rotations.py +86 -0
  95. pynibs/tests/test_subject.py +71 -0
  96. pynibs/tests/test_util.py +24 -0
  97. pynibs/tms_pulse.py +34 -0
  98. pynibs/util/__init__.py +4 -0
  99. pynibs/util/dosing.py +233 -0
  100. pynibs/util/quality_measures.py +562 -0
  101. pynibs/util/rotations.py +340 -0
  102. pynibs/util/simnibs.py +763 -0
  103. pynibs/util/util.py +727 -0
  104. pynibs/visualization/__init__.py +2 -0
  105. pynibs/visualization/para.py +4372 -0
  106. pynibs/visualization/plot_2D.py +137 -0
  107. pynibs/visualization/render_3D.py +347 -0
@@ -0,0 +1,152 @@
1
+ """
2
+ Functions to select optimal stimulation conditions based on the estimated y (i.e., MEPs in MEP studies).
3
+ """
4
+
5
+ import numpy as np
6
+
7
+
8
+ def get_fim_sample(fun, x, p):
9
+ """
10
+ Get Fisher Information Matrix of one single sample.
11
+
12
+ Parameters
13
+ ----------
14
+ fun : callable
15
+ Callable the fisher information matrix is calculated for. The sample is passed as the first argument.
16
+ x : float
17
+ Sample passed to function.
18
+ p : dict
19
+ Dictionary containing the parameter estimates. The keys are the parameter names of fun.
20
+
21
+ Returns
22
+ -------
23
+ fim_matrix : np.ndarray of float
24
+ (n_params, n_params) Fisher information matrix.
25
+ """
26
+
27
+ # read function arguments
28
+ params = p.keys()
29
+
30
+ # determine gradient of function w.r.t. parameters using forward approximation
31
+ dfdp = np.zeros(len(params))
32
+
33
+ for i, para in enumerate(params):
34
+ # copy original params dict
35
+ p_dp = dict()
36
+
37
+ for pa in params:
38
+ p_dp[pa] = p[pa]
39
+
40
+ # perturb parameter
41
+ dp = p[para] / 1000
42
+ p_dp[para] = p[para] + dp
43
+
44
+ # determine gradient with forward approximation
45
+ dfdp[i] = (fun(x, **p_dp) - fun(x, **p)) / dp
46
+
47
+ fim_matrix = np.outer(dfdp, dfdp)
48
+
49
+ return fim_matrix
50
+
51
+
52
+ def get_det_fim(x, fun, p, fim_matrix):
53
+ """
54
+ Updates the Fisher Information Matrix and returns the negative determinant based on the sample x.
55
+ It is a score how much information the additional sample yields.
56
+
57
+ Parameters
58
+ ----------
59
+ fun : callable
60
+ Callable defined in interval [0, 1].
61
+ x : float
62
+ Single sample location (interval [0, 1]).
63
+ p : dict
64
+ Dictionary containing the parameter estimates. The keys are the parameter names of fun.
65
+ fim_matrix : np.ndarray of float
66
+ (n_params, n_params) Fisher Information Matrix.
67
+
68
+ Returns
69
+ -------
70
+ det : float
71
+ Determinant of the Fisher Information Matrix after adding sample x.
72
+ """
73
+ fim_matrix_sample = fim_matrix + get_fim_sample(fun=fun, x=x, p=p)
74
+ sign, logdet = np.linalg.slogdet(fim_matrix_sample)
75
+
76
+ return -sign * np.exp(logdet)
77
+
78
+
79
+ def init_fim_matrix(fun, x, p):
80
+ """
81
+ Initializes the Fisher Information Matrix based on the samples given in x.
82
+
83
+ Parameters
84
+ ----------
85
+ fun : callable
86
+ Callable defined in interval [0, 1].
87
+ x : np.ndarray of float
88
+ Initial sample locations (interval [0, 1]).
89
+ p : dict
90
+ Dictionary containing the parameter estimates. The keys are the parameter names of fun.
91
+
92
+ Returns
93
+ -------
94
+ fim_matrix : np.ndarray of float [n_params x n_params]
95
+ Fisher Information Matrix.
96
+ """
97
+ fim_matrix = np.zeros((len(p), len(p)))
98
+
99
+ for x_i in x:
100
+ fim_matrix += get_fim_sample(fun=fun, x=x_i, p=p)
101
+
102
+ return fim_matrix
103
+
104
+
105
+ def get_optimal_sample_fim(fun, p, x=None):
106
+ """
107
+ Determines optimal location of next sample by maximizing the determinant of the Fisher Information Matrix.
108
+
109
+ Parameters
110
+ ----------
111
+ fun : callable
112
+ Callable (interval [0, 1]).
113
+ x : np.ndarray of float, optional
114
+ Previous sample locations (interval [0, 1]).
115
+ p : dict
116
+ Dictionary containing the parameter estimates. The keys are the parameter names of fun.
117
+
118
+ Returns
119
+ -------
120
+ x_opt : float
121
+ Optimal location of next sample (interval [0, 1]).
122
+ """
123
+ # initialize fim matrix with initial samples
124
+ if x is None:
125
+ fim_matrix = np.zeros((len(p), len(p)))
126
+ else:
127
+ fim_matrix = init_fim_matrix(fun=fun, x=x, p=p)
128
+
129
+ # run optimization
130
+ # res = minimize(fun=get_det_fim,
131
+ # method="trust-constr",
132
+ # bounds=((0, 1),),
133
+ # x0=np.array([0.5]),
134
+ # args=(fun, p, fim_matrix),
135
+ # options={"finite_diff_rel_step": 0.05, "xtol": 0.01})
136
+
137
+ # res = minimize(fun=get_det_fim,
138
+ # method="SLSQP",
139
+ # x0=np.array([0.5]),
140
+ # bounds=((0, 1),),
141
+ # args=(fun, p, fim_matrix),
142
+ # options={'disp': None, "eps": 0.001, "ftol": 1e-12}) #,
143
+ # return res.x[0]
144
+
145
+ x_bf = np.linspace(0, 1, 200)
146
+ det = np.zeros(len(x_bf))
147
+ for i in range(len(x_bf)):
148
+ det[i] = get_det_fim(x=x_bf[i], fun=fun, p=p, fim_matrix=fim_matrix)
149
+
150
+ x_opt = x_bf[np.argmin(det)]
151
+
152
+ return x_opt