Skip to content

Instantly share code, notes, and snippets.

@somada141
somada141 / os_path_walk.md
Last active August 29, 2015 14:03
Traverse a directory with os.path.walk #python #fileIO #os

Traverse a directory with os.path.walk

# Import the os module, for the os.walk function
import os
 
# Set the directory you want to start from
rootDir = '.'
for dirName, subdirList, fileList in os.walk(rootDir):
 print('Found directory: %s' % dirName)
@somada141
somada141 / tcc_disable_internal.md
Created June 30, 2014 01:25
Take Command Prompt: Disable an internal command

This option allows you to disable or enable internal commands. To disable a command, precede the command name with a minus [-]. To re-enable a command, precede it with a plus [+]. For example, to disable the internal LIST command to force TCC to use an external command:

setdos /i-list

To re-enable all disabled commands use /I*.

source:

@somada141
somada141 / ipython_notebook_progressbar.md
Last active August 29, 2015 14:03
IPython Notebook ProgressBar #python #visualization #ipython #progressbar

IPython Notebook ProgressBar

Class

import sys, time
try:
    from IPython.display import clear_output
    have_ipython = True
except ImportError:
@somada141
somada141 / mayavi_vis_mesh.py
Last active August 29, 2015 14:03
Visualize Mesh (MayaVi) #python #visualization #meshing #mayavi #mlab
# mesh created with
# verts, faces = skimage.measure.marching_cubes(volume, level, spacing=(1.0, 1.0, 1.0))
from mayavi import mlab
verts, faces = marching_cubes(myvolume, 0.0, (1., 1., 2.))
mlab.triangular_mesh([vert[0] for vert in verts],
[vert[1] for vert in verts],
[vert[2] for vert in verts],
faces)
mlab.show()
@somada141
somada141 / ct2hu.md
Last active March 7, 2023 21:43
Converting CT Data to Hounsfield Units #medical #CT #imagedata #dicom #hounsfield #math

Converting CT Data to Hounsfield Units

The formula is:

hu = pixel_value * slope + intercept

Normally, these values are stored in the DICOM file itself. The tags are generally called the Rescale Slope and Rescale Intercept, and typically have values of 1 and -1024, respectively.

@somada141
somada141 / copy_tree.py
Last active August 29, 2015 14:03
How to Recursively Copy a Folder (Directory) in Python #python #fileIO #shutil
import shutil
def copyDirectory(src, dest):
try:
shutil.copytree(src, dest)
# Directories are the same
except shutil.Error as e:
print('Directory not copied. Error: %s' % e)
# Any error saying that the directory doesn't exist
except OSError as e: