コード例 #1
0
 def __init__(self, original_fname, final_fname):
     self.original_fname = original_fname
     self.final_fname = final_fname
     
     #Create a copy to work with
     os.copyfile(self.original_fname, self.final_fname)
     
     self.parse_text()
     self.get_ccli_info()
     self.apply_ccli_info()
コード例 #2
0
def makekmz(outputPath):
    path = os.getcwd()
    print path
    try:
        shutil.make_archive(outputPath, "zip", outputPath)
    except:
        print "can not make file"
    print "Zip created!"
    try:
        os.copyfile(outputPath + ".zip", outputPath + ".kmz")
    except:
        print "overwriting"
        try:
            os.remove(outputPath + ".kmz")
            os.rename(outputPath + ".zip", outputPath + ".kmz")
        except:
            print "Failed"
コード例 #3
0
def register2MNI(fsl_dir, in_file, out_file, affmat, warp):
    """Register an image (or time-series of images) to MNI152 T1 2mm.

    If no affmat is defined, it only warps (i.e. it assumes that the data has
    been registered to the structural scan associated with the warp-file
    already). If no warp is defined either, it only resamples the data to 2mm
    isotropic if needed (i.e. it assumes that the data has been registered to
    a MNI152 template). In case only an affmat file is defined, it assumes that
    the data has to be linearly registered to MNI152 (i.e. the user has a
    reason not to use non-linear registration on the data).

    Parameters
    ----------
    fsl_dir : str
        Full path of the bin-directory of FSL
    in_file : str
        Full path to the data file (nii.gz) which has to be registerd to
        MNI152 T1 2mm
    out_file : str
        Full path of the output file
    affmat : str
        Full path of the mat file describing the linear registration (if data
        is still in native space)
    warp : str
        Full path of the warp file describing the non-linear registration (if
        data has not been registered to MNI152 space yet)

    Output
    ------
    melodic_IC_mm_MNI2mm.nii.gz : merged file containing the mixture modeling
                                  thresholded Z-statistical maps registered to
                                  MNI152 2mm
    """
    # Define the MNI152 T1 2mm template
    fslnobin = fsl_dir.rsplit('/', 2)[0]
    ref = op.join(fslnobin, 'data', 'standard', 'MNI152_T1_2mm_brain.nii.gz')

    # If the no affmat- or warp-file has been specified, assume that the data
    # is already in MNI152 space. In that case only check if resampling to
    # 2mm is needed
    if not affmat and not warp:
        in_img = nib.load(in_file)
        # Get 3D voxel size
        pixdim1, pixdim2, pixdim3 = in_img.header.get_zooms()[:3]

        # If voxel size is not 2mm isotropic, resample the data, otherwise
        # copy the file
        if (pixdim1 != 2) or (pixdim2 != 2) or (pixdim3 != 2):
            os.system(' '.join([
                op.join(fsl_dir, 'flirt'), ' -ref ' + ref, ' -in ' + in_file,
                ' -out ' + out_file, ' -applyisoxfm 2 -interp trilinear'
            ]))
        else:
            os.copyfile(in_file, out_file)

    # If only a warp-file has been specified, assume that the data has already
    # been registered to the structural scan. In that case apply the warping
    # without a affmat
    elif not affmat and warp:
        # Apply warp
        os.system(' '.join([
            op.join(fsl_dir, 'applywarp'), '--ref=' + ref, '--in=' + in_file,
            '--out=' + out_file, '--warp=' + warp, '--interp=trilinear'
        ]))

    # If only a affmat-file has been specified perform affine registration to
    # MNI
    elif affmat and not warp:
        os.system(' '.join([
            op.join(fsl_dir, 'flirt'), '-ref ' + ref, '-in ' + in_file,
            '-out ' + out_file, '-applyxfm -init ' + affmat,
            '-interp trilinear'
        ]))

    # If both a affmat- and warp-file have been defined, apply the warping
    # accordingly
    else:
        os.system(' '.join([
            op.join(fsl_dir, 'applywarp'), '--ref=' + ref, '--in=' + in_file,
            '--out=' + out_file, '--warp=' + warp, '--premat=' + affmat,
            '--interp=trilinear'
        ]))
コード例 #4
0
#!/usr/bin/python
'''
Geoffrey Weal, make_finish_files.py, 10/02/2021

This program will put all the input files you need for VASP into all the cluster folders.
'''

from os import copyfile

VASP_Input_Files = 'VASP_Input_Files'
files_to_copy = os.listdir(VASP_Input_Files)

cluster_folders = []
for folder in os.listdir('.'):
	if os.path.isdir('./'+folder) and (folder.startswith('Ico_') or folder.startswith('Deca_') or folder.startswith('Octa_')):
		cluster_folders.append(folder)

for cluster_folder in cluster_folders:
	print('Copying files from '+VASP_Input_Files+' to '+cluster_folder)
	for file_to_copy in files_to_copy:
		copyfile(VASP_Input_Files+'/'+file_to_copy,cluster_folder+'/'+file_to_copy)
コード例 #5
0
ファイル: segmap.py プロジェクト: sokvisal/analyzeclumps
%load_ext autoreload
%autoreload 1
%aimport segment
%aimport offset

from tqdm import tqdm
import glob
import os

tiles = ['t062']


wdir = "test_run"
os.mkdir(wdir)
os.copyfile('./analyzeclumps/segment.py', wdir)
os.copyfile('./analyzeclumps/offset.py', wdir)

os.chdir(wdir)

import segment
import offset

catdir = '/hpcstorage/sok/run/'
catname = 'cosmos_sfgs.dat'
decpath = '../cosmos/deconv'

for tile in tiles:
    offset.return_offsets(catdir, catname, tile, decpath)
    segment.wscat(catdir, 'cosmos_sfgs', '../deconv', tile, savedir=True)
コード例 #6
0
ファイル: main.py プロジェクト: zerynth/core-zerynth-stdlib
ww = os.open('0:zerynth.txt', 'w+')

# write a string on it, flushing data immediately (not waiting for file to be closed)
ww.write("Zerynth allows me to easily manage files, cool.", sync=True)

# ops, I forgot what I wrote...
# not a real problem problem using Zerynth

# back to the start
ww.seek(0)
print("I wrote: ", ww.read())

ww.close()

# files and directories in root folder?
print(os.listdir('.'))

# a folder for zerynth stuff is needed
if not os.exists("0:zerynth_stuff"):
    os.mkdir("0:zerynth_stuff")

# copy my cool file
os.copyfile("zerynth.txt", "zerynth_stuff/zerynth_cool.txt")
os.chdir("0:zerynth_stuff")

# check if anything went wrong
print("in ", os.getcwd())
print(os.listdir('.'))

print("SUCCESS!")
コード例 #7
0
ファイル: setup.py プロジェクト: pinshuai/watershed-workflow
        'console_scripts': [
            # 'command = some.module:some_function',
        ],
    },
    include_package_data=True,
    package_data={
        'watershed_workflow': [
            # When adding files here, remember to update MANIFEST.in as well,
            # or else they will not be included in the distribution on PyPI!
            # 'path/to/data_file',
        ]
    },
    install_requires=requirements,
    license="BSD (3-clause)",
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Natural Language :: English',
        'Programming Language :: Python :: 3',
    ],
)

# copy over the rc file as a template
try:
    rcfile = path.join(os.environ['HOME'], '.watershed_worklowrc')
    if not path.exists(rcfile):
        os.copyfile(path.join(here, 'watershed_workflowrc'), rcfile)
except:
    warnings.warn(
        'Warning: cannot figure out where to put .watershed_workflowrc.  Manually copy this to your home directory.'
    )
コード例 #8
0
ファイル: File.py プロジェクト: dvargas2013/MainPythons
 def Copy(old,new,copy=copy):
     head, tail = split(new) #Make sure directory exists
     if head and tail and not exists(head): makedirs(head)
     Delete(copy,new)
     copyfile(old,new)
     print('Copy: %s => %s'%(old,new))