Skip to content

trx fails when saving empty trx files. #91

@skoudoro

Description

@skoudoro

TRX should not fail to save empty tractogram.

here is the error:

    def _create_trx_from_pointer(
        header: dict,
        dict_pointer_size: dict,
        root_zip: Optional[str] = None,
        root: Optional[str] = None,
    ) -> Type["TrxFile"]:
        """After reading the structure of a zip/folder, create a TrxFile
    
        Keyword arguments:
            header -- A TrxFile header dictionary which will be used for the
                new TrxFile
            dict_pointer_size -- A dictionary containing the filenames of all
                the files within the TrxFile disk file/folder
            root_zip -- The path of the ZipFile pointer
            root -- The dirname of the ZipFile pointer
    
        Returns:
            A TrxFile constructer from the pointer provided
        """
        # TODO support empty positions, using optional tag?
        trx = TrxFile()
        trx.header = header
        positions, offsets = None, None
        for elem_filename in dict_pointer_size.keys():
            if root_zip:
                filename = root_zip
            else:
                filename = elem_filename
    
            folder = os.path.dirname(elem_filename)
            base, dim, ext = _split_ext_with_dimensionality(elem_filename)
            if ext == ".bit":
                ext = ".bool"
            mem_adress, size = dict_pointer_size[elem_filename]
    
            if root is not None:
                # This is for Unix
                if os.name != 'nt' and folder.startswith(root.rstrip("/")):
                    folder = folder.replace(root, "").lstrip("/")
                # These three are for Windows
                elif os.path.isdir(folder) and os.path.basename(folder) in ['dpv', 'dps', 'groups']:
                    folder = os.path.basename(folder)
                elif os.path.basename(os.path.dirname(folder)) == 'dpg':
                    folder = os.path.join('dpg', os.path.basename(folder))
                else:
                    folder = ''
    
            # Parse/walk the directory tree
            if base == "positions" and folder == "":
                if size != trx.header["NB_VERTICES"] * 3 or dim != 3:
>                   raise ValueError("Wrong data size/dimensionality.")
E                   ValueError: Wrong data size/dimensionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions