Exemple #1
0
    def __init__(
            self, filename, feature_filename=None, masker=None, r=6,
            transform=True, target='MNI', **kwargs):

        # Instance properties
        self.r = r

        # Set up transformations between different image spaces
        if transform:
            if not isinstance(transform, dict):
                transform = {'T88': transformations.t88_to_mni(),
                             'TAL': transformations.t88_to_mni()
                             }
            self.transformer = transformations.Transformer(transform, target)
        else:
            self.transformer = None

        # Load mappables
        self.mappables = self._load_mappables_from_txt(filename)

        # Load the volume into a new Masker
        if masker is None:
            resource_dir = os.path.join(os.path.dirname(__file__),
                                        os.path.pardir,
                                        'resources')
            masker = os.path.join(
                resource_dir, 'MNI152_T1_2mm_brain.nii.gz')
        self.masker = mask.Masker(masker)

        # Create supporting tables for images and features
        self.create_image_table()
        if feature_filename is not None:
            self.add_features(feature_filename, **kwargs)
Exemple #2
0
    def __init__(
            self, filename, feature_filename=None, masker=None, r=6,
            transform=True, target='MNI', **kwargs):

        # Instance properties
        self.r = r

        # Set up transformations between different image spaces
        if transform:
            if not isinstance(transform, dict):
                transform = {'T88': transformations.t88_to_mni(),
                             'TAL': transformations.t88_to_mni()
                             }
            self.transformer = transformations.Transformer(transform, target)
        else:
            self.transformer = None

        # Load and process activation data
        self.activations = self._load_activations(filename)

        # Load the volume into a new Masker
        if masker is None:
            resource_dir = os.path.join(os.path.dirname(__file__),
                                        os.path.pardir,
                                        'resources')
            masker = os.path.join(
                resource_dir, 'MNI152_T1_2mm_brain.nii.gz')
        self.masker = mask.Masker(masker)

        # Create supporting tables for images and features
        self.create_image_table()
        if feature_filename is not None:
            self.add_features(feature_filename, **kwargs)
Exemple #3
0
    def __init__(
        self, filename, feature_filename=None, masker=None, r=6, transform=True,
                  target='MNI'):
        """ Initialize a new Dataset instance.

        Creates a new Dataset instance from a text file containing activation data.
        At minimum, the input file must contain tab-delimited columns named x, y, z,
        id, and space (case-insensitive). The x/y/z columns indicate the coordinates
        of the activation center or peak, the id column is used to group multiple
        activations from a single Mappable (e.g. an article). Typically the id should
        be a uniquely identifying field accessible to others, e.g., a doi in the case
        of entire articles. The space column indicates the nominal atlas used to
        produce each activation. Currently all values except 'TAL' (Talairach) will
        be ignored. If space == TAL and the transform argument is True, all activations
        reported in Talairach space will be converted to MNI space using the
        Lancaster et al transform.

        Args:
          filename: The name of a database file containing a list of activations.
          feature_filename: An optional filename to construct a FeatureTable from.
          masker: An optional Nifti/Analyze image name defining the space to use for
            all operations. If no image is passed, defaults to the MNI152 2 mm
            template packaged with FSL.
          r: An optional integer specifying the radius of the smoothing kernel, in mm.
            Defaults to 6 mm.
          transform: Optional argument specifying how to handle transformation between
            coordinates reported in different stereotactic spaces. When True (default),
            activations in Talairach (T88) space will be converted to MNI space using
            the Lancaster et al (2007) transform; no other transformations will be
            applied. When False, no transformation will be applied. Alternatively,
            the user can pass their own dictionary of named transformations to apply,
            in which case each activation will be checked against the dictionary
            as it is read in and the specified transformation will be applied if
            found (for further explanation, see transformations.Transformer).
          target: The name of the target space within which activation coordinates
            are represented. By default, MNI.

        Returns:
          A Dataset instance.

        """

        # Instance properties
        self.r = r

        # Set up transformations between different image spaces
        if transform:
            if not isinstance(transform, dict):
                transform = {'T88': transformations.t88_to_mni(),
                              'TAL': transformations.t88_to_mni()
                             }
            self.transformer = transformations.Transformer(transform, target)
        else:
            self.transformer = None

        # Load mappables
        self.mappables = self._load_mappables_from_txt(filename)

        # Load the volume into a new Masker
        try:
            if masker is None:
                resource_dir = os.path.join(os.path.dirname(__file__),
                                            os.path.pardir,
                                            'resources')
                masker = os.path.join(
                    resource_dir, 'MNI152_T1_2mm_brain.nii.gz')
            self.masker = mask.Masker(masker)
        except Exception as e:
            logger.error("Error loading masker %s: %s" % (masker, e))
            # yoh: TODO -- IMHO should re-raise or not even swallow the exception here
            # raise e

        # Create supporting tables for images and features
        self.create_image_table()
        if feature_filename is not None:
            self.feature_table = FeatureTable(self, feature_filename)
Exemple #4
0
    def __init__(
        self, filename, feature_filename=None, masker=None, r=6, transform=True,
                  target='MNI'):
        """ Initialize a new Dataset instance.

        Creates a new Dataset instance from a text file containing activation data.
        At minimum, the input file must contain tab-delimited columns named x, y, z,
        id, and space (case-insensitive). The x/y/z columns indicate the coordinates
        of the activation center or peak, the id column is used to group multiple
        activations from a single Mappable (e.g. an article). Typically the id should
        be a uniquely identifying field accessible to others, e.g., a doi in the case
        of entire articles. The space column indicates the nominal atlas used to
        produce each activation. Currently all values except 'TAL' (Talairach) will
        be ignored. If space == TAL and the transform argument is True, all activations
        reported in Talairach space will be converted to MNI space using the
        Lancaster et al transform.

        Args:
          filename: The name of a database file containing a list of activations.
          feature_filename: An optional filename to construct a FeatureTable from.
          masker: An optional Nifti/Analyze image name defining the space to use for
            all operations. If no image is passed, defaults to the MNI152 2 mm
            template packaged with FSL.
          r: An optional integer specifying the radius of the smoothing kernel, in mm.
            Defaults to 6 mm.
          transform: Optional argument specifying how to handle transformation between
            coordinates reported in different stereotactic spaces. When True (default),
            activations in Talairach (T88) space will be converted to MNI space using
            the Lancaster et al (2007) transform; no other transformations will be
            applied. When False, no transformation will be applied. Alternatively,
            the user can pass their own dictionary of named transformations to apply,
            in which case each activation will be checked against the dictionary
            as it is read in and the specified transformation will be applied if
            found (for further explanation, see transformations.Transformer).
          target: The name of the target space within which activation coordinates
            are represented. By default, MNI.

        Returns:
          A Dataset instance.

        """

        # Instance properties
        self.r = r

        # Set up transformations between different image spaces
        if transform:
            if not isinstance(transform, dict):
                transform = {'T88': transformations.t88_to_mni(),
                              'TAL': transformations.t88_to_mni()
                             }
            self.transformer = transformations.Transformer(transform, target)
        else:
            self.transformer = None

        # Load mappables
        self.mappables = self._load_mappables_from_txt(filename)

        # Load the volume into a new Masker
        if masker is None:
            resource_dir = os.path.join(os.path.dirname(__file__),
                                        os.path.pardir,
                                        'resources')
            masker = os.path.join(
                resource_dir, 'MNI152_T1_2mm_brain.nii.gz')
        self.masker = mask.Masker(masker)

        # Create supporting tables for images and features
        self.create_image_table()
        if feature_filename is not None:
            self.feature_table = FeatureTable(self, feature_filename)