# Path: osrefl/theory/wavefunction_kernel.py
# def calc_r(kz_in, array_of_sld):
# def calc_r_array(kz_in_array, array_of_sld):
# def calc_r_born(kz_in, array_of_sld):
# def calc_r_born_prediscretized(kz_in, z, sld_z):
# def calc_r_born_2d_discrete(Qz, Qy, dz, dy, sld_z_y):
#     def __init__(self, kz_in, array_of_sld):
#     def calc_c_d(self):
#     def partial_layer_r(self, start_layer, end_layer):
#     def __call__(self, z):
#     def prime(self, z):
#     def __init__(self, kz_escapee, array_of_sld, layer_escaping_from):
# def sld_discretize(sld, min_feature_pixels = 10):
# def bottom_scatterer():
#     M = eye(2)
#         M = dot(M_l[layer_num], M) # cumulative product moving right to left along M_j-1*M_j-2*...*M_1
#         M = empty(((2,2,kzlen)), dtype=complex)
#         M[0,0] = 1.0
#         M[0,1] = 0.0
#         M[1,0] = 0.0
#         M[1,1] = 1.0
#             M = M_new
#         M = self.M
#         M = eye(2, dtype=complex)
#             M = dot(m, M)
#     A4 = 2. * arcsin(q / (2 * k0))
# class neutron_wavefunction:
# class escaping_neutron:
# 
# Path: osrefl/theory/czt.py
# def czt(x, m=None, w=1.0, a=1, axis=-1):
#     """
#     Compute the frequency response around a spiral.
# 
#     Parameters:
#     ----------
#     x: array
#       The set of data to transform.
#     m: int
#       The number of points desired. Default is the length of the input data.
#     a: complex
#       The starting point in the complex plane.  Default is 1.
#     w: complex or float
#       If w is complex, it is the ratio between points in each step.
#       If w is float, it is the frequency step scale (relative to the
#       normal dft frquency step).
#     axis: int
#       Array dimension to operate over.  Default is the final dimension.
# 
#     Returns:
#     -------
#       An array of the same dimensions as x, but with the length of the
#       transformed axis set to m.  Note that this is a view on a much
#       larger array.  To save space, you may want to call it as
#       y = ascontiguousarray(czt(x))
# 
#     See zoomfft for a friendlier interface to partial fft calculations.
# 
#     If the transform needs to be repeated, use CZT to construct a
#     specialized transform function which can be reused without
#     recomputing constants.
#     """
#     x = np.asarray(x)
#     transform = CZT(x.shape[axis], m=m, w=w, a=a)
#     return transform(x,axis=axis)


from pylab import imshow,colorbar,show,pcolormesh
from numpy import *
from osrefl.theory import wavefunction_kernel
from osrefl.theory import czt
    from smba_driver import magCudaBA_form
    from smba_driver import cudaBA_form
    from scipy.interpolate import RectBivariateSpline, interp1d
    from ..model.sample_prep import Q_space
    from smba_wave_driver import wave
    from smba_driver import cudaSMBA_form
    from scipy.interpolate import RectBivariateSpline
    from smba_wave_driver import wave
    from pylab import imshow,show,colorbar,figure,subplot
    from DWBA import dwbaWavefunction
    from scipy.integrate import quad
        from numpy import exp,shape
    from numpy import shape
    from osrefl.model.sample_prep import Parallelapiped, Layer, Scene, GeomUnit, Rectilinear, Beam, Q_space
    from osrefl.theory.scatter import Calculator
import osrefl.viewers.view
import numpy as np
    import wavefunction_kernel
    import time
    import osrefl.model.sample_prep
    import os
    import wx
                        a = q.q_list[0][i] - (q.q_step[0]/2.)
                        b = q.q_list[0][i] + (q.q_step[0]/2.)
                        
                        ftHoldx = quad(ftIntegral,a,b,args)[0]/q.q_step[0]
                        
                        args = [y[0,ny,0],0,rhoTilOverRho[nx,ny,nz]]
                        a = q.q_list[1][ii] - (q.q_step[1]/2.)
                        b = q.q_list[1][ii] + (q.q_step[1]/2.)
                        ftHoldy = quad(ftIntegral,a,b,args)[0]/q.q_step[1]

                        ftwRef[nx,ny,nz] = ftHoldx * ftHoldy
            
            ftwCollector[i,ii,:] = (sum(sum(ftwRef,axis = 0),axis = 0)).reshape((1,1,cell.n[2]))

            '''   
            ftwRef[i,ii,:] = (Vfac*sum(sum(rhoTilOverRho * exp(1j*q.q_list[0][i]*x)*
                                   exp(1j*q.q_list[1][ii]*y),axis = 0),axis=0))
            '''
            ftwCollector[i,ii,:] *= laux
            ftwCollector[i,ii,:] *= lauy

            
            ftwCollector[i,ii,:] *=SF[i,ii,0]

            ftwCollector[i,ii,:] = ftwCollector[i,ii,:]/(lattice.repeat[0]*lattice.repeat[1])
            
            ftwCollector[i,ii,:] = ((SLDArray[:,0]).reshape((1,1,cell.n[2]))*
                      ftwCollector[i,ii,:].reshape((1,1,cell.n[2])))

    max_qxyz = (2*pi)/cell.step

