Пример #1
0
    def f(self, array, warp):
        """
        A sampling function, responsible for returning a sampled set of values
        from the given array.
        
        Parameters
        ----------
        array: nd-array
            Input array for sampling.
        warp: nd-array
            Deformation coordinates.
    
        Returns
        -------
        sample: nd-array
           Sampled array data.
        """
    
        if self.coordinates is None:
            raise ValueError('Appropriately defined coordinates not provided.')

        result = np.zeros_like(array)

        arg0 = c_ndarray(warp, dtype=np.double, ndim=3)
        arg1 = c_ndarray(array, dtype=np.double, ndim=2)
        arg2 = c_ndarray(result, dtype=np.double, ndim=2)

        libsampler.cubicConvolution(arg0, arg1, arg2)

        return result.flatten()
Пример #2
0
    def f(self, array, warp):
        """
        A sampling function, responsible for returning a sampled set of values
        from the given array.
        
        Parameters
        ----------
        array: nd-array
            Input array for sampling.
        warp: nd-array
            Deformation coordinates.
    
        Returns
        -------
        sample: nd-array
           Sampled array data.
        """

        if self.coordinates is None:
            raise ValueError("Appropriately defined coordinates not provided.")

        result = np.zeros_like(warp[0])

        arg0 = c_ndarray(warp, dtype=np.double, ndim=3)
        arg1 = c_ndarray(array, dtype=np.double, ndim=2)
        arg2 = c_ndarray(result, dtype=np.double, ndim=2)

        libsampler.nearest(
            arg0, arg1, arg2, ctypes.c_char(EXTRAPOLATION_MODE[0]), ctypes.c_double(EXTRAPOLATION_CVALUE)
        )

        return result.flatten()
Пример #3
0
    def f(self, array, warp):
        """
        A sampling function, responsible for returning a sampled set of values
        from the given array.
        
        Parameters
        ----------
        array: nd-array
            Input array for sampling.
        warp: nd-array
            Deformation coordinates.
    
        Returns
        -------
        sample: nd-array
           Sampled array data.
        """

        if self.coordinates is None:
            raise ValueError("Appropriately defined coordinates not provided.")

        result = np.zeros_like(array)

        arg0 = c_ndarray(warp, dtype=np.double, ndim=3)
        arg1 = c_ndarray(array, dtype=np.double, ndim=2)
        arg2 = c_ndarray(result, dtype=np.double, ndim=2)

        libsampler.cubicConvolution(arg0, arg1, arg2)

        return result.flatten()
Пример #4
0
def run(vis, model = 'gaussian', flux_ext=1e-3, dflux_ext=1e-4,
        flux_ps=0e-3, dflux_ps=1e-4,
        sigma=1*arcsec, dsigma=1*arcsec, x=0., y=0., nscan=10):

    libpath = os.path.join(os.path.abspath(__path__[0]), 'build', 'libchi2_scan.so')
    libchi2 = cdll.LoadLibrary(libpath)

    if model =='gaussian':
        shape = [nscan, nscan]
    else:
        shape = [nscan]*3
    chi2 = np.zeros(shape)

    xs = np.zeros(shape)
    ys = np.zeros(shape)

    if model == 'gaussian':
        fluxes_ext = np.linspace(flux_ext-dflux_ext, flux_ext+dflux_ext, nscan)
        sigmas = np.linspace(sigma-dsigma, sigma+dsigma, nscan)
        fluxes_ext,sigmas = np.meshgrid(fluxes_ext, sigmas)

        parameters = np.zeros(shape+[4])
        parameters[:,:,0] = fluxes_ext
        parameters[:,:,1] = xs
        parameters[:,:,2] = ys
        parameters[:,:,3] = sigmas
    elif model == 'gaussian_ps':
        fluxes_ext = np.linspace(flux_ext-dflux_ext, flux_ext+dflux_ext, nscan)
        fluxes_ps = np.linspace(flux_ps-dflux_ps, flux_ps+dflux_ps, nscan)
        sigmas = np.linspace(sigma-dsigma, sigma+dsigma, nscan)
        fluxes_ext, fluxes_ps, sigmas = meshgrid(fluxes_ext, fluxes_ps, sigmas, indexing='xy')

        parameters = np.zeros(shape+[5])
        parameters[:,:,:,0] = fluxes_ext
        parameters[:,:,:,1] = xs
        parameters[:,:,:,2] = ys
        parameters[:,:,:,3] = sigmas
        parameters[:,:,:,4] = fluxes_ps
#         fluxes,sigmas = np.meshgrid(fluxes, sigmas)
    

    chi2_scan = libchi2.c_chi2_scan
    c_chi2 = c_ndarray(chi2, dtype=chi2.dtype, ndim=chi2.ndim)
    c_parameters = c_ndarray(parameters, dtype=parameters.dtype, ndim=parameters.ndim)
    chi2_scan(c_chi2, c_int(chi2.ndim), c_char_p(vis), c_model[model], c_parameters)
    return parameters, chi2
Пример #5
0
    def f(self, array, warp):
        """
        A sampling function, responsible for returning a sampled set of values
        from the given array.

        @param array: an n-dimensional array (representing an image or volume).
        @param coords: array coordinates in cartesian form (n by p).
        """

        if self.coordinates is None:
            raise ValueError('Appropriately defined coordinates not provided.')

        result = np.zeros_like(array)

        arg0 = c_ndarray(warp, dtype=np.double, ndim=3)
        arg1 = c_ndarray(array, dtype=np.double, ndim=2)
        arg2 = c_ndarray(result, dtype=np.double, ndim=2)

        libsampler.nearest(arg0, arg1, arg2)

        return result.flatten()
Пример #6
0
    def f(self, array, warp):
        """
        A sampling function, responsible for returning a sampled set of values
        from the given array.
        
        Parameters
        ----------
        array: nd-array
            Input array for sampling.
        warp: nd-array
            Deformation coordinates.
    
        Returns
        -------
        sample: nd-array
           Sampled array data.
        """
    
        if self.coordinates is None:
            raise ValueError('Appropriately defined coordinates not provided.')

        result = np.zeros_like(warp[0])

        arg0 = c_ndarray(warp, dtype=np.double, ndim=3)
        arg1 = c_ndarray(array, dtype=np.double, ndim=2)
        arg2 = c_ndarray(result, dtype=np.double, ndim=2)

        libsampler.nearest(
            arg0, 
            arg1, 
            arg2, 
            ctypes.c_char(EXTRAPOLATION_MODE[0]),
            ctypes.c_double(EXTRAPOLATION_CVALUE)
            )

        return result.flatten()
Пример #7
0
import numpy as np
from numpyctypes import c_ndarray

c_myarray = c_ndarray(myarray, dtype=np.double, ndim=3)
Пример #8
0
def DbbWrapper(array1, array2, aShape):
    arg1 = c_ndarray(array1, dtype=N.uint8, ndim=2, shape=aShape)
    arg2 = c_ndarray(array2, dtype=N.uint8, ndim=2, shape=aShape)
    return mylib.DbbWrapper(arg1, arg2)