<commit_before>#!/usr/bin/env python


import commands, 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')

from msct_parser import Parser
from nibabel import load, save, Nifti1Image
import os
import time
import sct_utils as sct
from sct_process_segmentation import extract_centerline
from sct_orientation import get_orientation

# DEFAULT PARAMETERS
class Param:
   ## The constructor
   def __init__(self):
       self.debug = 0
       self.verbose = 1  # verbose
       self.remove_temp_files = 1
       self.type_window = 'hanning'  # for smooth_centerline @sct_straighten_spinalcord
       self.window_length = 80  # for smooth_centerline @sct_straighten_spinalcord
       self.algo_fitting = 'nurbs'
       # self.parameter = "binary_centerline"
       self.list_file = []
       self.output_file_name = ''


def main(list_file, param, output_file_name=None, remove_temp_files = 1, verbose = 0):

    path, file, ext = sct.extract_fname(list_file[0])

    # create temporary folder
    path_tmp = 'tmp.'+time.strftime("%y%m%d%H%M%S")
    sct.run('mkdir '+path_tmp)

    # copy files into tmp folder
    sct.printv('\nCopy files into tmp folder...', verbose)
    for i in range(len(list_file)):
       file_temp = os.path.abspath(list_file[i])
       sct.run('cp '+file_temp+' '+path_tmp)

    # go to tmp folder
    os.chdir(path_tmp)

    ## Concatenation of the files

    # Concatenation : sum of matrices
    file_0 = load(list_file[0])
    data_concatenation = file_0.get_data()
    hdr_0 = file_0.get_header()
    orientation_file_0 = get_orientation(list_file[0])
    if len(list_file)>0:
       for i in range(1, len(list_file)):
           orientation_file_temp = get_orientation(list_file[i])
           if orientation_file_0 != orientation_file_temp :
               print "ERROR: The files ", list_file[0], " and ", list_file[i], " are not in the same orientation. Use sct_orientation to change the orientation of a file."
               sys.exit(2)
           file_temp = load(list_file[i])
           data_temp = file_temp.get_data()
           data_concatenation = data_concatenation + data_temp

    # Save concatenation as a file
    print '\nWrite NIFTI volumes...'
    img = Nifti1Image(data_concatenation, None, hdr_0)
    save(img,'concatenation_file.nii.gz')

<commit_msg>BUG: partial path did not work<commit_after>#!/usr/bin/env python


import commands, 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')

from msct_parser import Parser
from nibabel import load, save, Nifti1Image
import os
import time
import sct_utils as sct
from sct_process_segmentation import extract_centerline
from sct_orientation import get_orientation

# DEFAULT PARAMETERS
class Param:
   ## The constructor
   def __init__(self):
       self.debug = 0
       self.verbose = 1  # verbose
       self.remove_temp_files = 1
       self.type_window = 'hanning'  # for smooth_centerline @sct_straighten_spinalcord
       self.window_length = 80  # for smooth_centerline @sct_straighten_spinalcord
       self.algo_fitting = 'nurbs'
       # self.parameter = "binary_centerline"
       self.list_file = []
       self.output_file_name = ''


def main(list_file, param, output_file_name=None, remove_temp_files = 1, verbose = 0):

    path, file, ext = sct.extract_fname(list_file[0])

    # create temporary folder
    path_tmp = 'tmp.'+time.strftime("%y%m%d%H%M%S")
    sct.run('mkdir '+path_tmp)

    # copy files into tmp folder
    sct.printv('\nCopy files into tmp folder...', verbose)
    for i in range(len(list_file)):
       file_temp = os.path.abspath(list_file[i])
       sct.run('cp '+file_temp+' '+path_tmp)

    # go to tmp folder
    os.chdir(path_tmp)

    ## Concatenation of the files

    # Concatenation : sum of matrices
    file_0 = load(file+ext)
    data_concatenation = file_0.get_data()
    hdr_0 = file_0.get_header()
    orientation_file_0 = get_orientation(list_file[0])
    if len(list_file)>0:
       for i in range(1, len(list_file)):
           orientation_file_temp = get_orientation(list_file[i])
           if orientation_file_0 != orientation_file_temp :
               print "ERROR: The files ", list_file[0], " and ", list_file[i], " are not in the same orientation. Use sct_orientation to change the orientation of a file."
               sys.exit(2)
           file_temp = load(list_file[i])
           data_temp = file_temp.get_data()
           data_concatenation = data_concatenation + data_temp

    # Save concatenation as a file
    print '\nWrite NIFTI volumes...'
    img = Nifti1Image(data_concatenation, None, hdr_0)
    save(img,'concatenation_file.nii.gz')


{'fraction_non_alphanumeric': 0.09749133183765042, 'fraction_numerical': 0.00917805425249847, 'mean_word_length': 3.324514991181658, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5095788', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1599, 'n_words': 405}