Exemplo n.º 1
0
def _int_pars(handle, set, par, n):
    h = pygadgetron.cGT_parameter(handle, set, par)
    check_status(h)
    for i in range(n):
        value += (pyiutil.intDataItemFromHandle(h, i), )
    pyiutil.deleteDataHandle(h)
    return value
Exemplo n.º 2
0
def uint16_pars(handle, group, par, n):
    h = parameter(handle, group, par)
    check_status(h)
    value = ()
    for i in range(n):
        value += (pyiutil.uint16DataItemFromHandle(h, i),)
    pyiutil.deleteDataHandle(h)
    return value
Exemplo n.º 3
0
 def get_storage_scheme():
     '''Returns acquisition data storage scheme.
     '''
     handle = pygadgetron.cGT_getAcquisitionsStorageScheme()
     check_status(handle)
     scheme = pyiutil.charDataFromHandle(handle)
     pyiutil.deleteDataHandle(handle)
     return scheme
Exemplo n.º 4
0
 def data_type(self, im_num):
     '''
     Returns the data type for a specified image (see 8 data types above).
     im_num: image (slice) 
     '''
     assert self.handle is not None
     handle = pygadgetron.cGT_imageDataType(self.handle, im_num)
     check_status(handle)
     n = pyiutil.intDataFromHandle(handle)
     pyiutil.deleteDataHandle(handle)
     return n
Exemplo n.º 5
0
 def value_of_gadget_property(self, id, prop):
     '''
     Returns the string representation of the value of specified property.
     id  : gadget id
     prop: property name (string)
     '''
     hg = _parameterHandle(self.handle, 'gadget_chain', id)
     hv = _parameterHandle(hg, 'gadget', prop)
     value = pyiutil.charDataFromHandle(hv)
     pyiutil.deleteDataHandle(hg)
     pyiutil.deleteDataHandle(hv)
     return value
Exemplo n.º 6
0
 def calculate(self, data, method=None):
     '''
     Calculates coil sensitivity maps from coil images or sorted 
     acquisitions.
     data  : either AcquisitionData or CoilImages
     method: either SRSS (Square Root of the Sum of Squares, default) or 
             Inati
     '''
     if isinstance(data, AcquisitionData):
         if data.is_sorted() is False:
             print('WARNING: acquisitions may be in a wrong order')
     if self.handle is not None:
         pyiutil.deleteDataHandle(self.handle)
     self.handle = pygadgetron.cGT_CoilSensitivities('')
     check_status(self.handle)
     if method is not None:
         method_name, parm_list = name_and_parameters(method)
         parm = parse_arglist(parm_list)
     else:
         method_name = 'SRSS'
         parm = {}
     if isinstance(data, AcquisitionData):
         assert data.handle is not None
         _set_int_par\
             (self.handle, 'coil_sensitivity', 'smoothness', self.smoothness)
         try_calling(pygadgetron.cGT_computeCoilSensitivities\
             (self.handle, data.handle))
     elif isinstance(data, CoilImageData):
         assert data.handle is not None
         if method_name == 'Inati':
             #                if not HAVE_ISMRMRDTOOLS:
             try:
                 from ismrmrdtools import coils
             except:
                 raise error('Inati method requires ismrmrd-python-tools')
             nz = data.number()
             for z in range(nz):
                 ci = numpy.squeeze(data.as_array(z))
                 (csm, rho) = coils.calculate_csm_inati_iter(ci)
                 self.append(csm.astype(numpy.complex64))
         elif method_name == 'SRSS':
             if 'niter' in parm:
                 nit = int(parm['niter'])
                 _set_int_par\
                     (self.handle, 'coil_sensitivity', 'smoothness', nit)
             try_calling(pygadgetron.cGT_computeCSMsFromCIs\
                 (self.handle, data.handle))
         else:
             raise error('Unknown method %s' % method_name)
     else:
         raise error('Cannot calculate coil sensitivities from %s' % \
                     repr(type(data)))
Exemplo n.º 7
0
 def reconstruct(self, input_data):
     '''
     Returns the output from the chain for specified input.
     input_data: AcquisitionData
     '''
     assert_validity(input_data, AcquisitionData)
     handle = pygadgetron.cGT_reconstructImages\
          (self.handle, input_data.handle)
     check_status(handle)
     pyiutil.deleteDataHandle(handle)
     images = ImageData()
     images.handle = pygadgetron.cGT_reconstructedImages(self.handle)
     check_status(images.handle)
     return images
Exemplo n.º 8
0
 def set_gadget_property(self, id, prop, value):
     '''
     Assigns specified value to specified gadget property.
     id   : gadget id
     prop : property name (string)
     value: property value (string)
     '''
     if type(value) == type('abc'):
         v = value
     else:
         v = repr(value).lower()
     hg = _parameterHandle(self.handle, 'gadget_chain', id)
     try_calling(pygadgetron.cGT_setGadgetProperty(hg, prop, v))
     pyiutil.deleteDataHandle(hg)
