def cortex_to_image(self, data,<EOL>hemi=None, method='<STR_LIT>', fill=<NUM_LIT:0>, dtype=None, affine=None, shape=None):
<EOL>hemi = to_hemi_str(hemi)<EOL>hemi = ('<STR_LIT>', None) if hemi == '<STR_LIT>' else (None, '<STR_LIT>') if hemi == '<STR_LIT>' else ('<STR_LIT>','<STR_LIT>')<EOL>nhems = len([x for x in hemi if x])<EOL>tr = None<EOL>if   is_tuple(data) and len(data) == <NUM_LIT:2>: pass<EOL>elif pimms.is_map(data): data = ((None,       data['<STR_LIT>']) if hemi[<NUM_LIT:0>] is None else<EOL>(data['<STR_LIT>'], None)       if hemi[<NUM_LIT:1>] is None else<EOL>(data['<STR_LIT>'], data['<STR_LIT>']))<EOL>elif pimms.is_str(data): data = (data, data)<EOL>elif pimms.is_array(data):<EOL><INDENT>data = np.asarray(data)<EOL>sh = data.shape<EOL>if   nhems == <NUM_LIT:1>: data = tuple([None if k is None else data for k in hemi])<EOL>elif <NUM_LIT:2> in sh:<EOL><INDENT>ax = next([k for (k,d) in enumerate(sh) if d == <NUM_LIT:2>])<EOL>data = np.transpose(data, list(chain([ax], range(<NUM_LIT:0>, ax), range(ax+<NUM_LIT:1>, len(sh)))))<EOL><DEDENT>else: raise ValueError('<STR_LIT>')<EOL><DEDENT>else: raise ValueError('<STR_LIT>')<EOL>data = list(data)<EOL>for (dat,h,ii) in zip(data, hemi, [<NUM_LIT:0>,<NUM_LIT:1>]):<EOL><INDENT>if h is None: continue<EOL>if dat is None: raise ValueError('<STR_LIT>' % h)<EOL>hem = self.hemis[h]<EOL>dat = hem.property(dat)<EOL>if not pimms.is_array(dat, None, (<NUM_LIT:1>,<NUM_LIT:2>)):<EOL><INDENT>raise ValueError('<STR_LIT>' % h)<EOL><DEDENT>if pimms.is_matrix(dat) and dat.shape[<NUM_LIT:0>] != hem.vertex_count: dat = dat.T<EOL>if dat.shape[<NUM_LIT:0>] != hem.vertex_count:<EOL><INDENT>raise ValueError('<STR_LIT>' % h)<EOL><DEDENT>data[ii] = dat<EOL><DEDENT>if data[<NUM_LIT:0>] is not None and data[<NUM_LIT:1>] is not None:<EOL><INDENT>if not pimms.is_matrix(data[<NUM_LIT:0>]):<EOL><INDENT>if pimms.is_matrix(data[<NUM_LIT:1>]):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>else: frames = <NUM_LIT:1><EOL><DEDENT>elif not pimms.is_matrix(data[<NUM_LIT:1>]):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>elif data[<NUM_LIT:0>].shape[<NUM_LIT:1>] != data[<NUM_LIT:1>].shape[<NUM_LIT:1>]:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>else: frames = data[<NUM_LIT:0>].shape[<NUM_LIT:1>]<EOL><DEDENT>elif data[<NUM_LIT:0>] is None:<EOL><INDENT>frames = data[<NUM_LIT:1>].shape[<NUM_LIT:1>] if pimms.is_matrix(data[<NUM_LIT:1>]) else <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>frames = data[<NUM_LIT:0>].shape[<NUM_LIT:1>] if pimms.is_matrix(data[<NUM_LIT:0>]) else <NUM_LIT:1><EOL><DEDENT>if dtype is None:<EOL><INDENT>floatq = any(d is not None and pimms.is_array(d, np.inexact) for d in data)<EOL>dtype = np.float32 if floatq else np.int32<EOL><DEDENT>shape = self.image_dimensions if shape is None else shape<EOL>dims = shape + (frames,) if frames > <NUM_LIT:1> and len(shape) < <NUM_LIT:4> else shape<EOL>arr = np.full(dims, fill, dtype=dtype)<EOL>if pimms.is_str(method):<EOL><INDENT>method = '<STR_LIT>' if method is None else method.lower()<EOL>if method in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>method = '<STR_LIT>' if np.issubdtype(dtype, np.inexact) else '<STR_LIT>'<EOL><DEDENT>if affine is None and np.array_equal(shape, self.image_dimensions):<EOL><INDENT>if nhems == <NUM_LIT:2>:<EOL><INDENT>interp  = getattr(self, '<STR_LIT>' % method)<EOL>indices = self.gray_indices<EOL><DEDENT>else:<EOL><INDENT>interp =  [getattr(self, '<STR_LIT>' % (h, method))<EOL>for h in hemi if h is not None][<NUM_LIT:0>]<EOL>indices = [getattr(self, '<STR_LIT>'%h) for h in hemi if h is not None][<NUM_LIT:0>]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>tmp = [cortex_to_image_interpolation(h, mask=mask, affine=affine,<EOL>method=method, shape=shape)<EOL>for h in hemi if h is not None]<EOL>indices = (tmp[<NUM_LIT:0>][<NUM_LIT:0>], tmp[<NUM_LIT:1>][<NUM_LIT:0>])<EOL>interp = (tmp[<NUM_LIT:0>][<NUM_LIT:1>], tmp[<NUM_LIT:1>][<NUM_LIT:1>])<EOL>interp  = interp[<NUM_LIT:0>]  if nhems == <NUM_LIT:1> else sps.hstack(interp)<EOL>indices = indices[<NUM_LIT:0>] if nhems == <NUM_LIT:1> else tuple(np.hstack(indices))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>indices = mask<EOL>interp = method<EOL><DEDENT>data = [x for x in data if x is not None][<NUM_LIT:0>] if nhems == <NUM_LIT:1> else np.concatenate(data)<EOL>misses = None if fill == <NUM_LIT:0> else np.where(np.abs(interp).sum(axis=<NUM_LIT:1>) == <NUM_LIT:0>)<EOL>arr[indices] = interp.dot(data)<EOL>if misses: arr[misses] = fill<EOL>return arr<EOL>
sub.cortex_to_image(data, hemi) projects the given cortical-surface data to the given
  subject's gray-matter voxels of the given hemisphere and returns the resulting numpy
  array.
