<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_vtk(im, path='./voxvtk', divide=False, downsample=False, voxel_size=1, vox=False):
 r""" Converts an array to a vtk file. Parameters im : 3D image The image of the porous material path : string Path to output file divide : bool vtk files can get very large, this option allows you for two output files, divided at z = half. This allows for large data sets to be imaged without loss of information downsample : bool very large images acan be downsampled to half the size in each dimension, this doubles the effective voxel size voxel_size : int The side length of the voxels (voxels are cubic) vox : bool For an image that is binary (1's and 0's) this reduces the file size by using int8 format (can also be used to reduce file size when accuracy is not necessary ie: just visulization) Notes ----- Outputs a vtk, vtp or vti file that can opened in paraview """

    if len(im.shape) == 2:
        im = im[:, :, np.newaxis]
    if im.dtype == bool:
        vox = True
    if vox:
        im = im.astype(np.int8)
    vs = voxel_size
    if divide:
        split = np.round(im.shape[2]/2).astype(np.int)
        im1 = im[:, :, 0:split]
        im2 = im[:, :, split:]
        imageToVTK(path+'1', cellData={'im': np.ascontiguousarray(im1)},
                   spacing=(vs, vs, vs))
        imageToVTK(path+'2', origin=(0.0, 0.0, split*vs),
                   cellData={'im': np.ascontiguousarray(im2)},
                   spacing=(vs, vs, vs))
    elif downsample:
        im = spim.interpolation.zoom(im, zoom=0.5, order=0, mode='reflect')
        imageToVTK(path, cellData={'im': np.ascontiguousarray(im)},
                   spacing=(2*vs, 2*vs, 2*vs))
    else:
        imageToVTK(path, cellData={'im': np.ascontiguousarray(im)},
                   spacing=(vs, vs, vs))