def setCInterface(homotopy_lib): global homotopy homotopy = loadclib.loadCLibrary(os.path.dirname(__file__), homotopy_lib) l1flt_size = homotopy.getL1FLTSize() if (l1flt_size == 4): float_type = c_float float_array_type = numpy.float32 elif (l1flt_size == 8): float_type = c_double float_array_type = numpy.float64 homotopy.getXVector.argtypes = [ndpointer(dtype=float_array_type)] homotopy.initialize.argtypes = [ ndpointer(dtype=float_array_type), c_int, c_int, c_int, c_int, c_int ] homotopy.l2Error.argtypes = [ndpointer(dtype=float_array_type)] homotopy.l2Error.restype = float_type homotopy.newYVector.argtypes = [ndpointer(dtype=float_array_type)] homotopy.solve.argtypes = [float_type, c_int] homotopy.solve.restype = float_type if (hasattr(homotopy, "getVisited")): homotopy.getVisited.argtypes = [ndpointer(dtype=numpy.int32)] if (hasattr(homotopy, "initializeGPU")): homotopy.initializeGPU.argtypes = [c_char_p, c_int, c_int, c_int]
def setCInterface(homotopy_lib): global homotopy homotopy = loadclib.loadCLibrary(os.path.dirname(__file__), homotopy_lib) l1flt_size = homotopy.getL1FLTSize() if(l1flt_size == 4): float_type = c_float float_array_type = numpy.float32 elif(l1flt_size == 8): float_type = c_double float_array_type = numpy.float64 homotopy.getXVector.argtypes = [ndpointer(dtype=float_array_type)] homotopy.initialize.argtypes = [ndpointer(dtype=float_array_type), c_int, c_int, c_int, c_int, c_int] homotopy.l2Error.argtypes = [ndpointer(dtype=float_array_type)] homotopy.l2Error.restype = float_type homotopy.newYVector.argtypes = [ndpointer(dtype=float_array_type)] homotopy.solve.argtypes = [float_type, c_int] homotopy.solve.restype = float_type if(hasattr(homotopy, "getVisited")): homotopy.getVisited.argtypes = [ndpointer(dtype=numpy.int32)] if(hasattr(homotopy, "initializeGPU")): homotopy.initializeGPU.argtypes = [c_char_p, c_int, c_int, c_int]
# # Hazen # import numpy import os import scipy import scipy.ndimage import ctypes import numpy from numpy.ctypeslib import ndpointer import sa_library.loadclib as loadclib rball = loadclib.loadCLibrary(os.path.dirname(__file__), "rolling_ball_lib") # C interface definition rball.estimateBg.argtypes = [ ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ctypes.c_int, ctypes.c_int ] rball.init.argtypes = [ndpointer(dtype=numpy.float64), ctypes.c_int] class CRollingBall(object): def __init__(self, ball_radius, smoothing_sigma): self.ball_radius = ball_radius self.smoothing_sigma = smoothing_sigma ball_size = int(round(ball_radius * 0.5))
#!/usr/bin/python # # Simple Python interface to utilities.c. # # Hazen 6/11 # from ctypes import * import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.loadclib as loadclib util = loadclib.loadCLibrary(os.path.dirname(__file__), "ia_utilities") # C interface definition util.findLocalMaxima.argtypes = [ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.float64), c_double, c_double, c_double, c_double, c_int, c_int, c_int, c_int] util.findLocalMaxima.restype = c_int util.getBackgroundIndex.restype = c_int
# Simple Python interface to grid.c. This is a somewhat faster # but less flexible approach to creating 2D and 3D histograms # than using the built-in numpy function numpy.histogramdd(). # # Hazen 12/11 # from ctypes import * import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.loadclib as loadclib grid = loadclib.loadCLibrary(os.path.dirname(__file__), "grid") # Function specifications grid.grid2D.argtypes = [ ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.int32), c_int, c_int, c_int ] grid.grid3D.argtypes = [ ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.int32), c_int, c_int, c_int, c_int ]
#!/usr/bin/python # # Draws guassians onto a user supplied image. # # Hazen 01/16 # import ctypes import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.loadclib as loadclib drawgauss = loadclib.loadCLibrary(os.path.dirname(__file__), "draw_gaussians") drawgauss.drawGaussians.argtypes = [ ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int ] def cDrawGaussians(image, objects, resolution): c_image = numpy.ascontiguousarray(image, dtype=numpy.float64) c_objects = numpy.ascontiguousarray(objects, dtype=numpy.float64) drawgauss.drawGaussians(c_image, c_objects, c_image.shape[1], c_image.shape[0], objects.shape[0], resolution) return c_image
#!/usr/bin/env python # # Simply Python interface to matched_filter.c # # Hazen 3/16 # import ctypes import numpy from numpy.ctypeslib import ndpointer import os import sa_library.loadclib as loadclib import sa_library.recenter_psf as recenterPSF m_filter = loadclib.loadCLibrary(os.path.dirname(__file__), "matched_filter") m_filter.cleanup.argtypes = [ctypes.c_void_p] m_filter.convolve.argtypes = [ctypes.c_void_p, ndpointer(dtype = numpy.float64), ndpointer(dtype = numpy.float64)] m_filter.initialize.argtypes = [ndpointer(dtype = numpy.float64), ctypes.c_int, ctypes.c_int] m_filter.initialize.restype = ctypes.c_void_p class MatchedFilterException(Exception): def __init__(self, message): Exception.__init__(self, message)
# and cleanup once, rather than for every image in movie. # Also, all the static variables should be removed from # multi_fit.c # from ctypes import * import math import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.ia_utilities_c as util_c import sa_library.loadclib as loadclib multi = loadclib.loadCLibrary(os.path.dirname(__file__), "multi_fit") # C interface definition multi.getError.restype = c_double multi.getResidual.argtypes = [ndpointer(dtype=numpy.float64)] multi.getResults.argtypes = [ndpointer(dtype=numpy.float64)] multi.getUnconverged.restype = c_int multi.initialize.argtypes = [ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), c_double, c_int, c_int, c_int, c_int] multi.initializeZParameters.argtypes = [ndpointer(dtype=numpy.float64),
#!/usr/bin/python # # Simple Python interface to fista_decon_utilities.c # # Hazen 1/16 # import ctypes import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.loadclib as loadclib fd_util = loadclib.loadCLibrary(os.path.dirname(__file__), "fista_decon_utilities") # C interface definition fd_util.label.argtypes = [ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.int32), ctypes.c_double, ctypes.c_int, ctypes.c_int, ctypes.c_int] fd_util.label.restype = ctypes.c_int fd_util.moments.argtypes = [ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.int32), ctypes.c_int, ctypes.c_int, ctypes.c_int,
# Simple Python interface to fista_fft.c # # Hazen 2/16 # import ctypes import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.loadclib as loadclib import fista_3d as fista3D fista_fft = loadclib.loadCLibrary(os.path.dirname(__file__), "fista_fft") # C interface definition fista_fft.getXVector.argtypes = [ndpointer(dtype=numpy.float64)] fista_fft.initialize2D.argtypes = [ndpointer(dtype=numpy.float64), ctypes.c_double, ctypes.c_int] fista_fft.initialize3D.argtypes = [ndpointer(dtype=numpy.float64), ctypes.c_double, ctypes.c_int, ctypes.c_int] fista_fft.iterate.argtypes = [ctypes.c_double] fista_fft.l1Error.restype = ctypes.c_double fista_fft.l2Error.restype = ctypes.c_double fista_fft.newImage.argtypes = [ndpointer(dtype=numpy.float64)] fista_fft.run.argtypes = [ctypes.c_double,
#!/usr/bin/env python # # Simply Python interface to matched_filter.c # # Hazen 3/16 # import ctypes import numpy from numpy.ctypeslib import ndpointer import os import sa_library.loadclib as loadclib import sa_library.recenter_psf as recenterPSF m_filter = loadclib.loadCLibrary(os.path.dirname(__file__), "matched_filter") m_filter.cleanup.argtypes = [ctypes.c_void_p] m_filter.convolve.argtypes = [ ctypes.c_void_p, ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64) ] m_filter.initialize.argtypes = [ ndpointer(dtype=numpy.float64), ctypes.c_int, ctypes.c_int ] m_filter.initialize.restype = ctypes.c_void_p class MatchedFilterException(Exception): def __init__(self, message):
#!/usr/bin/python # # Draws guassians onto a user supplied image. # # Hazen 01/16 # import ctypes import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.loadclib as loadclib drawgauss = loadclib.loadCLibrary(os.path.dirname(__file__), "draw_gaussians") drawgauss.drawGaussians.argtypes = [ndpointer(dtype = numpy.float64), ndpointer(dtype = numpy.float64), ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int] def cDrawGaussians(image, objects, resolution): c_image = numpy.ascontiguousarray(image, dtype = numpy.float64) c_objects = numpy.ascontiguousarray(objects, dtype = numpy.float64) drawgauss.drawGaussians(c_image, c_objects, c_image.shape[1], c_image.shape[0],
# # Hazen # # from ctypes import * import math import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.ia_utilities_c as util_c import sa_library.loadclib as loadclib multi = loadclib.loadCLibrary(os.path.dirname(__file__), "multi_fit") # C interface definition multi.getError.restype = c_double multi.getResidual.argtypes = [ndpointer(dtype=numpy.float64)] multi.getResults.argtypes = [ndpointer(dtype=numpy.float64)] multi.getUnconverged.restype = c_int multi.initialize.argtypes = [ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), c_double, c_int, c_int, c_int, c_int] multi.initializeZParameters.argtypes = [ndpointer(dtype=numpy.float64),
# "Video-rate nanoscopy using sCMOS camera-specific single-molecule localization algorithms" # F. Huang et al. Nature Methods, 10, p653-658. # # Hazen 10/13 # import ctypes import math import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.loadclib as loadclib slib = loadclib.loadCLibrary(os.path.dirname(__file__), "scmos_utilities") # C interface definition. slib.deregularize.argtypes = [ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ctypes.c_int] slib.regularize.argtypes = [ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ctypes.c_int]
#!/usr/bin/python # # Simple Python interface to utilities.c. # # Hazen 6/11 # import ctypes import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.loadclib as loadclib util = loadclib.loadCLibrary(os.path.dirname(__file__), "ia_utilities") # C interface definition util.findLocalMaxima.argtypes = [ ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.float64), ctypes.c_double, ctypes.c_double, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int ] util.findLocalMaxima.restype = ctypes.c_int util.getBackgroundIndex.restype = ctypes.c_int util.getErrorIndex.restype = ctypes.c_int util.getHeightIndex.restype = ctypes.c_int util.getNPeakPar.restype = ctypes.c_int util.getNResultsPar.restype = ctypes.c_int util.getStatusIndex.restype = ctypes.c_int
# Simple Python interface to fista_fft.c # # Hazen 2/16 # import ctypes import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.loadclib as loadclib import fista_3d as fista3D fista_fft = loadclib.loadCLibrary(os.path.dirname(__file__), "fista_fft") # C interface definition fista_fft.getXVector.argtypes = [ndpointer(dtype=numpy.float64)] fista_fft.initialize2D.argtypes = [ ndpointer(dtype=numpy.float64), ctypes.c_double, ctypes.c_int ] fista_fft.initialize3D.argtypes = [ ndpointer(dtype=numpy.float64), ctypes.c_double, ctypes.c_int, ctypes.c_int ] fista_fft.iterate.argtypes = [ctypes.c_double] fista_fft.l1Error.restype = ctypes.c_double fista_fft.l2Error.restype = ctypes.c_double fista_fft.newImage.argtypes = [ndpointer(dtype=numpy.float64)] fista_fft.run.argtypes = [ctypes.c_double, ctypes.c_int]
# Simple Python interface to grid.c. This is a somewhat faster # but less flexible approach to creating 2D and 3D histograms # than using the built-in numpy function numpy.histogramdd(). # # Hazen 12/11 # from ctypes import * import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.loadclib as loadclib grid = loadclib.loadCLibrary(os.path.dirname(__file__), "grid") # Function specifications grid.grid2D.argtypes = [ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.int32), c_int, c_int, c_int] grid.grid3D.argtypes = [ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.int32), ndpointer(dtype=numpy.int32), c_int, c_int,
# "Video-rate nanoscopy using sCMOS camera-specific single-molecule localization algorithms" # F. Huang et al. Nature Methods, 10, p653-658. # # Hazen 10/13 # import ctypes import math import numpy from numpy.ctypeslib import ndpointer import os import sys import sa_library.loadclib as loadclib slib = loadclib.loadCLibrary(os.path.dirname(__file__), "scmos_utilities") # C interface definition. slib.deregularize.argtypes = [ ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ctypes.c_int ] slib.regularize.argtypes = [ ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64), ndpointer(dtype=numpy.float64),