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

import commands
import sys
# get path of the toolbox
status, path_sct = commands.getstatusoutput('echo $SCT_DIR')
# append path that contains scripts, to be able to load modules
sys.path.append(path_sct + '/scripts')

def test(data_path):

    output = ''
    status = 0

    # parameters
    folder_data = ['t2/']
    file_data = ['t2.nii.gz', 't2_seg.nii.gz', 'labels.nii.gz']

    # define command
    cmd = 'sct_detect_vertebral_levels -i ' + data_path + folder_data[0] + file_data[0] \
        + ' -seg ' + data_path + folder_data[0] + file_data[1] \
        + ' -initz 34,3 ' \
        + ' -o t2_seg_labeled_totest.nii.gz'

    output += '\n====================================================================================================\n'+cmd+'\n====================================================================================================\n\n'  # copy command
    s, o = commands.getstatusoutput(cmd)
    status += s
    output += o

    # if command ran without error, test integrity
    # if status == 0:
        # compare with gold-standard labeling

        # check if labels are located in the right vertebrae
        # TODO

        # add function that does MSD between two images

        # from sct_average_data_within_mask import average_within_mask
        # mtr_mean, mtr_std = average_within_mask('mtr.nii.gz', data_path+folder_data+file_data[2], verbose=0)
        # if not (mtr_mean > range_mtr[0] and mtr_mean < range_mtr[1]):
        #     status = 99
        #     output += '\nMean MTR = '+str(mtr_mean)+'\nAuthorized range: '+str(range_mtr)

    return status, output

<commit_msg>TEST: detect_vertebral_levels: now testing integrity<commit_after>#!/usr/bin/env python
#########################################################################################
#
# Test function sct_detect_vertebral_levels
#
# ---------------------------------------------------------------------------------------
# Copyright (c) 2015 Polytechnique Montreal <www.neuro.polymtl.ca>
# Author: <NAME>
#
# About the license: see the file LICENSE.TXT
#########################################################################################

import commands
import sys
# append path that contains scripts, to be able to load modules
status, path_sct = commands.getstatusoutput('echo $SCT_DIR')
sys.path.append(path_sct + '/scripts')
from msct_image import Image
from numpy import any

def test(data_path):

    output = ''
    status = 0

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

    # define command
    cmd = 'sct_detect_vertebral_levels -i ' + data_path + folder_data[0] + file_data[0] \
        + ' -seg ' + data_path + folder_data[0] + file_data[1] \
        + ' -initz 34,3 ' \
        + ' -o t2_seg_labeled_totest.nii.gz'

    output += '\n====================================================================================================\n'+cmd+'\n====================================================================================================\n\n'  # copy command
    s, o = commands.getstatusoutput(cmd)
    status += s
    output += o

    # if command ran without error, test integrity
    if status == 0:
        # compare with gold-standard labeling
        data_original = Image(data_path + folder_data[0] + file_data[2]).data
        data_totest = Image('t2_seg_labeled_totest.nii.gz').data
        # check if non-zero elements are present when computing the difference of the two images
        if any(data_original - data_totest):
            status = 99
            output += '\nResulting image differs from gold-standard.'

    return status, output


{'fraction_non_alphanumeric': 0.3140933140933141, 'fraction_numerical': 0.011063011063011063, 'mean_word_length': 3.2137791286727455, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '5820892', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1116, 'n_words': 284}