<commit_before>#!/usr/bin/env python
#########################################################################################
#
# Test function sct_label_utils
#
# ---------------------------------------------------------------------------------------
# Copyright (c) 2014 Polytechnique Montreal <www.neuro.polymtl.ca>
# Author: <NAME>
# modified: 2014/10/30
#
# About the license: see the file LICENSE.TXT
#########################################################################################

# TODO: add test to other processes.

import commands

def test(data_path):

    # parameters
    folder_data = ['t2/']
    file_data = ['t2_seg.nii.gz', 't2_seg_labeled.nii.gz']
    output = ''
    status = 0
    list_status = []

    # TEST CREATE
    cmd = 'sct_label_utils -i ' + data_path + folder_data[0] + file_data[0] + ' -create 1,1,1,1:2,2,2,2'
    output += '\n====================================================================================================\n'+cmd+'\n====================================================================================================\n\n'  # copy command
    s, o = commands.getstatusoutput(cmd)
    list_status.append(s)
    output += o

    # TEST cubic-to-point
    cmd = 'sct_label_utils -i ' + data_path + folder_data[0] + file_data[1] + ' -cubic-to-point -o test_centerofmass.nii.gz'
    output += '\n====================================================================================================\n'+cmd+'\n====================================================================================================\n\n'  # copy command
    s, o = commands.getstatusoutput(cmd)
    list_status.append(s)
    output += o

    # Integrity testing
    if s == 0:
        # compute center of mass of labeled segmentation
        status_mass, output_mass = commands.getstatusoutput('sct_label_utils -i test_centerofmass.nii.gz -display')
        centers_of_mass = '30,25,25,4:30,42,25,3:31,9,25,5:32,0,25,6:30,52,26,2'
        if output_mass.split('\n')[-1] != centers_of_mass:
            output += 'WARNING: Center of mass different from gold-standard. \n--> Results:   ' + output_mass.split('\n')[-1] + '\n--> Should be: ' + centers_of_mass + '\n'
            list_status.append(99)

    # check if at least one integrity status was equal to 99
    if 99 in list_status:
        status = 99

    return status, output


if __name__ == "__main__":
    # call main function
    test()<commit_msg>TEST: new test for sct_label_utils compatible with sct_pipeline (#1402)<commit_after>#!/usr/bin/env python
#########################################################################################
#
# Test function sct_label_utils
#
# ---------------------------------------------------------------------------------------
# Copyright (c) 2014 Polytechnique Montreal <www.neuro.polymtl.ca>
# Author: <NAME>
# modified: 2014/10/30
#
# About the license: see the file LICENSE.TXT
#########################################################################################

# TODO: add test to other processes.

import commands
from pandas import DataFrame
import time

def test(path_data='', parameters=''):

    # parameters
    folder_data = ['t2/']
    file_data = ['t2_seg.nii.gz', 't2_seg_labeled.nii.gz']
    output = ''
    status = 0
    list_status = []

    # start timer
    time_start = time.time()

    # TEST CREATE
    cmd = 'sct_label_utils -i ' + path_data + folder_data[0] + file_data[0] + ' -create 1,1,1,1:2,2,2,2'
    output += '\n====================================================================================================\n'+cmd+'\n====================================================================================================\n\n'  # copy command
    s, o = commands.getstatusoutput(cmd)
    list_status.append(s)
    output += o

    # TEST cubic-to-point
    cmd = 'sct_label_utils -i ' + path_data + folder_data[0] + file_data[1] + ' -cubic-to-point -o test_centerofmass.nii.gz'
    output += '\n====================================================================================================\n'+cmd+'\n====================================================================================================\n\n'  # copy command
    s, o = commands.getstatusoutput(cmd)
    list_status.append(s)
    output += o

    duration = time.time() - time_start

    # Integrity testing
    if s == 0:
        # compute center of mass of labeled segmentation
        status_mass, output_mass = commands.getstatusoutput('sct_label_utils -i test_centerofmass.nii.gz -display')
        centers_of_mass = '30,25,25,4:30,42,25,3:31,9,25,5:32,0,25,6:30,52,26,2'
        if output_mass.split('\n')[-1] != centers_of_mass:
            output += 'WARNING: Center of mass different from gold-standard. \n--> Results:   ' + output_mass.split('\n')[-1] + '\n--> Should be: ' + centers_of_mass + '\n'
            list_status.append(99)

    # check if at least one integrity status was equal to 99
    if 99 in list_status:
        status = 99

    # transform results into Pandas structure
    results = DataFrame(data={'status': status, 'output': output, 'duration [s]': duration}, index=[path_data])

    # end test
    return status, output, results


if __name__ == "__main__":
    # call main function
    test()
{'fraction_non_alphanumeric': 0.358726549175668, 'fraction_numerical': 0.028046238393026342, 'mean_word_length': 3.577623590633131, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1341367', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1455, 'n_words': 338}