<commit_before>####################################################################################################
# main/surface_to_image.py
# The code for the function that handles the registration of retinotopy
# By <NAME>

from __future__ import print_function

import numpy                        as     np
import scipy                        as     sp
import nibabel                      as     nib
import nibabel.freesurfer.io        as     fsio
import nibabel.freesurfer.mghformat as     fsmgh
import os, sys, pimms

from ..freesurfer                   import (subject, add_subject_path, find_subject_path)
from ..io                           import (save, load)
from ..mri                          import (is_image, is_image_spec, image_clear, to_image)

info = \
   '''
   Syntax: surface_to_image <subject> <out>
   <subject> must be a valid FreeSurfer subject id (in the $SUBJECTS_DIR directory
     or configured subject paths) or a full path to a FreeSurfer subject or it can
     be a valid HCP subject identifier.
   <out> is the output volume file to write.
   In addition to the subject and the output filename, at least one and at most two
   surface file(s) must be specified. These may be specified using the --lh (or -l)
   and --rh (or -r) options below or without them; if they files are specified
   without the given arguments and the ordering cannot be detected by the number of
   vertices in the file, then the left hemisphere surface is assumed to be
   specified first.
   The command projects the given surface files into the subject's ribbon and
   writes the result out to the given filename. If only one hemisphere's surface
   datafile is given, then only that hemisphere's data is projected to the ribbon.

   The following options may be given:
     * -v|--verbose
       Indicates that detailed output should be printed.
     * -l|--lh=<file>
       -r|--rh=<file>
       These options specify the surface data files that are to be projected to
       the subject's ribbon.
     * -i|--image=<file>
       The given file specifies the image-spec of the output image; all header-data
       are copied from this image and the file's affine and the image shape are used
       to determine the slice prescription of the output image. File may optionally
       be a JSON file containing a mapping with the keys 'affine' and 'image_shape'.
       If no image is given then the subject's 'brain' image is used.
     * -m|--method=<name>
       Specifies the method that should be used. Supported options are linear,
       nearest, and auto (the default). Both linear and nearest methods find the
       position of the voxel-center in the cortical sheet. The linear option linearly
       interpolates between the three vertices that form the triangle faces of the
       prism containing the voxel-center while the nearest option uses the nearest of
       these three vertices. If the auto option is used, then chooses nearest for int
       data and linear for floating-point data.
     * -f|--fill=<value>
       The fill value (default: 0) is inserted in everywhere in the volume that is
       not part of the ribbon.
     * -t|--dtype=<value>
       Specifies that the output data type should be <value>. Currently supported are
       'int' or 'float' (default: 'float').
     * -d|--subjects-dir=<path>
       Specifies that the given path(s) should be added to the subjects directory
       when performing the operation. Note that this may include directories
       separated by colons (:), as with the PATH environment variable.
     * --
       This token, by itself, indicates that the arguments that remain should not
       be processed as flags or options, even if they begin with a -.
   '''
_surface_to_ribbon_parser_instructions = [
    # Flags
    ('h', 'help',         'help',         False),
    ('v', 'verbose',      'verbose',      False),
    # Options             
    ['l', 'lh',           'lh_file',      None],
    ['r', 'rh',           'rh_file',      None],
    ['i', 'image',        'image',        None],
    ['f', 'fill',         'fill',         0],
    ['m', 'method',       'method',       'auto'],
    ['t', 'type',         'dtype',        None],
    ['d', 'subjects-dir', 'subjects_dir', None]]
_surface_to_ribbon_parser = pimms.argv_parser(_surface_to_ribbon_parser_instructions)

def read_surf_file(flnm):
  if flnm.endswith(".mgh") or flnm.endswith(".mgz"):
    data = fsmgh.load(flnm).dataobj.flatten()
  else:
    data = fsio.read_morph_data(flnm)
  return data

def main(args):
    '''
    surface_to_rubbon.main(args) can be given a list of arguments, such as sys.argv[1:]; these
    arguments may include any options and must include exactly one subject id and one output
    filename. Additionally one or two surface input filenames must be given. The surface files are
    projected into the ribbon and written to the output filename. For more information see the
    string stored in surface_to_image.info.
    '''
    # Parse the arguments
    (args, opts) = _surface_to_ribbon_parser(args)
    # First, help?
    if opts['help']:
        print(info, file=sys.stdout)
        return 1
    # and if we are verbose, lets setup a note function<commit_msg>AttributeError: 'ArrayProxy' correction<commit_after>####################################################################################################
# main/surface_to_image.py
# The code for the function that handles the registration of retinotopy
# By <NAME>

from __future__ import print_function

import numpy                        as     np
import scipy                        as     sp
import nibabel                      as     nib
import nibabel.freesurfer.io        as     fsio
import nibabel.freesurfer.mghformat as     fsmgh
import os, sys, pimms

from ..freesurfer                   import (subject, add_subject_path, find_subject_path)
from ..io                           import (save, load)
from ..mri                          import (is_image, is_image_spec, image_clear, to_image)

info = \
   '''
   Syntax: surface_to_image <subject> <out>
   <subject> must be a valid FreeSurfer subject id (in the $SUBJECTS_DIR directory
     or configured subject paths) or a full path to a FreeSurfer subject or it can
     be a valid HCP subject identifier.
   <out> is the output volume file to write.
   In addition to the subject and the output filename, at least one and at most two
   surface file(s) must be specified. These may be specified using the --lh (or -l)
   and --rh (or -r) options below or without them; if they files are specified
   without the given arguments and the ordering cannot be detected by the number of
   vertices in the file, then the left hemisphere surface is assumed to be
   specified first.
   The command projects the given surface files into the subject's ribbon and
   writes the result out to the given filename. If only one hemisphere's surface
   datafile is given, then only that hemisphere's data is projected to the ribbon.

   The following options may be given:
     * -v|--verbose
       Indicates that detailed output should be printed.
     * -l|--lh=<file>
       -r|--rh=<file>
       These options specify the surface data files that are to be projected to
       the subject's ribbon.
     * -i|--image=<file>
       The given file specifies the image-spec of the output image; all header-data
       are copied from this image and the file's affine and the image shape are used
       to determine the slice prescription of the output image. File may optionally
       be a JSON file containing a mapping with the keys 'affine' and 'image_shape'.
       If no image is given then the subject's 'brain' image is used.
     * -m|--method=<name>
       Specifies the method that should be used. Supported options are linear,
       nearest, and auto (the default). Both linear and nearest methods find the
       position of the voxel-center in the cortical sheet. The linear option linearly
       interpolates between the three vertices that form the triangle faces of the
       prism containing the voxel-center while the nearest option uses the nearest of
       these three vertices. If the auto option is used, then chooses nearest for int
       data and linear for floating-point data.
     * -f|--fill=<value>
       The fill value (default: 0) is inserted in everywhere in the volume that is
       not part of the ribbon.
     * -t|--dtype=<value>
       Specifies that the output data type should be <value>. Currently supported are
       'int' or 'float' (default: 'float').
     * -d|--subjects-dir=<path>
       Specifies that the given path(s) should be added to the subjects directory
       when performing the operation. Note that this may include directories
       separated by colons (:), as with the PATH environment variable.
     * --
       This token, by itself, indicates that the arguments that remain should not
       be processed as flags or options, even if they begin with a -.
   '''
_surface_to_ribbon_parser_instructions = [
    # Flags
    ('h', 'help',         'help',         False),
    ('v', 'verbose',      'verbose',      False),
    # Options             
    ['l', 'lh',           'lh_file',      None],
    ['r', 'rh',           'rh_file',      None],
    ['i', 'image',        'image',        None],
    ['f', 'fill',         'fill',         0],
    ['m', 'method',       'method',       'auto'],
    ['t', 'type',         'dtype',        None],
    ['d', 'subjects-dir', 'subjects_dir', None]]
_surface_to_ribbon_parser = pimms.argv_parser(_surface_to_ribbon_parser_instructions)

def read_surf_file(flnm):
  if flnm.endswith(".mgh") or flnm.endswith(".mgz"):
    data = np.array(fsmgh.load(flnm).dataobj).flatten()
  else:
    data = fsio.read_morph_data(flnm)
  return data

def main(args):
    '''
    surface_to_rubbon.main(args) can be given a list of arguments, such as sys.argv[1:]; these
    arguments may include any options and must include exactly one subject id and one output
    filename. Additionally one or two surface input filenames must be given. The surface files are
    projected into the ribbon and written to the output filename. For more information see the
    string stored in surface_to_image.info.
    '''
    # Parse the arguments
    (args, opts) = _surface_to_ribbon_parser(args)
    # First, help?
    if opts['help']:
        print(info, file=sys.stdout)
        return 1
    # and if we are verbose, lets setup a note function
{'fraction_non_alphanumeric': 0.09507510933637574, 'fraction_numerical': 0.0007606008746910059, 'mean_word_length': 2.647364771151179, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '236807', 'n_tokens_mistral': 2874, 'n_tokens_neox': 2787, 'n_words': 1263}