Exemplo n.º 9
0
 def dimensions(self, select='image'):
     '''
     Returns acquisitions dimensions as a tuple (na, nc, ns), where na is
     the number of acquisitions, nc the number of coils and ns the number of
     samples.
     If select is set to 'all', the total number of acquisitions is returned.
     Otherwise, the number of acquisitions directly related to imaging data
     is returned.
     '''
     assert self.handle is not None
     dim = numpy.ones((MAX_ACQ_DIMENSIONS, ), dtype=numpy.int32)
     hv = pygadgetron.cGT_getAcquisitionsDimensions\
          (self.handle, dim.ctypes.data)
     #nr = pyiutil.intDataFromHandle(hv)
     pyiutil.deleteDataHandle(hv)
     if select == 'all':
         dim[2] = self.number()
     else:
         dim[2] = numpy.prod(dim[2:])
     return tuple(dim[2::-1])
Exemplo n.º 10
0
 def append(self, csm):
     '''
     Appends a coil sensitivity map to self.
     csm: Numpy ndarray with csm values
     '''
     if self.handle is None:
         self.handle = pygadgetron.cGT_CoilSensitivities('')
         check_status(self.handle)
     shape = csm.shape
     nc = shape[0]
     if csm.ndim == 4:
         nz = shape[1]
         iy = 2
     else:
         nz = 1
         iy = 1
     ny = shape[iy]
     nx = shape[iy + 1]
     re = csm.real.copy()
     im = csm.imag.copy()
     handle = pygadgetron.cGT_appendCSM\
         (self.handle, nx, ny, nz, nc, re.ctypes.data, im.ctypes.data)
     check_status(handle)
     pyiutil.deleteDataHandle(handle)
Exemplo n.º 11
0
def try_calling(returned_handle):
    check_status(returned_handle, inspect.stack()[1])
    pyiutil.deleteDataHandle(returned_handle)
Exemplo n.º 12
0
def _float_par(handle, set, par):
    h = pygadgetron.cGT_parameter(handle, set, par)
    check_status(h)
    v = pyiutil.floatDataFromHandle(h)
    pyiutil.deleteDataHandle(h)
    return v
Exemplo n.º 13
0
def int_par(handle, group, par):
    h = parameter(handle, group, par)
    check_status(h, inspect.stack()[1])
    value = pyiutil.intDataFromHandle(h)
    pyiutil.deleteDataHandle(h)
    return value
Exemplo n.º 14
0
def char_par(handle, group, par):
    h = parameter(handle, group, par)
    check_status(h)
    value = pyiutil.charDataFromHandle(h)
    pyiutil.deleteDataHandle(h)
    return value
Exemplo n.º 15
0
def set_float_par(handle, group, par, value):
    h = pyiutil.floatDataHandle(float(value))
    set_parameter(handle, group, par, h, inspect.stack()[1])
    pyiutil.deleteDataHandle(h)
Exemplo n.º 16
0
def set_bool_par(handle, group, par, value):
    h = pyiutil.boolDataHandle(bool(value))
    set_parameter(handle, group, par, h, inspect.stack()[1])
    pyiutil.deleteDataHandle(h)
Exemplo n.º 17
0
def set_char_par(handle, group, par, value):
    h = pyiutil.charDataHandle(value)
    set_parameter(handle, group, par, h, inspect.stack()[1])
    pyiutil.deleteDataHandle(h)
Exemplo n.º 18
0
def set_parameter(hs, group, par, hv, stack = None):
    if stack is None:
        stack = inspect.stack()[1]
    h = setParameter(hs, group, par, hv)
    check_status(h, stack)
    pyiutil.deleteDataHandle(h)
Exemplo n.º 19
0
def float_par(handle, group, par):
    h = parameter(handle, group, par)
    check_status(h)
    v = pyiutil.floatDataFromHandle(h)
    pyiutil.deleteDataHandle(h)
    return v
Exemplo n.º 20
0
 def read(self, file):
     if self.handle is not None:
         pyiutil.deleteDataHandle(self.handle)
     self.handle = pygadgetron.cGT_CoilSensitivities(file)
     check_status(self.handle)
Exemplo n.º 21
0
 def __del__(self):
     if self.handle is not None:
         pyiutil.deleteDataHandle(self.handle)
Exemplo n.º 22
0
def _int_par(handle, set, par):
    h = pygadgetron.cGT_parameter(handle, set, par)
    check_status(h)
    value = pyiutil.intDataFromHandle(h)
    pyiutil.deleteDataHandle(h)
    return value
Exemplo n.º 23
0
def _set_int_par(handle, set, par, value):
    h = pyiutil.intDataHandle(value)
    _setParameter(handle, set, par, h)
    pyiutil.deleteDataHandle(h)
Exemplo n.º 24
0
 def read_from_file(self, file):
     if self.handle is not None:
         pyiutil.deleteDataHandle(self.handle)
     self.handle = pygadgetron.cGT_readImages(file)
     check_status(self.handle)