pyNIBS 0.2024.8__py3-none-any.whl → 0.2026.1__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/__init__.py +26 -14
- pynibs/coil/__init__.py +6 -0
- pynibs/{coil.py → coil/coil.py} +213 -543
- pynibs/coil/export.py +508 -0
- pynibs/congruence/__init__.py +4 -1
- pynibs/congruence/congruence.py +37 -45
- pynibs/congruence/ext_metrics.py +40 -11
- pynibs/congruence/stimulation_threshold.py +1 -2
- pynibs/expio/Mep.py +120 -370
- pynibs/expio/__init__.py +10 -0
- pynibs/expio/brainsight.py +34 -37
- pynibs/expio/cobot.py +25 -25
- pynibs/expio/exp.py +10 -7
- pynibs/expio/fit_funs.py +3 -0
- pynibs/expio/invesalius.py +70 -0
- pynibs/expio/localite.py +190 -91
- pynibs/expio/neurone.py +139 -0
- pynibs/expio/signal_ced.py +345 -2
- pynibs/expio/visor.py +16 -15
- pynibs/freesurfer.py +34 -33
- pynibs/hdf5_io/hdf5_io.py +149 -132
- pynibs/hdf5_io/xdmf.py +35 -31
- pynibs/mesh/__init__.py +1 -1
- pynibs/mesh/mesh_struct.py +77 -92
- pynibs/mesh/transformations.py +121 -21
- pynibs/mesh/utils.py +191 -99
- pynibs/models/_TMS.py +2 -1
- pynibs/muap.py +1 -2
- pynibs/neuron/__init__.py +10 -0
- pynibs/neuron/models/mep.py +566 -0
- pynibs/neuron/neuron_regression.py +98 -8
- pynibs/optimization/__init__.py +12 -2
- pynibs/optimization/{optimization.py → coil_opt.py} +157 -133
- pynibs/optimization/multichannel.py +1174 -24
- pynibs/optimization/workhorses.py +7 -8
- pynibs/regression/__init__.py +4 -2
- pynibs/regression/dual_node_detection.py +229 -219
- pynibs/regression/regression.py +92 -61
- pynibs/roi/__init__.py +4 -1
- pynibs/roi/roi_structs.py +19 -21
- pynibs/roi/{roi.py → roi_utils.py} +56 -33
- pynibs/subject.py +24 -14
- pynibs/util/__init__.py +20 -4
- pynibs/util/dosing.py +4 -5
- pynibs/util/quality_measures.py +39 -38
- pynibs/util/rotations.py +116 -9
- pynibs/util/{simnibs.py → simnibs_io.py} +29 -19
- pynibs/util/{util.py → utils.py} +20 -22
- pynibs/visualization/para.py +4 -4
- pynibs/visualization/render_3D.py +4 -4
- pynibs-0.2026.1.dist-info/METADATA +105 -0
- pynibs-0.2026.1.dist-info/RECORD +69 -0
- {pyNIBS-0.2024.8.dist-info → pynibs-0.2026.1.dist-info}/WHEEL +1 -1
- pyNIBS-0.2024.8.dist-info/METADATA +0 -723
- pyNIBS-0.2024.8.dist-info/RECORD +0 -107
- pynibs/data/configuration_exp0.yaml +0 -59
- pynibs/data/configuration_linear_MEP.yaml +0 -61
- pynibs/data/configuration_linear_RT.yaml +0 -61
- pynibs/data/configuration_sigmoid4.yaml +0 -68
- pynibs/data/network mapping configuration/configuration guide.md +0 -238
- pynibs/data/network mapping configuration/configuration_TEMPLATE.yaml +0 -42
- pynibs/data/network mapping configuration/configuration_for_testing.yaml +0 -43
- pynibs/data/network mapping configuration/configuration_modelTMS.yaml +0 -43
- pynibs/data/network mapping configuration/configuration_reg_isi_05.yaml +0 -43
- pynibs/data/network mapping configuration/output_documentation.md +0 -185
- pynibs/data/network mapping configuration/recommendations_for_accuracy_threshold.md +0 -77
- pynibs/data/neuron/models/L23_PC_cADpyr_biphasic_v1.csv +0 -1281
- pynibs/data/neuron/models/L23_PC_cADpyr_monophasic_v1.csv +0 -1281
- pynibs/data/neuron/models/L4_LBC_biphasic_v1.csv +0 -1281
- pynibs/data/neuron/models/L4_LBC_monophasic_v1.csv +0 -1281
- pynibs/data/neuron/models/L4_NBC_biphasic_v1.csv +0 -1281
- pynibs/data/neuron/models/L4_NBC_monophasic_v1.csv +0 -1281
- pynibs/data/neuron/models/L4_SBC_biphasic_v1.csv +0 -1281
- pynibs/data/neuron/models/L4_SBC_monophasic_v1.csv +0 -1281
- pynibs/data/neuron/models/L5_TTPC2_cADpyr_biphasic_v1.csv +0 -1281
- pynibs/data/neuron/models/L5_TTPC2_cADpyr_monophasic_v1.csv +0 -1281
- pynibs/tests/data/InstrumentMarker20200225163611937.xml +0 -19
- pynibs/tests/data/TriggerMarkers_Coil0_20200225163443682.xml +0 -14
- pynibs/tests/data/TriggerMarkers_Coil1_20200225170337572.xml +0 -6373
- pynibs/tests/data/Xdmf.dtd +0 -89
- pynibs/tests/data/brainsight_niiImage_nifticoord.txt +0 -145
- pynibs/tests/data/brainsight_niiImage_nifticoord_largefile.txt +0 -1434
- pynibs/tests/data/brainsight_niiImage_niifticoord_mixedtargets.txt +0 -47
- pynibs/tests/data/create_subject_testsub.py +0 -332
- pynibs/tests/data/data.hdf5 +0 -0
- pynibs/tests/data/geo.hdf5 +0 -0
- pynibs/tests/test_coil.py +0 -474
- pynibs/tests/test_elements2nodes.py +0 -100
- pynibs/tests/test_hdf5_io/test_xdmf.py +0 -61
- pynibs/tests/test_mesh_transformations.py +0 -123
- pynibs/tests/test_mesh_utils.py +0 -143
- pynibs/tests/test_nnav_imports.py +0 -101
- pynibs/tests/test_quality_measures.py +0 -117
- pynibs/tests/test_regressdata.py +0 -289
- pynibs/tests/test_roi.py +0 -17
- pynibs/tests/test_rotations.py +0 -86
- pynibs/tests/test_subject.py +0 -71
- pynibs/tests/test_util.py +0 -24
- /pynibs/{regression/score_types.py → neuron/models/m1_montbrio.py} +0 -0
- {pyNIBS-0.2024.8.dist-info → pynibs-0.2026.1.dist-info/licenses}/LICENSE +0 -0
- {pyNIBS-0.2024.8.dist-info → pynibs-0.2026.1.dist-info}/top_level.txt +0 -0
pynibs/congruence/congruence.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import h5py
|
|
3
|
-
import numpy as np
|
|
4
3
|
import yaml
|
|
4
|
+
import numpy as np
|
|
5
5
|
import pynibs
|
|
6
6
|
|
|
7
7
|
|
|
@@ -15,15 +15,14 @@ def cf_curveshift_workhorse_stretch_correction(elm_idx_list, mep, mep_params, e,
|
|
|
15
15
|
Parameters
|
|
16
16
|
----------
|
|
17
17
|
elm_idx_list : np.ndarray
|
|
18
|
-
(chunksize) List of element indices, the congruence factor is computed for
|
|
18
|
+
(chunksize) List of element indices, the congruence factor is computed for.
|
|
19
19
|
mep : list of :py:class:`~pynibs.expio.Mep`
|
|
20
20
|
(n_cond) List of fitted Mep object instances for all conditions.
|
|
21
21
|
mep_params : np.ndarray of float
|
|
22
22
|
(n_mep_params_total) List of all mep parameters of curve fits used to calculate the MEP,
|
|
23
23
|
accumulated into one array.
|
|
24
24
|
|
|
25
|
-
* e.g. [``mep_#1_para_#1``, ``mep_#1_para_#2``, ``mep_#1_para_#3``,
|
|
26
|
-
``mep_#2_para_#1``, ``mep_#2_para_#1``, ...]
|
|
25
|
+
* e.g. [``mep_#1_para_#1``, ``mep_#1_para_#2``, ``mep_#1_para_#3``, ``mep_#2_para_#1``, ``mep_#2_para_#1``, ...]
|
|
27
26
|
|
|
28
27
|
e : list of list of np.ndarray of float
|
|
29
28
|
[n_cond][n_datasets][n_elm] Tuple of n_datasets of the electric field to compute the congruence factor for,
|
|
@@ -31,7 +30,7 @@ def cf_curveshift_workhorse_stretch_correction(elm_idx_list, mep, mep_params, e,
|
|
|
31
30
|
Each dataset is a list over all conditions containing the electric field component of interest
|
|
32
31
|
|
|
33
32
|
* e.g.: ``len(e) = n_cond``
|
|
34
|
-
* ``len(e[0]) = n_comp`` (e.g: ``e_mag = e[0]
|
|
33
|
+
* ``len(e[0]) = n_comp`` (e.g: ``e_mag = e[0]``)
|
|
35
34
|
|
|
36
35
|
n_samples : int, default=100
|
|
37
36
|
Number of data points to generate discrete mep and e curves.
|
|
@@ -41,7 +40,6 @@ def cf_curveshift_workhorse_stretch_correction(elm_idx_list, mep, mep_params, e,
|
|
|
41
40
|
congruence_factor : np.ndarray of float
|
|
42
41
|
(n_roi, n_datasets) Congruence factor in each element specified in elm_idx_list and for each input dataset.
|
|
43
42
|
"""
|
|
44
|
-
|
|
45
43
|
stepsize = 1e-1
|
|
46
44
|
n_datasets = len(e[0])
|
|
47
45
|
n_elm = len(elm_idx_list)
|
|
@@ -94,7 +92,7 @@ def cf_curveshift_workhorse_stretch_correction(elm_idx_list, mep, mep_params, e,
|
|
|
94
92
|
# find median mep cond
|
|
95
93
|
e_mean = np.mean((e_max + e_min) / 2)
|
|
96
94
|
|
|
97
|
-
# return
|
|
95
|
+
# return nan if xmax-xmin is smaller than stepsize
|
|
98
96
|
if np.any(e_max - e_min <= stepsize):
|
|
99
97
|
congruence_factor[elm_idx, i_datasets] = np.nan
|
|
100
98
|
|
|
@@ -161,9 +159,9 @@ def cf_curveshift_workhorse_stretch_correction(elm_idx_list, mep, mep_params, e,
|
|
|
161
159
|
|
|
162
160
|
# length of shifted curve as a function of position (gets longer while shifting)
|
|
163
161
|
len_mep_idx_shift = np.round(np.linspace(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
len_e_mep_start,
|
|
163
|
+
len_e_mep_end,
|
|
164
|
+
len_e_mep_start + len_e_ref + 2 * stepsize_local_shift[reference_idx]))
|
|
167
165
|
|
|
168
166
|
# construct shift array (there are less 0 at the beginning and more at the end because the mep
|
|
169
167
|
# curve is stretched during shifting)
|
|
@@ -184,7 +182,7 @@ def cf_curveshift_workhorse_stretch_correction(elm_idx_list, mep, mep_params, e,
|
|
|
184
182
|
slice_indices = np.outer(len_mep_idx_shift[:, np.newaxis],
|
|
185
183
|
np.linspace(0, 1, len_e_mep_start)[np.newaxis, :])
|
|
186
184
|
slice_indices = np.round(
|
|
187
|
-
|
|
185
|
+
np.add(slice_indices, np.arange(slice_indices.shape[0])[:, np.newaxis])).astype(int)
|
|
188
186
|
|
|
189
187
|
# the error is y-difference between mep[idx] and mep[reference].zero_padded
|
|
190
188
|
err = np.sqrt(np.sum((shift_array[slice_indices] - mep_shift) ** 2, axis=1))
|
|
@@ -266,8 +264,8 @@ def cf_curveshift_workhorse_stretch_correction_new(mep, mep_params, e, n_samples
|
|
|
266
264
|
mep_c_shift = mep[idx].eval(i_c_shift, mep_params_c[i])
|
|
267
265
|
# generate index shift list to compare curves
|
|
268
266
|
slice_indices = np.outer(
|
|
269
|
-
|
|
270
|
-
|
|
267
|
+
np.round(np.linspace(n_c_before[i], n_c_after[i], n_c_before[i] + n_samples))[:, np.newaxis],
|
|
268
|
+
np.linspace(0, 1, n_c_before[i])[np.newaxis, :])
|
|
271
269
|
slice_indices = np.round(slice_indices + np.arange(slice_indices.shape[0])[:, np.newaxis])
|
|
272
270
|
slice_indices = (slice_indices + (np.max(n_c_before) - n_c_before[i])).astype(int)
|
|
273
271
|
# the error is y-difference between mep[idx] and mep[reference].zero_padded
|
|
@@ -301,7 +299,7 @@ def cf_curveshift_workhorse_stretch_correction_sign_new(mep, mep_params, e, n_sa
|
|
|
301
299
|
Worker function for congruence factor computation - call from :py:class:`multiprocessing.Pool`.
|
|
302
300
|
Calculates congruence factor for ``e = (E_mag, E_norm and/or E_tan)`` for given zaps and elements.
|
|
303
301
|
The computations are parallelized in terms of element indices (``elm_idx_list``).
|
|
304
|
-
``n_sample``
|
|
302
|
+
``n_sample`` are taken from fitted_mep, within the range of the :py:class:`~pynibs.expio.Mep`.
|
|
305
303
|
|
|
306
304
|
Parameters
|
|
307
305
|
----------
|
|
@@ -379,8 +377,8 @@ def cf_curveshift_workhorse_stretch_correction_sign_new(mep, mep_params, e, n_sa
|
|
|
379
377
|
mep_c_shift = mep[idx].eval(i_c_shift, mep_params_c[i])
|
|
380
378
|
# generate index shift list to compare curves
|
|
381
379
|
slice_indices = np.outer(
|
|
382
|
-
|
|
383
|
-
|
|
380
|
+
np.round(np.linspace(n_c_before[i], n_c_after[i], n_c_before[i] + n_samples))[:, np.newaxis],
|
|
381
|
+
np.linspace(0, 1, n_c_before[i])[np.newaxis, :])
|
|
384
382
|
slice_indices = np.round(slice_indices + np.arange(slice_indices.shape[0])[:, np.newaxis])
|
|
385
383
|
slice_indices = (slice_indices + (np.max(n_c_before) - n_c_before[i])).astype(int)
|
|
386
384
|
# the error is y-difference between mep[idx] and mep[reference].zero_padded
|
|
@@ -472,7 +470,6 @@ def cf_curveshift_workhorse_stretch_correction_variance(elm_idx_list, mep, mep_p
|
|
|
472
470
|
congruence_factor : np.ndarray of float [n_roi, n_datasets]
|
|
473
471
|
Congruence factor in each element specified in elm_idx_list and for each input dataset
|
|
474
472
|
"""
|
|
475
|
-
|
|
476
473
|
stepsize = 1e-1
|
|
477
474
|
n_datasets = len(e[0])
|
|
478
475
|
n_elm = len(elm_idx_list)
|
|
@@ -527,7 +524,7 @@ def cf_curveshift_workhorse_stretch_correction_variance(elm_idx_list, mep, mep_p
|
|
|
527
524
|
# find median mep cond
|
|
528
525
|
e_mean = np.mean((e_max + e_min) / 2)
|
|
529
526
|
|
|
530
|
-
# return
|
|
527
|
+
# return nan if xmax-xmin is smaller than stepsize
|
|
531
528
|
if np.any(e_max - e_min <= stepsize):
|
|
532
529
|
congruence_factor[elm_idx, i_datasets] = np.nan
|
|
533
530
|
|
|
@@ -591,9 +588,9 @@ def cf_curveshift_workhorse_stretch_correction_variance(elm_idx_list, mep, mep_p
|
|
|
591
588
|
|
|
592
589
|
# length of shifted curve as a function of position (gets longer while shifting)
|
|
593
590
|
len_mep_idx_shift = np.round(np.linspace(
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
591
|
+
len_e_mep_start,
|
|
592
|
+
len_e_mep_end,
|
|
593
|
+
len_e_mep_start + len_e_ref + 2 * stepsize_local_shift[reference_idx]))
|
|
597
594
|
|
|
598
595
|
# construct shift array (there are less 0 at the beginning and more at the end because the mep
|
|
599
596
|
# curve is stretched during shifting)
|
|
@@ -614,7 +611,7 @@ def cf_curveshift_workhorse_stretch_correction_variance(elm_idx_list, mep, mep_p
|
|
|
614
611
|
slice_indices = np.outer(len_mep_idx_shift[:, np.newaxis],
|
|
615
612
|
np.linspace(0, 1, len_e_mep_start)[np.newaxis, :])
|
|
616
613
|
slice_indices = np.round(
|
|
617
|
-
|
|
614
|
+
np.add(slice_indices, np.arange(slice_indices.shape[0])[:, np.newaxis])).astype(int)
|
|
618
615
|
|
|
619
616
|
# the error is y-difference between mep[idx] and mep[reference].zero_padded
|
|
620
617
|
err = np.sqrt(np.sum((shift_array[slice_indices] - mep_shift) ** 2, axis=1))
|
|
@@ -642,10 +639,9 @@ def cf_variance_workhorse(elm_idx_list, mep, mep_params, e, old_style=True):
|
|
|
642
639
|
mep: list of :py:class:`~pynibs.expio.Mep`
|
|
643
640
|
(n_cond) List of fitted Mep object instances for all conditions.
|
|
644
641
|
mep_params: np.ndarray of float
|
|
645
|
-
(n_mep_params_total) List of all mep parameters used to calculate the MEP, accumulated into one array
|
|
642
|
+
(n_mep_params_total) List of all mep parameters used to calculate the MEP, accumulated into one array.
|
|
646
643
|
|
|
647
|
-
* e.g. [``mep_#1_para_#1``, ``mep_#1_para_#2``, ``mep_#1_para_#3``, ``mep_#2_para_#1``,
|
|
648
|
-
``mep_#2_para_#1``, ...])
|
|
644
|
+
* e.g. [``mep_#1_para_#1``, ``mep_#1_para_#2``, ``mep_#1_para_#3``, ``mep_#2_para_#1``,``mep_#2_para_#1``, ...])
|
|
649
645
|
|
|
650
646
|
e: list of list of np.ndarray of float
|
|
651
647
|
[n_cond][n_datasets][n_elm] Tuple of ``n_datasets`` of the electric field to compute the congruence factor for,
|
|
@@ -653,7 +649,7 @@ def cf_variance_workhorse(elm_idx_list, mep, mep_params, e, old_style=True):
|
|
|
653
649
|
Each dataset is a list over all conditions containing the electric field component of interest
|
|
654
650
|
|
|
655
651
|
* ``len(e) = n_cond``
|
|
656
|
-
* ``len(e[0]) = n_comp`` (e.g: ``e_mag = e[0]
|
|
652
|
+
* ``len(e[0]) = n_comp`` (e.g: ``e_mag = e[0]``)
|
|
657
653
|
|
|
658
654
|
old_style: bool, default: True
|
|
659
655
|
True: Weight ``var(x_0_prime(r))`` with ``mean(e(r) * mean(Stimulator Intensity)``, taken from ``mep``
|
|
@@ -662,7 +658,7 @@ def cf_variance_workhorse(elm_idx_list, mep, mep_params, e, old_style=True):
|
|
|
662
658
|
Returns
|
|
663
659
|
-------
|
|
664
660
|
congruence_factor: np.ndarray of float
|
|
665
|
-
(n_roi, n_datasets) Congruence factor in each element specified in elm_idx_list and for each input dataset
|
|
661
|
+
(n_roi, n_datasets) Congruence factor in each element specified in elm_idx_list and for each input dataset.
|
|
666
662
|
"""
|
|
667
663
|
n_datasets = len(e[0])
|
|
668
664
|
n_elm = len(elm_idx_list)
|
|
@@ -805,8 +801,7 @@ def cf_curveshift_workhorse(elm_idx_list, mep, mep_params, e, n_samples=100):
|
|
|
805
801
|
(n_mep_params_total) List of all mep parameters of curve fits used to calculate the MEP,
|
|
806
802
|
accumulated into one array.
|
|
807
803
|
|
|
808
|
-
* e.g. [``mep_#1_para_#1``, ``mep_#1_para_#2``, ``mep_#1_para_#3``,
|
|
809
|
-
``mep_#2_para_#1``, ``mep_#2_para_#1``, ...]
|
|
804
|
+
* e.g. [``mep_#1_para_#1``, ``mep_#1_para_#2``, ``mep_#1_para_#3``,``mep_#2_para_#1``, ``mep_#2_para_#1``, ...]
|
|
810
805
|
|
|
811
806
|
e : list of list of np.ndarray of float
|
|
812
807
|
[n_cond][n_datasets][n_elm] Tuple of ``n_datasets`` of the electric field to compute the congruence factor for,
|
|
@@ -823,7 +818,6 @@ def cf_curveshift_workhorse(elm_idx_list, mep, mep_params, e, n_samples=100):
|
|
|
823
818
|
-------
|
|
824
819
|
congruence_factor: np.ndarray of float
|
|
825
820
|
(n_roi, n_datasets) Congruence factor in each element specified in elm_idx_list and for each input dataset.
|
|
826
|
-
|
|
827
821
|
"""
|
|
828
822
|
n_datasets = len(e[0])
|
|
829
823
|
n_elm = len(elm_idx_list)
|
|
@@ -895,7 +889,6 @@ def cf_curveshift_kernel(e_curve, mep_curve):
|
|
|
895
889
|
congruence_factor: float
|
|
896
890
|
Congruence factor for the n_cond electric field and MEP curves.
|
|
897
891
|
"""
|
|
898
|
-
|
|
899
892
|
stepsize = 1e-1
|
|
900
893
|
n_condition = len(mep_curve)
|
|
901
894
|
e_min = np.min(e_curve, axis=1) # minima of electric field for every condition
|
|
@@ -904,7 +897,7 @@ def cf_curveshift_kernel(e_curve, mep_curve):
|
|
|
904
897
|
e_max = np.max(e_curve, axis=1) # maxima of electric field for every condition
|
|
905
898
|
e_max = np.floor(e_max / stepsize) * stepsize
|
|
906
899
|
|
|
907
|
-
# return
|
|
900
|
+
# return nan if xmax-xmin is smaller than stepsize
|
|
908
901
|
if np.any(e_max - e_min <= stepsize):
|
|
909
902
|
return np.nan
|
|
910
903
|
|
|
@@ -997,26 +990,25 @@ def extract_condition_combination(fn_config_cfg, fn_results_hdf5, conds, fn_out_
|
|
|
997
990
|
Parameters
|
|
998
991
|
----------
|
|
999
992
|
fn_config_cfg : str
|
|
1000
|
-
Filename of .cfg file the permutation study was
|
|
993
|
+
Filename of .cfg file the permutation study was conducted with.
|
|
1001
994
|
fn_results_hdf5 : str
|
|
1002
995
|
Filename of ``.hdf5`` results file generated by ``00_run_c_standard_compute_all_permutations.py``
|
|
1003
996
|
containing congruence factors and condition combinations.
|
|
1004
997
|
conds : list of str
|
|
1005
998
|
(n_cond) List containing condition combinations to extract and plot,
|
|
1006
|
-
e.g. ``['P_0', 'I_225', 'M1_0', 'I_675', 'P_225']
|
|
999
|
+
e.g. ``['P_0', 'I_225', 'M1_0', 'I_675', 'P_225']``.
|
|
1007
1000
|
fn_out_prefix : str
|
|
1008
|
-
Prefix of output filenames of
|
|
1001
|
+
Prefix of output filenames of \*_data.xdmf, \*_data.hdf5 and \*_geo.hdf5.
|
|
1009
1002
|
|
|
1010
1003
|
Returns
|
|
1011
1004
|
-------
|
|
1012
1005
|
<fn_out_prefix_data.xdmf> : .xdmf file
|
|
1013
|
-
Output file linking
|
|
1006
|
+
Output file linking \*_data.hdf5 and \*_geo.hdf5 file to plot in paraview.
|
|
1014
1007
|
<fn_out_prefix_data.hdf5> : .hdf5 file
|
|
1015
1008
|
Output .hdf5 file containing the data.
|
|
1016
1009
|
<fn_out_prefix_geo.xdmf> : .hdf5 file
|
|
1017
1010
|
Output .hdf5 file containing the geometry information.
|
|
1018
1011
|
"""
|
|
1019
|
-
|
|
1020
1012
|
# Read config file
|
|
1021
1013
|
with open(fn_config_cfg, 'r') as f:
|
|
1022
1014
|
config = yaml.load(f)
|
|
@@ -1069,14 +1061,14 @@ def extract_condition_combination(fn_config_cfg, fn_results_hdf5, conds, fn_out_
|
|
|
1069
1061
|
|
|
1070
1062
|
# recreate complete midlayer surface to write in .hdf5 geo file
|
|
1071
1063
|
points_midlayer, con_midlayer = pynibs.make_GM_WM_surface(
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1064
|
+
gm_surf_fname=os.path.join(mesh_folder, subject.mesh[mesh_idx]['fn_lh_gm']),
|
|
1065
|
+
wm_surf_fname=os.path.join(mesh_folder, subject.mesh[mesh_idx]['fn_lh_wm']),
|
|
1066
|
+
delta=subject.roi[mesh_idx][roi_idx]['delta'],
|
|
1067
|
+
x_roi=None,
|
|
1068
|
+
y_roi=None,
|
|
1069
|
+
z_roi=None,
|
|
1070
|
+
layer=1,
|
|
1071
|
+
fn_mask=None)
|
|
1080
1072
|
|
|
1081
1073
|
# write output files
|
|
1082
1074
|
# save .hdf5 _geo file
|
pynibs/congruence/ext_metrics.py
CHANGED
|
@@ -16,7 +16,7 @@ def rsd_inverse_workhorse(elm_idx_list, mep, e):
|
|
|
16
16
|
Parameters
|
|
17
17
|
----------
|
|
18
18
|
elm_idx_list : np.ndarray
|
|
19
|
-
|
|
19
|
+
(chunksize) List of element indices, the congruence factor is computed for
|
|
20
20
|
mep: list of :py:class:`~pynibs.expio.Mep`
|
|
21
21
|
(n_cond) List of fitted Mep object instances for all conditions.
|
|
22
22
|
e: list of list of np.ndarray of float
|
|
@@ -38,7 +38,6 @@ def rsd_inverse_workhorse(elm_idx_list, mep, e):
|
|
|
38
38
|
Where does TMS stimulate the motor cortex? Combining electrophysiological measurements and realistic field
|
|
39
39
|
estimates to reveal the affected cortex position. Cerebral Cortex, 27(11), 5083-5094.
|
|
40
40
|
"""
|
|
41
|
-
|
|
42
41
|
n_datasets = len(e[0])
|
|
43
42
|
n_elm = len(elm_idx_list)
|
|
44
43
|
n_conditions = len(mep)
|
|
@@ -61,6 +60,38 @@ def rsd_inverse_workhorse(elm_idx_list, mep, e):
|
|
|
61
60
|
|
|
62
61
|
|
|
63
62
|
def dvs_likelihood(params, x, y, verbose=True, normalize=False, bounds=[(1, 2), (1, 2)]):
|
|
63
|
+
"""
|
|
64
|
+
Calculate the log likelihood of the DVS model with test data.
|
|
65
|
+
|
|
66
|
+
Parameters
|
|
67
|
+
----------
|
|
68
|
+
params : list of float
|
|
69
|
+
List of parameters for the DVS model. The first two parameters are `sigma_x` and `sigma_y`,
|
|
70
|
+
and the remaining parameters are model-specific.
|
|
71
|
+
x : np.ndarray
|
|
72
|
+
Array of input data for the DVS model.
|
|
73
|
+
y : np.ndarray
|
|
74
|
+
Array of observed data corresponding to `x`.
|
|
75
|
+
verbose : bool, optional
|
|
76
|
+
If True, print detailed information about the likelihood calculation. Default is True.
|
|
77
|
+
normalize : bool, optional
|
|
78
|
+
If True, normalize the parameters to the specified bounds. Default is False.
|
|
79
|
+
bounds : list of tuple of float, optional
|
|
80
|
+
List of bounds for the parameters. Default is [(1, 2), (1, 2)].
|
|
81
|
+
|
|
82
|
+
Returns
|
|
83
|
+
-------
|
|
84
|
+
float
|
|
85
|
+
Negative log likelihood of the DVS model.
|
|
86
|
+
|
|
87
|
+
Notes
|
|
88
|
+
-----
|
|
89
|
+
The function calculates the posterior of the DVS model with test data by generating a posterior
|
|
90
|
+
distribution and binning the data. It then determines the log likelihood based on the kernel
|
|
91
|
+
density estimate of the binned data.
|
|
92
|
+
|
|
93
|
+
The function prints the likelihood and parameter values if `verbose` is True.
|
|
94
|
+
"""
|
|
64
95
|
start = time.time()
|
|
65
96
|
|
|
66
97
|
# extract parameters
|
|
@@ -114,7 +145,7 @@ def dvs_likelihood(params, x, y, verbose=True, normalize=False, bounds=[(1, 2),
|
|
|
114
145
|
try:
|
|
115
146
|
kde_bins = kde.fit(y_post[mask][:, np.newaxis])
|
|
116
147
|
except ValueError:
|
|
117
|
-
warnings.warn("kde.fit(y_post[mask][:, np.newaxis]) yield
|
|
148
|
+
warnings.warn("kde.fit(y_post[mask][:, np.newaxis]) yield nan ... skipping bin")
|
|
118
149
|
continue
|
|
119
150
|
|
|
120
151
|
# get probability densities at data
|
|
@@ -151,14 +182,14 @@ def e_focal_workhorse(elm_idx_list, e):
|
|
|
151
182
|
Parameters
|
|
152
183
|
----------
|
|
153
184
|
elm_idx_list : np.ndarray
|
|
154
|
-
(chunksize) List of element indices, the congruence factor is computed for
|
|
185
|
+
(chunksize) List of element indices, the congruence factor is computed for.
|
|
155
186
|
e: list of list of np.ndarray of float
|
|
156
187
|
[n_cond][n_datasets][n_elm] Tuple of ``n_datasets`` of the electric field to compute the congruence factor for,
|
|
157
188
|
e.g. ``(e_mag, e_norm, e_tan)``.
|
|
158
|
-
Each dataset is a list over all conditions containing the electric field component of interest
|
|
189
|
+
Each dataset is a list over all conditions containing the electric field component of interest.
|
|
159
190
|
|
|
160
191
|
* ``len(e) = n_cond``
|
|
161
|
-
* ``len(e[0]) = n_comp`` (e.g: ``e_mag = e[0]
|
|
192
|
+
* ``len(e[0]) = n_comp`` (e.g: ``e_mag = e[0]``)
|
|
162
193
|
|
|
163
194
|
Returns
|
|
164
195
|
-------
|
|
@@ -171,7 +202,6 @@ def e_focal_workhorse(elm_idx_list, e):
|
|
|
171
202
|
A high-resolution computational localization method for transcranial magnetic stimulation mapping.
|
|
172
203
|
NeuroImage, 172, 85-93.
|
|
173
204
|
"""
|
|
174
|
-
|
|
175
205
|
n_datasets = len(e[0])
|
|
176
206
|
n_elm = len(elm_idx_list)
|
|
177
207
|
n_conditions = len(e)
|
|
@@ -202,8 +232,8 @@ def e_cog_workhorse(elm_idx_list, mep, mep_params, e):
|
|
|
202
232
|
(n_mep_params_total) List of all mep parameters of curve fits used to calculate the MEP, accumulated into
|
|
203
233
|
one array.
|
|
204
234
|
|
|
205
|
-
* e.g. [``mep_#1_para_#1``, ``mep_#1_para_#2``, ``mep_#1_para_#3``, ``mep_#2_para_#1``,
|
|
206
|
-
|
|
235
|
+
* e.g. [``mep_#1_para_#1``, ``mep_#1_para_#2``, ``mep_#1_para_#3``, ``mep_#2_para_#1``, ``mep_#2_para_#1``, ...]
|
|
236
|
+
|
|
207
237
|
|
|
208
238
|
e : list of list of np.ndarray of float
|
|
209
239
|
[n_cond][n_datasets][n_elm] Tuple of n_datasets of the electric field to compute the congruence factor for,
|
|
@@ -211,7 +241,7 @@ def e_cog_workhorse(elm_idx_list, mep, mep_params, e):
|
|
|
211
241
|
Each dataset is a list over all conditions containing the electric field component of interest
|
|
212
242
|
|
|
213
243
|
* e.g.: ``len(e) = n_cond``
|
|
214
|
-
* ``len(e[0]) = n_comp`` (e.g: ``e_mag = e[0]
|
|
244
|
+
* ``len(e[0]) = n_comp`` (e.g: ``e_mag = e[0]``)
|
|
215
245
|
|
|
216
246
|
Returns
|
|
217
247
|
-------
|
|
@@ -224,7 +254,6 @@ def e_cog_workhorse(elm_idx_list, mep, mep_params, e):
|
|
|
224
254
|
Physiological observations validate finite element models for estimating subject-specific electric field
|
|
225
255
|
distributions induced by transcranial magnetic stimulation of the human motor cortex. Neuroimage, 81, 253-264.
|
|
226
256
|
"""
|
|
227
|
-
|
|
228
257
|
n_datasets = len(e[0])
|
|
229
258
|
n_elm = len(elm_idx_list)
|
|
230
259
|
n_conditions = len(mep)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import numpy as np
|
|
2
|
-
|
|
3
2
|
import pynibs
|
|
4
3
|
|
|
5
4
|
|
|
@@ -248,7 +247,7 @@ def sigmoid_thresh(elm_idx, mep_curve, intensities, e, mep_threshold):
|
|
|
248
247
|
e_all = np.hstack(e_all)
|
|
249
248
|
|
|
250
249
|
# fit data to function
|
|
251
|
-
mep = pynibs.Mep(intensities=e_all, mep=mep_curve_all, intensity_min_threshold=0, mep_min_threshold=0)
|
|
250
|
+
mep = pynibs.expio.Mep(intensities=e_all, mep=mep_curve_all, intensity_min_threshold=0, mep_min_threshold=0)
|
|
252
251
|
mep.fit = mep.run_fit_multistart(pynibs.expio.fit_funs.sigmoid,
|
|
253
252
|
x=e_all,
|
|
254
253
|
y=mep_curve_all,
|