Example #1
0
def copyData(source, sink):
    """Copy a raw/mhd file pair from source to sink
    
    Arguments:
        source (str): file name of source
        sink (str): file name of sink
    
    Returns:
        str: file name of the copy
    """

    sourceExt = io.fileExtension(source)
    sinkExt = io.fileExtension(sink)

    sources = [source]
    sinks = []

    if sourceExt == 'raw':
        sources.append(source[:-3] + 'mhd')

        if sinkExt == 'raw':
            sinks.append(sink)
            sinks.append(sink[:-3] + 'mhd')
        elif sinkExt == 'mhd':
            sinks.append(sink[:-3] + 'raw')
            sinks.append(sink)
        else:
            raise RuntimeError('copyData: sink extension %s not raw or mhd' %
                               sinkExt)

    elif sourceExt == 'mhd':
        sources.append(source[:-3] + 'raw')

        if sinkExt == 'raw':
            sinks.append(sink[:-3] + 'mhd')
            sinks.append(sink)
        elif sinkExt == 'mhd':
            sinks.append(sink)
            sinks.append(sink[:-3] + 'raw')
        else:
            raise RuntimeError('copyData: sink extension %s not raw or mhd' %
                               sinkExt)

    for i in range(2):
        io.copyData(sources[i], sinks[i])

    return sink
Example #2
0
def copyData(source, sink):
    """Copy a raw/mhd file pair from source to sink
    
    Arguments:
        source (str): file name of source
        sink (str): file name of sink
    
    Returns:
        str: file name of the copy
    """     
    
    sourceExt = io.fileExtension(source);
    sinkExt   = io.fileExtension(sink);
    
    sources = [source]; 
    sinks = [];
    
    if sourceExt == 'raw':
        sources.append(source[:-3] + 'mhd');
        
        if sinkExt == 'raw':
            sinks.append(sink);
            sinks.append(sink[:-3] + 'mhd');
        elif sinkExt == 'mhd':
            sinks.append(sink[:-3] + 'raw');
            sinks.append(sink);
        else:
            raise RuntimeError('copyData: sink extension %s not raw or mhd' % sinkExt);
    
    elif sourceExt == 'mhd':
        sources.append(source[:-3] + 'raw');
        
        if sinkExt == 'raw':
            sinks.append(sink[:-3] + 'mhd');
            sinks.append(sink);
        elif sinkExt == 'mhd':
            sinks.append(sink);
            sinks.append(sink[:-3] + 'raw');
        else:
            raise RuntimeError('copyData: sink extension %s not raw or mhd' % sinkExt);
        
    for i in range(2):
        io.copyData(sources[i], sinks[i]);
    
    return sink;