digraph inheritance5791bfee87 { rankdir=LR; ratio=compress; fontsize=14; size="6.0, 8.0"; "SpmAnalyzeHeader" [shape=ellipse,URL="nibabel.spm99analyze.SpmAnalyzeHeader.html#nibabel.spm99analyze.SpmAnalyzeHeader",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "AnalyzeHeader" -> "SpmAnalyzeHeader" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Spm99AnalyzeHeader" [shape=ellipse,URL="nibabel.spm99analyze.Spm99AnalyzeHeader.html#nibabel.spm99analyze.Spm99AnalyzeHeader",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "SpmAnalyzeHeader" -> "Spm99AnalyzeHeader" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AnalyzeHeader" [shape=ellipse,URL="nibabel.analyze.AnalyzeHeader.html#nibabel.analyze.AnalyzeHeader",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "Spm2AnalyzeHeader" [shape=ellipse,URL="#nibabel.spm2analyze.Spm2AnalyzeHeader",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; "Spm99AnalyzeHeader" -> "Spm2AnalyzeHeader" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
SPM2 header; adds possibility of reading, but not writing DC offset for data
Initialize header from binary data block
Parameters : | binaryblock : {None, string} optional
endianness : {None, ‘<’,’>’, other endian code} string, optional
check : bool, optional
|
---|
Examples
>>> hdr1 = AnalyzeHeader() # an empty header
>>> hdr1.endianness == native_code
True
>>> hdr1.get_data_shape()
(0,)
>>> hdr1.set_data_shape((1,2,3)) # now with some content
>>> hdr1.get_data_shape()
(1, 2, 3)
We can set the binary block directly via this initialization. Here we get it from the header we have just made
>>> binblock2 = hdr1.binaryblock
>>> hdr2 = AnalyzeHeader(binblock2)
>>> hdr2.get_data_shape()
(1, 2, 3)
Empty headers are native endian by default
>>> hdr2.endianness == native_code
True
You can pass valid opposite endian headers with the endianness parameter. Even empty headers can have endianness
>>> hdr3 = AnalyzeHeader(endianness=swapped_code)
>>> hdr3.endianness == swapped_code
True
If you do not pass an endianness, and you pass some data, we will try to guess from the passed data.
>>> binblock3 = hdr3.binaryblock
>>> hdr4 = AnalyzeHeader(binblock3)
>>> hdr4.endianness == swapped_code
True
Get data scaling (slope) and offset (intercept) from header data
Uses the algorithm from SPM2 spm_vol_ana.m by John Ashburner
Parameters : | self : header
|
---|---|
Returns : | scl_slope : None or float
scl_inter : None or float
|
Examples
>>> fields = {'scl_slope':1,'scl_inter':0,'glmax':0,'glmin':0,'cal_max':0, 'cal_min':0}
>>> hdr = Spm2AnalyzeHeader()
>>> for key, value in fields.items():
... hdr[key] = value
>>> hdr.get_slope_inter()
(1.0, 0.0)
>>> hdr['scl_inter'] = 0.5
>>> hdr.get_slope_inter()
(1.0, 0.5)
>>> hdr['scl_inter'] = np.nan
>>> hdr.get_slope_inter()
(1.0, 0.0)
If ‘scl_slope’ is 0, nan or inf, cannot use ‘scl_slope’. Without valid information in the gl / cal fields, we cannot get scaling, and return None
>>> hdr['scl_slope'] = 0
>>> hdr.get_slope_inter()
(None, None)
>>> hdr['scl_slope'] = np.nan
>>> hdr.get_slope_inter()
(None, None)
Valid information in the gl AND cal fields are needed
>>> hdr['cal_max'] = 0.8
>>> hdr['cal_min'] = 0.2
>>> hdr.get_slope_inter()
(None, None)
>>> hdr['glmax'] = 110
>>> hdr['glmin'] = 10
>>> np.allclose(hdr.get_slope_inter(), [0.6/100, 0.2-0.6/100*10])
True