<Class Brain>
Brain
is a high-level class that provides almost all the core features of threebrainpy
.
To import the Brain
class, use the following command:
from threebrainpy.core import Brain
Bases: object
Class definition for storing brain data and rendering information.
Examples:
This example loads fsaverage
brain from FreeSurfer (if you have installed) and renders it.
>>> import os
>>> from threebrainpy.core import Brain
>>> fs_home = os.environ.get("FREESURFER_HOME", None)
>>> if fs_home is not None:
>>> brain = Brain("fsaverage", os.path.join(fs_home, "subjects", "fsaverage"))
>>> print(brain)
>>> brain.build()
Source code in threebrainpy/core/brain.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 |
|
electrode_contacts
property
Get all electrode contacts from the brain.
path
property
The root path to the imaging files.
path_mri
property
The path to the MRI and atlas files.
path_surf
property
The path to the surface mesh files.
ras2mni_152
property
A 4x4
transform matrix from T1 scanner RAS (right-anterior-superior coordinate) to MNI152 template space using FreeSurfer affine transform (generated during recon-all
).
ras2mni_305
property
A 4x4
transform matrix from T1 scanner RAS (right-anterior-superior coordinate) to MNI305 template space using FreeSurfer affine transform (generated during recon-all
).
ras2ras_tkr
property
A 4x4
T1 scanner RAS (right-anterior-superior coordinate) to viewer (or FreeSurfer tk-registered) tkrRAS transform matrix.
ras_tkr2mni_152
property
A 4x4
transform matrix from tkrRAS to MNI152 template space using FreeSurfer affine transform (generated during recon-all
).
ras_tkr2mni_305
property
A 4x4
transform matrix from tkrRAS to MNI305 template space using FreeSurfer affine transform (generated during recon-all
).
storage
property
The path to a temporary directory for storing intermediate files and viewers.
subject_code
property
Subject code string.
vox2ras
property
A 4x4
voxel (indexing) to T1 scanner RAS (right-anterior-superior coordinate) transform matrix.
vox2ras_tkr
property
A 4x4
voxel (indexing) to viewer (or FreeSurfer) tkrRAS (tk-registered right-anterior-superior coordinate) transform matrix.
__init__(subject_code, path, work_dir=None)
Constructor for Brain.
Args:
subject_code: The subject code of the brain.
path: The path to the FreeSurfer or FreeSurfer-like folder (with MRI stored at mri
and surfaces at surf
).
work_dir: The path to the working directory. If not specified, a temporary directory will be created.
Source code in threebrainpy/core/brain.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
add_electrode_contact(number, label, position=None, is_surface=False, radius=None, mni_position=None, sphere_position=None, **kwargs)
Add an electrode contact to the brain. The electrode contact will be rendered in main canvas using sphere (JavaScript class).
Args:
number: The integer number of the electrode contact, starting from 1.
label: The label of the electrode contact.
position: The position of the electrode contact in the native space of the brain, or a Vec3
instance with given spaces.
is_surface: Whether the electrode contact is a surface electrode.
radius: The radius of the electrode contact, default is 2.0 for surface electrodes and 1.0 for depth electrodes.
mni_position: The position of the electrode contact in MNI space, overrides the default affine MNI calculation;
often used if you have advanced/more accurate MNI estimation
sphere_position: The position of the electrode contact in the sphere space; surface electrodes only.
kwargs: Other arguments to be passed to ElectrodeSphere
.
Returns:
The electrode contact instance.
Examples:
Adds an electrode contact to the brain
>>> e1 = brain.add_electrode_contact(number = 1, label = "LA1", position = [35,10,10], is_surface = False)
>>> e1.get_position("ras")
Vec3(35.0, 10.0, 10.0) [ras]
>>> e2 = brain.add_electrode_contact(number = 2, label = "LA2", position = Vec3([5,10,10], space = "voxel"), is_surface = False)
>>> # Automatically transform position to RAS space
>>> e2.get_position("ras")
Vec3(126.61447143554688, -117.5, 117.5) [ras]
Source code in threebrainpy/core/brain.py
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 |
|
add_electrodes(table, space='ras')
Add electrodes to the brain. Args: table: A pandas table containing the electrode information, or the path to the table. (See 'Details:') space: The space of the electrode coordinates, default is "ras". Returns: The number of electrodes added.
Details
The table (or table file) must contains at least the following columns (case-sensitive):
-
Electrode
(int, mandatory): electrode contact number, starting from 1 -
Label
(str, mandatory): electrode label string, must not be empty string -
x
,y
,z
(float): the coordinates of the electrode contact in the space specified byspace
.If
space
is not specified, then the coordinates are assumed to be in the T1 space ("ras").If x=y=z=0, then the electrode will be hidden. (This is the default behavior of R package threeBrain)
If
x
,y
,z
is not specified, then the following columns will be used in order:Coord_x
,Coord_y
,Coord_z
: electrode coordinates in tkrRAS space (FreeSurfer space)T1R
,T1A
,T1S
: electrode coordinates in T1 RAS space (scanner space)MNI305_x
,MNI305_y
,MNI305_z
: electrode coordinates in MNI305 spaceMNI152_x
,MNI152_y
,MNI152_z
: electrode coordinates in MNI152 space
The order will be Coord_ > T1 > MNI305_ > MNI152_ to be consistent with R package threeBrain.
xyz in native (subject brain) space and MNI space can co-exist in the same table. In this case, the native space coordinates will be used to show the electrodes in the native brain, and the MNI space coordinates will be used to show the electrodes on the template brain.
The following columns are optional:
Radius
(float): the radius of the electrode contact, default is 1.0 for sEEG and 2.0 for ECoGHemisphere
(str, ["auto", "left", "right"]): the hemisphere of the electrode contact, default is "auto" If "auto", then the hemisphere will be determined by theFSLabel
column.Sphere_x
,Sphere_y
,Sphere_z
(float): the coordinates of the electrode contact in the sphere space (surface electrodes only)SurfaceElectrode
(bool): whether the electrode is a surface electrode, default is FalseFSLabel
(str): the FreeSurfer label of the electrode contact.
Source code in threebrainpy/core/brain.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
|
add_global_data(name, value, is_cache=False, absolute_path=None)
Internal method to add global data to the brain.
Args:
name: The name of the global data.
value: If is_cache=False
, the value of the global data, can be any JSON-serializable object.
If is_cache=True
, the path to, or the file name of the cached JSON file.
is_cache: Whether the value
is a cached JSON file.
absolute_path: The absolute path to the cached JSON file.
Source code in threebrainpy/core/brain.py
319 320 321 322 323 324 325 326 327 328 329 |
|
add_group(name, exists_ok=True)
Internal method to add a geometry groups to the brain. Args: name: The name of the group. exists_ok: Whether to overwrite the existing group if the group already exists. Returns: The group instance.
Source code in threebrainpy/core/brain.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
|
add_slice(slice_prefix='brain.finalsurfs', name='T1')
Add a (MRI) volume slice to the brain. The slices will be rendered in side canvas using datacube (JavaScript class).
Args:
slice_prefix: The prefix of the slice file in the mri
folder. (default: "brain.finalsurfs")
name: The name of the slice, currently only "T1" is supported. (default: "T1")
Examples:
Adds brain.finalsurfs.mgz
or brain.finalsurfs.nii[.gz]
to the brain slices
>>> brain.add_slice(slice_prefix = "brain.finalsurfs", name = "T1")
Source code in threebrainpy/core/brain.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|
add_surfaces(surface_type, hemesphere='both')
Add a surface to the brain. The surface will be rendered in main canvas using surface (JavaScript class).
Args:
surface_type: The type of the surface, e.g. "pial", "white", "inflated", "sphere" (see surf/
folder, usually [lr]h.<surface_type>
).
hemesphere: The hemesphere of the surface, can be "l", "r", "b" (both). (default: "both")
Returns:
A dictionary of surface instances if exist, with keys being the hemesphere.
Examples:
Adds lh.pial
and rh.pial
to the brain surfaces
>>> brain.add_surfaces(surface_type = "pial", hemesphere = "both")
Source code in threebrainpy/core/brain.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
|
add_volume(volume_prefix, is_continuous, name=None)
Add a (Atlas/CT/3D voxel) volume cube to the brain. The VolumeCube will be rendered in main canvas using datacube2 (JavaScript class).
Args:
volume_prefix: The prefix of the volume file in the mri
folder. (e.g. "aparc+aseg", "CT_raw")
is_continuous: Whether the volume is continuous or discrete.
The color map for continuous and discrete values are set separately.
For continuous values, the volume will be rendered using RedFormat (single-channel shader).
The color will be assgined according to the volume value (density).
For discrete values, the volume will be rendered using RGBAFormat (four-channel shader).
The volume data will be used as the color index, and the color map will be set separately.
The color index must be integer, and the color map must be a list of RGBA colors.
name: The name of the volume, default is to automatically derived from the volume_prefix.
Please set name to "CT" is the volume file is CT for localization
Examples:
Adds aparc+aseg.mgz
or aparc+aseg.nii[.gz]
to the brain volumes
>>> brain.add_volume(volume_prefix = "aparc+aseg", is_continuous = False)
Source code in threebrainpy/core/brain.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
|
build(path=None, dry_run=False)
Build the brain cache. If path
is not specified, the cache will be built under the temporary directory.
Args:
path: The path to build the cache; default is using the self._storage
path.
dry_run: If True, the cache will not be built, instead, the build process will be printed to the console.
Source code in threebrainpy/core/brain.py
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 |
|
clean_electrodes()
Remove all electrode contacts from the brain.
Source code in threebrainpy/core/brain.py
711 712 713 714 715 716 717 718 |
|
ensure_group(name, **kwargs)
Ensure that a geometry group exists, if not, create one.
Args:
name: The name of the group.
kwargs: Other arguments to be passed to add_group
.
Returns:
The group instance.
Source code in threebrainpy/core/brain.py
373 374 375 376 377 378 379 380 381 382 383 384 |
|
get_electrode_colormap(name)
Get the colormap of an electrode contact.
Args:
name: The name of the electrode keyframe (which is also the color-map name).
Returns:
The colormap instance or None
if the colormap does not exist.
Source code in threebrainpy/core/brain.py
925 926 927 928 929 930 931 932 933 |
|
get_electrode_contact(number)
Get an electrode contact from the brain.
Args:
number: The integer number of the electrode contact, starting from 1.
Returns:
The electrode contact instance or None
if the electrode contact does not exist.
Source code in threebrainpy/core/brain.py
696 697 698 699 700 701 702 703 704 |
|
get_geometry(name)
Get a geometry instance from the brain.
Args:
name: The name of the geometry template.
Returns:
The geometry instance or None
if the geometry instance does not exist.
Source code in threebrainpy/core/brain.py
421 422 423 424 425 426 427 428 429 |
|
get_global_data(name, force_reload=False, ifnotfound=None)
Get group data from the brain instance.
Args:
name: The name of the group data.
force_reload: Whether to force reload the group data.
ifnotfound: If the group data is not found, return this value.
Returns:
The value of the group data, or ifnotfound
.
Source code in threebrainpy/core/brain.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
get_group(name)
Get a geometry group from the brain.
Args:
name: The name of the group.
Returns:
The group instance or None
if the group does not exist.
Source code in threebrainpy/core/brain.py
355 356 357 358 359 360 361 362 363 |
|
get_slice(name)
Get MRI slices from the brain.
Args:
name: The name of the slice.
Returns:
The slice instance or None
if the slice does not exist.
Source code in threebrainpy/core/brain.py
469 470 471 472 473 474 475 476 477 |
|
get_slices()
Get all MRI slices from the brain.
Source code in threebrainpy/core/brain.py
478 479 480 481 482 |
|
get_surfaces(surface_type)
Get surfaces from the brain.
Args:
surface_type: The type of the surface, e.g. "pial", "white", "inflated", "sphere" (see surf/
folder, usually [lr]h.<surface_type>
).
Returns:
A dictionary of surface instances if exist, with keys being the hemesphere.
Source code in threebrainpy/core/brain.py
611 612 613 614 615 616 617 618 619 |
|
get_transform(space_from, space_to)
Get transform matrix from space_from
to space_to
.
Args:
space_from: The space from which the transform matrix is defined.
choices are voxel
, ras
, ras_tkr
, mni305
, mni152
.
space_to: The space to which the transform matrix is defined.
see space_from
for choices.
Examples:
>>> brain.get_transform(space_from = "voxel", space_to = "ras_tkr")
Mat44 (T1.voxel -> T1.ras_tkr):
array([[ -1., 0., 0., 128.],
[ 0., 0., 1., -128.],
[ 0., -1., 0., 128.],
[ 0., 0., 0., 1.]])
Source code in threebrainpy/core/brain.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
has_geometry(name)
Check if the brain has a geometry instance.
Args:
name: The name of the geometry template.
Returns:
True
if the geometry instance exists, False
otherwise.
Source code in threebrainpy/core/brain.py
430 431 432 433 434 435 436 437 438 |
|
has_group(name)
Check if the brain has a geometry group.
Args:
name: The name of the group.
Returns:
True
if the group exists, False
otherwise.
Source code in threebrainpy/core/brain.py
364 365 366 367 368 369 370 371 372 |
|
has_slice(name)
Check if the brain has MRI slices with given name.
Source code in threebrainpy/core/brain.py
483 484 485 486 487 |
|
has_surface_type(surface_type)
Check if the brain has surfaces with given type.
Args:
surface_type: The type of the surface, e.g. "pial", "white", "inflated", "sphere" (see surf/
folder, usually [lr]h.<surface_type>
).
Source code in threebrainpy/core/brain.py
620 621 622 623 624 625 626 |
|
render(launch_browser=True, host='localhost', port=None, **kwargs)
Render the brain cache. If path
is not specified, the cache will be rendered under the temporary directory.
Args:
path: The path to render the cache; default is using the self._storage
path.
kwargs: Other arguments to be passed to subprocess.call
.
Source code in threebrainpy/core/brain.py
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 |
|
set_electrode_keyframe(number, value, time=None, name='value')
Low-level method to set electrode contacts keyframe (values).
Args:
number: The integer number of the electrode contact, starting from 1.
value: The value of the keyframe, can be numerical or characters.
time: The time (second) of the keyframe, default is None
which means 0.
name: The name of the keyframe, default is "value".
Returns:
The keyframe created
Source code in threebrainpy/core/brain.py
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
|
set_electrode_value(number, name, value, time=None)
Set value to a electrode contact. Args: number: The electrode contact number. name: The data name of the value. value: The value to set, can be a list of values or a single value. time: The time of the value, can be a list of times (in seconds) or a single time. Returns: The keyframe object or None if the electrode contact is not found.
Source code in threebrainpy/core/brain.py
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 |
|
set_electrode_values(table)
Set single or multiple values to multiple electrode contacts. Args: table: A pandas or a path to a csv file. The see 'Details' for table contents Details: The table (or table file) contains the following columns (case-sensitive):
* `Electrode` (mandatory): The electrode contact number, starting from 1
* `Subject` (optional): The subject code of the value, default is the current subject code
* `Time` (optional): The numeric time of the value, in seconds
* All other columns: The the column names are the data names of the values, can
be combinations of letters `[a-zA-Z]`, numbers `[0-9]`, dots `.`, and underscores `_`
Examples: The minimal table contains only the electrode contact number and the value:
| Electrode | brain.response |
|-----------|----------------|
| 1 | 0.1 |
| 2 | 0.2 |
| 3 | 0.3 |
Here's an example of the table with two variables `brain.response` and `classifier`,
and two electrodes `1` and `2`. The time range is `0~1` seconds.
| Electrode | Time | brain.response | classifier |
|-----------|------|----------------|------------|
| 1 | 0 | 0.1 | A |
| 1 | 1 | 0.2 | A |
| 2 | 0 | 0.3 | A |
| 2 | 1 | 0.4 | B |
Source code in threebrainpy/core/brain.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 |
|
set_group_data(name, value, is_cache=False, absolute_path=None, auto_create=True)
Set group data to the brain so the JavaScript engine will have access to the data.
This method is a low-level function
Args:
name: The name of the group data.
value: If is_cache=False
, the value of the group data, can be any JSON-serializable object.
If is_cache=True
, the path to, or the file name of the cached JSON file.
is_cache: Whether the value
is a cached JSON file.
absolute_path: The absolute path to the cached JSON file.
auto_create: Whether to create a group if the group does not exist.
Source code in threebrainpy/core/brain.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
set_transform_space(transform, space_from, space_to)
Returns a copy of transform
, but with space transformed.
Args:
transform: The transform matrix of class Mat44
. If transform
is not specified, then the transform will be identity matrix.
space_from: The space from which the transform matrix will be defined.
choices are voxel
, ras
, ras_tkr
, mni305
, mni152
.
space_to: The space to which the transform matrix will be defined.
Returns:
The new transform matrix with given spaces and inherited modalities.
Examples:
If you have a matrix that switch the column and row indexes in the voxel space,
what's the matrix in the ras space?
>>> from threebrainpy.core import Mat44
>>> idx_transform = Mat44([0,1,0,0,1,0,0,0,0,0,1,0], space_from = "voxel", space_to = "voxel")
>>> idx_transform
Mat44 (T1.voxel -> T1.voxel):
array([[0., 1., 0., 0.],
[1., 0., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]])
>>> # Applies idx_transform first then vox-to-ras
>>> brain.set_transform_space(transform = idx_transform, space_from = "voxel", space_to = "ras")
Mat44 (T1.voxel -> T1.ras):
array([[ 0. , -1. , 0. , 131.61447144],
[ 0. , 0. , 1. , -127.5 ],
[ -1. , 0. , 0. , 127.5 ],
[ 0. , 0. , 0. , 1. ]])
>>> # To validate the transform
>>> brain.vox2ras * idx_transform
Mat44 (T1.voxel -> T1.ras):
array([[ 0. , -1. , 0. , 131.61447144],
[ 0. , 0. , 1. , -127.5 ],
[ -1. , 0. , 0. , 127.5 ],
[ 0. , 0. , 0. , 1. ]])
Source code in threebrainpy/core/brain.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
to_dict()
Convert the brain to a dict. Returns: A dict containing the brain data.
Source code in threebrainpy/core/brain.py
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 |
|