# Path: osrefl/theory/wavefunction_kernel.py
# def calc_r(kz_in, array_of_sld):
# def calc_r_array(kz_in_array, array_of_sld):
# def calc_r_born(kz_in, array_of_sld):
# def calc_r_born_prediscretized(kz_in, z, sld_z):
# def calc_r_born_2d_discrete(Qz, Qy, dz, dy, sld_z_y):
#     def __init__(self, kz_in, array_of_sld):
#     def calc_c_d(self):
#     def partial_layer_r(self, start_layer, end_layer):
#     def __call__(self, z):
#     def prime(self, z):
#     def __init__(self, kz_escapee, array_of_sld, layer_escaping_from):
# def sld_discretize(sld, min_feature_pixels = 10):
# def bottom_scatterer():
#     M = eye(2)
#         M = dot(M_l[layer_num], M) # cumulative product moving right to left along M_j-1*M_j-2*...*M_1
#         M = empty(((2,2,kzlen)), dtype=complex)
#         M[0,0] = 1.0
#         M[0,1] = 0.0
#         M[1,0] = 0.0
#         M[1,1] = 1.0
#             M = M_new
#         M = self.M
#         M = eye(2, dtype=complex)
#             M = dot(m, M)
#     A4 = 2. * arcsin(q / (2 * k0))
# class neutron_wavefunction:
# class escaping_neutron:
# 
# Path: osrefl/theory/czt.py
# def czt(x, m=None, w=1.0, a=1, axis=-1):
#     """
#     Compute the frequency response around a spiral.
# 
#     Parameters:
#     ----------
#     x: array
#       The set of data to transform.
#     m: int
#       The number of points desired. Default is the length of the input data.
#     a: complex
#       The starting point in the complex plane.  Default is 1.
#     w: complex or float
#       If w is complex, it is the ratio between points in each step.
#       If w is float, it is the frequency step scale (relative to the
#       normal dft frquency step).
#     axis: int
#       Array dimension to operate over.  Default is the final dimension.
# 
#     Returns:
#     -------
#       An array of the same dimensions as x, but with the length of the
#       transformed axis set to m.  Note that this is a view on a much
#       larger array.  To save space, you may want to call it as
#       y = ascontiguousarray(czt(x))
# 
#     See zoomfft for a friendlier interface to partial fft calculations.
# 
#     If the transform needs to be repeated, use CZT to construct a
#     specialized transform function which can be reused without
#     recomputing constants.
#     """
#     x = np.asarray(x)
#     transform = CZT(x.shape[axis], m=m, w=w, a=a)
#     return transform(x,axis=axis)


# Path: osrefl/theory/approximations.py
from pylab import imshow,colorbar,show,pcolormesh
from numpy import *
from osrefl.theory import wavefunction_kernel
from osrefl.theory import czt
    from smba_driver import magCudaBA_form
    from smba_driver import cudaBA_form
    from scipy.interpolate import RectBivariateSpline, interp1d
    from ..model.sample_prep import Q_space
    from smba_wave_driver import wave
    from smba_driver import cudaSMBA_form
    from scipy.interpolate import RectBivariateSpline
    from smba_wave_driver import wave
    from pylab import imshow,show,colorbar,figure,subplot
    from DWBA import dwbaWavefunction
    from scipy.integrate import quad
        from numpy import exp,shape
    from numpy import shape
    from osrefl.model.sample_prep import Parallelapiped, Layer, Scene, GeomUnit, Rectilinear, Beam, Q_space
    from osrefl.theory.scatter import Calculator
import osrefl.viewers.view
import numpy as np
    import wavefunction_kernel
    import time
    import osrefl.model.sample_prep
    import os
    import wx

                        a = q.q_list[0][i] - (q.q_step[0]/2.)
                        b = q.q_list[0][i] + (q.q_step[0]/2.)
                        
                        ftHoldx = quad(ftIntegral,a,b,args)[0]/q.q_step[0]
                        
                        args = [y[0,ny,0],0,rhoTilOverRho[nx,ny,nz]]
                        a = q.q_list[1][ii] - (q.q_step[1]/2.)
                        b = q.q_list[1][ii] + (q.q_step[1]/2.)
                        ftHoldy = quad(ftIntegral,a,b,args)[0]/q.q_step[1]

                        ftwRef[nx,ny,nz] = ftHoldx * ftHoldy
            
            ftwCollector[i,ii,:] = (sum(sum(ftwRef,axis = 0),axis = 0)).reshape((1,1,cell.n[2]))

            '''   
            ftwRef[i,ii,:] = (Vfac*sum(sum(rhoTilOverRho * exp(1j*q.q_list[0][i]*x)*
                                   exp(1j*q.q_list[1][ii]*y),axis = 0),axis=0))
            '''
            ftwCollector[i,ii,:] *= laux
            ftwCollector[i,ii,:] *= lauy

            
            ftwCollector[i,ii,:] *=SF[i,ii,0]

            ftwCollector[i,ii,:] = ftwCollector[i,ii,:]/(lattice.repeat[0]*lattice.repeat[1])
            
            ftwCollector[i,ii,:] = ((SLDArray[:,0]).reshape((1,1,cell.n[2]))*
                      ftwCollector[i,ii,:].reshape((1,1,cell.n[2])))

    max_qxyz = (2*pi)/cell.step

    scat = czt.zoomfft(ftwRef,q.minimums[2],q.maximums[2],q.points[2],