562
562
info = info | (((slice+1) & 3) << 4)
563
563
self._header_data['dim_info'] = info
565
def get_intent_code(self, code_repr='label'):
566
''' Return representation of intent code
571
string giving output form of intent code representation.
572
Default is 'label'; use 'code' for integer representation.
576
intent_code : string or integer
577
string label for intent code or code
581
>>> hdr = Nifti1Header()
582
>>> hdr.set_intent('t test', (10,), name='some score')
583
>>> hdr.get_intent_code()
586
return self._get_code_field(
565
591
def get_intent(self, code_repr='label'):
566
592
''' Get intent code, parameters and name
744
767
>>> hdr.set_dim_info(slice=2)
745
768
>>> hdr.set_data_shape((1, 1, 7))
746
769
>>> hdr.set_slice_duration(0.1)
747
>>> hdr['slice_code'] = slice_order_codes.code['sequential increasing']
749
771
We need a function to print out the Nones and floating point
750
values in a predictable way, for the tests below
772
values in a predictable way, for the tests below.
752
774
>>> _stringer = lambda val: val is not None and '%2.1f' % val or None
753
>>> printable_seq = lambda s: map(_stringer, s)
755
The following examples are from the nifti1.h documentation
757
>>> printable_seq(hdr.get_slice_times())
775
>>> _print_me = lambda s: map(_stringer, s)
777
The following examples are from the nifti1.h documentation.
779
>>> hdr['slice_code'] = slice_order_codes['sequential increasing']
780
>>> _print_me(hdr.get_slice_times())
758
781
['0.0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6']
759
782
>>> hdr['slice_start'] = 1
760
783
>>> hdr['slice_end'] = 5
761
>>> printable_seq(hdr.get_slice_times())
784
>>> _print_me(hdr.get_slice_times())
762
785
[None, '0.0', '0.1', '0.2', '0.3', '0.4', None]
763
>>> hdr['slice_code'] = slice_order_codes.code['sequential decreasing']
764
>>> printable_seq(hdr.get_slice_times())
786
>>> hdr['slice_code'] = slice_order_codes['sequential decreasing']
787
>>> _print_me(hdr.get_slice_times())
765
788
[None, '0.4', '0.3', '0.2', '0.1', '0.0', None]
766
>>> hdr['slice_code'] = slice_order_codes.code['alternating increasing']
767
>>> printable_seq(hdr.get_slice_times())
789
>>> hdr['slice_code'] = slice_order_codes['alternating increasing']
790
>>> _print_me(hdr.get_slice_times())
768
791
[None, '0.0', '0.3', '0.1', '0.4', '0.2', None]
769
>>> hdr['slice_code'] = slice_order_codes.code['alternating decreasing']
770
>>> printable_seq(hdr.get_slice_times())
792
>>> hdr['slice_code'] = slice_order_codes['alternating decreasing']
793
>>> _print_me(hdr.get_slice_times())
771
794
[None, '0.2', '0.4', '0.1', '0.3', '0.0', None]
772
>>> hdr['slice_code'] = slice_order_codes.code['alternating increasing 2']
773
>>> printable_seq(hdr.get_slice_times())
795
>>> hdr['slice_code'] = slice_order_codes['alternating increasing 2']
796
>>> _print_me(hdr.get_slice_times())
774
797
[None, '0.2', '0.0', '0.3', '0.1', '0.4', None]
775
>>> hdr['slice_code'] = slice_order_codes.code['alternating decreasing 2']
776
>>> printable_seq(hdr.get_slice_times())
798
>>> hdr['slice_code'] = slice_order_codes['alternating decreasing 2']
799
>>> _print_me(hdr.get_slice_times())
777
800
[None, '0.4', '0.1', '0.3', '0.0', '0.2', None]
779
802
hdr = self._header_data
1076
1103
>>> str(meta['magic'])
1078
>>> img.files = {'header':'tmp.nii','image':'tmp.nii'}
1079
>>> img.update_metadata()
1106
Now we change the files, to reveal the checks.
1108
>>> from StringIO import StringIO
1109
>>> str_io = StringIO()
1110
>>> files = {'header':str_io,'image':str_io}
1111
>>> img.to_files(files) # implies img.update_metadata()
1080
1112
>>> str(meta['magic'])
1082
1114
>>> int(meta['vox_offset'])
1084
>>> img.files = {'header':'tmp.hdr','image':'tmp.img'}
1085
>>> img.update_metadata()
1116
>>> str_io2 = StringIO()
1117
>>> files = {'header':str_io,'image':str_io2}
1118
>>> img.to_files(files) # implies img.update_metadata()
1086
1119
>>> str(meta['magic'])
1088
1121
>>> int(meta['vox_offset'])