sub.cortex_to_image((lh_data, rh_data)) projects into both hemispheres.

The following options may be given:
  * method (default: 'linear') specifies that a particular method should be used; valid
    options are 'linear', 'heaviest', and 'nearest'. The 'linear' method uses the
    lh_vertex_to_voxel_linear_interpolation and rh_vertex_to_voxel_linear_interpolation 
    matrices while 'nearest' uses the nearest-neighbor interpolation. The 'heaviest' method
    uses the highest-valued weight in the 'linear' interpolation matrix, which is
    equivalent to using nearest-neighbor interpolation after controlling for the depth of
    the voxel with respect to the vertices. The 'linear' method is generally preferred
    unless your data is discreet, in which the 'heaviest' method is generally best.
  * fill (default: 0) specifies the value to be assigned to all voxels not in the gray mask
    or voxels in the gray-mask that are missed by the interpolation method.
  * dtype (default: None) specifies the data type that should be exported. If None, this
    will be automatically set to np.float32 for floating-point data and np.int32 for integer
    data.
  * affine (default: None) specifies the affine transformation that should be used to align
    the cortical surfaces with the voxels. If None, then the subject's vertex-to-voxel
    matrix will be used.
  * shape (default: None) specifies the dimensions of the output array; if None, then the
    subject's image_dimensions is used.