Skip to content

Compress cat12 outputs - #67

Open
AymericGaudin wants to merge 2 commits into
brainprepdesk:devfrom
AymericGaudin:compress_cat12
Open

AymericGaudin wants to merge 2 commits into
brainprepdesk:devfrom
AymericGaudin:compress_cat12

Conversation

@AymericGaudin

Copy link
Copy Markdown
Contributor

In this PR, I add features that compress cat12 outputs from .nii to .nii.gz, and that delete the input .nii, which is a (uncompressed) copy of a rawdata. This occurs directly after the computation is over and before the checks.

@AymericGaudin

Copy link
Copy Markdown
Contributor Author

J'ai pas fait le ruff check sur le bon dossier... Je corrige tout ça

@AGrigis

AGrigis commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

In interfaces.utils we can define a more generic compression function:

@step(
    hooks=[
        CoerceparamsHook(),
        LogRuntimeHook(
            bunched=False
        ),
        CommandLineWrapperHook(),
        SignatureHook(),
    ]
)
def compressfiles(
        root_dir: Directory, 
        extensions: list[str] = (".nii", ), 
    ) -> list[str]:
    """
    Recursively scan a directory to compress specified neuroimaging files into
    .gz.

    Parameters
    ----------
    root_dir : Directory
        Path to the root directory to scan.
    extensions : list[str]
        A list of file extensions to target for compression.
        Default `(".nii", )`.
    """
    if not root_dir.is_dir():
        raise ValueError(
            f"The specified path is not a valid directory: {root_dir}"
        )

    clean_extensions = [
        ext.lstrip(".")
        for ext in extensions
    ]

    command = [
        "find",
        str(root_dir),
        "-type f",
        "\\(",
    ]
    for cnt, ext in enumerate(clean_extensions):
        if cnt > 0:
            command.append("-o")
        command.extend([
            "-name",
            f"*.{ext}",
        ])  
    command.extend([
        "\\)",
        "!", "-name", "*.gz",
        "-exec", "gzip", "-v", "{}", "\\;",
    ])

    return command

return (morphometry_files, )


def find_cat12_input_copy(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be decoracted @step.

input_copies: list[File]
Files copied from rawdata and processed by cat12.
"""
if isinstance(matlabbatch, str):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already handle by CoerceparamsHook.

return (morphometry_files, )


def find_cat12_input_copy(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the main workflow we build the batch so have a direct access to these files in 't1_files' and the root 'output_dir.parent'. Can we avoid parsing the batch file?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants