Example #1
0
 def calc_overlap(self):
     wf_in = dwbaWavefunction(self.kz_in, self.SLDArray)
     wf_out = dwbaWavefunction(-self.kz_out, self.SLDArray) # solve 1d equation for time-reversed state
     self.wf_in = wf_in
     self.wf_out = wf_out
     
     kz_in_l = wf_in.kz_l # inside the layers
     kz_out_l = -wf_out.kz_l # inside the layers
     
     dz = self.SLDArray[1:-1,1][:,newaxis,newaxis,newaxis]
     zs = cumsum(self.SLDArray[1:-1,1]) - self.SLDArray[1,1] # start at zero with first layer
     z_array = array(zs)[:,newaxis,newaxis,newaxis]
     thickness = sum(self.SLDArray[1:-1,1])
     
     qrt_inside = -kz_in_l[1:-1] - kz_out_l[1:-1]
     qtt_inside = -kz_in_l[1:-1] + kz_out_l[1:-1]
     qtr_inside = +kz_in_l[1:-1] + kz_out_l[1:-1]
     qrr_inside = +kz_in_l[1:-1] - kz_out_l[1:-1]
     
     # the overlap is the forward-moving amplitude c in psi_in multiplied by 
     # the forward-moving amplitude in the time-reversed psi_out, which
     # ends up being the backward-moving amplitude d in the non-time-reversed psi_out
     # (which is calculated by the wavefunction calculator)
     # ... and vice-verso for d and c in psi_in and psi_out
     overlap  = wf_out.c[1:-1] * wf_in.c[1:-1] / (1j * qtt_inside) * (exp(1j * qtt_inside * dz) - 1.0)*exp(1j*qtt_inside*z_array)
     overlap += wf_out.d[1:-1] * wf_in.d[1:-1] / (1j * qrr_inside) * (exp(1j * qrr_inside * dz) - 1.0)*exp(1j*qrr_inside*z_array)
     overlap += wf_out.c[1:-1] * wf_in.d[1:-1] / (1j * qtr_inside) * (exp(1j * qtr_inside * dz) - 1.0)*exp(1j*qtr_inside*z_array)
     overlap += wf_out.d[1:-1] * wf_in.c[1:-1] / (1j * qrt_inside) * (exp(1j * qrt_inside * dz) - 1.0)*exp(1j*qrt_inside*z_array)
     self.overlap = overlap
     return overlap
Example #2
0
def calc_gisans(alpha_in, show_plot=True):

    #alpha_in = 0.25 # incoming beam angle

    kz_in_0 = 2 * pi / wavelength * sin(alpha_in * pi / 180.0)
    kz_out_0 = kz_in - qz

    wf_in = dwbaWavefunction(kz_in_0, SLDArray)
    wf_out = dwbaWavefunction(-kz_out_0, conj(SLDArray))

    kz_in_l = wf_in.kz_l
    kz_out_l = -wf_out.kz_l

    zs = cumsum(SLDArray[1:-1, 1])
    dz = SLDArray[1:-1, 1][:, newaxis]
    z_array = array(zs)[:, newaxis]

    qrt_inside = kz_in_l[1] - kz_out_l[1]
    qtt_inside = kz_in_l[1] + kz_out_l[1]
    qtr_inside = -kz_in_l[1] + kz_out_l[1]
    qrr_inside = -kz_in_l[1] - kz_out_l[1]

    # the overlap is the forward-moving amplitude c in psi_in multiplied by
    # the forward-moving amplitude in the time-reversed psi_out, which
    # ends up being the backward-moving amplitude d in the non-time-reversed psi_out
    # (which is calculated by the wavefunction calculator)
    # ... and vice-verso for d and c in psi_in and psi_out
    overlap = wf_out.d[1] * wf_in.c[1] / (1j * qtt_inside) * (
        exp(1j * qtt_inside * thickness) - 1.0)
    overlap += wf_out.c[1] * wf_in.d[1] / (1j * qrr_inside) * (
        exp(1j * qrr_inside * thickness) - 1.0)
    overlap += wf_out.d[1] * wf_in.d[1] / (1j * qtr_inside) * (
        exp(1j * qtr_inside * thickness) - 1.0)
    overlap += wf_out.c[1] * wf_in.c[1] / (1j * qrt_inside) * (
        exp(1j * qrt_inside * thickness) - 1.0)

    overlap_BA = 1.0 / (1j * qz) * (exp(1j * qz * thickness) - 1.0)
    overlap_BA += 1.0 / (-1j * qz) * (exp(-1j * qz * thickness) - 1.0)

    gisans = overlap[:, newaxis] * FT[newaxis, :]
    gisans_BA = overlap_BA[:, newaxis] * FT[newaxis, :]
    extent = [qy.min(), qy.max(), qz.min(), qz.max()]
    if show_plot == True:
        from pylab import imshow, figure, colorbar
        figure()
        imshow(log10(abs(gisans)**2),
               origin='lower',
               extent=extent,
               aspect='auto')
        colorbar()

        figure()
        imshow(log10(abs(gisans_BA)**2),
               origin='lower',
               extent=extent,
               aspect='auto')
        colorbar()
    return gisans, gisans_BA
Example #3
0
def calc_gisans(alpha_in, show_plot=True):

    #alpha_in = 0.25 # incoming beam angle

    kz_in_0 = 2*pi/wavelength * sin(alpha_in * pi/180.0)
    kz_out_0 = kz_in - qz

    wf_in = dwbaWavefunction(kz_in_0, SLDArray)
    wf_out = dwbaWavefunction(-kz_out_0, conj(SLDArray))
    
    kz_in_l = wf_in.kz_l
    kz_out_l = -wf_out.kz_l

    zs = cumsum(SLDArray[1:-1,1])
    dz = SLDArray[1:-1,1][:,newaxis]
    z_array = array(zs)[:,newaxis]

    qrt_inside =  kz_in_l[1] - kz_out_l[1]
    qtt_inside =  kz_in_l[1] + kz_out_l[1]
    qtr_inside = -kz_in_l[1] + kz_out_l[1]
    qrr_inside = -kz_in_l[1] - kz_out_l[1]
    
    
    # the overlap is the forward-moving amplitude c in psi_in multiplied by 
    # the forward-moving amplitude in the time-reversed psi_out, which
    # ends up being the backward-moving amplitude d in the non-time-reversed psi_out
    # (which is calculated by the wavefunction calculator)
    # ... and vice-verso for d and c in psi_in and psi_out
    overlap  = wf_out.d[1] * wf_in.c[1] / (1j * qtt_inside) * (exp(1j * qtt_inside * thickness) - 1.0)
    overlap += wf_out.c[1] * wf_in.d[1] / (1j * qrr_inside) * (exp(1j * qrr_inside * thickness) - 1.0)
    overlap += wf_out.d[1] * wf_in.d[1] / (1j * qtr_inside) * (exp(1j * qtr_inside * thickness) - 1.0)
    overlap += wf_out.c[1] * wf_in.c[1] / (1j * qrt_inside) * (exp(1j * qrt_inside * thickness) - 1.0)

    overlap_BA  = 1.0 / (1j * qz) * (exp(1j * qz * thickness) - 1.0) 
    overlap_BA += 1.0 / (-1j * qz) * (exp(-1j * qz * thickness) - 1.0) 


    gisans = overlap[:,newaxis] * FT[newaxis, :]
    gisans_BA = overlap_BA[:,newaxis] * FT[newaxis, :]
    extent = [qy.min(), qy.max(), qz.min(), qz.max()]
    if show_plot == True:
        from pylab import imshow, figure, colorbar
        figure()
        imshow(log10(abs(gisans)**2), origin='lower', extent=extent, aspect='auto')
        colorbar()
        
        figure()
        imshow(log10(abs(gisans_BA)**2), origin='lower', extent=extent, aspect='auto')
        colorbar()
    return gisans, gisans_BA
Example #4
0
    def calc_overlap(self):
        wf_in = dwbaWavefunction(self.kz_in, self.SLDArray)
        wf_out = dwbaWavefunction(
            -self.kz_out,
            self.SLDArray)  # solve 1d equation for time-reversed state
        self.wf_in = wf_in
        self.wf_out = wf_out

        kz_in_l = wf_in.kz_l  # inside the layers
        kz_out_l = -wf_out.kz_l  # inside the layers

        dz = self.SLDArray[1:-1, 1][:, newaxis, newaxis, newaxis]
        zs = cumsum(self.SLDArray[1:-1, 1]) - self.SLDArray[
            1, 1]  # start at zero with first layer
        z_array = array(zs)[:, newaxis, newaxis, newaxis]
        thickness = sum(self.SLDArray[1:-1, 1])

        qrt_inside = -kz_in_l[1:-1] - kz_out_l[1:-1]
        qtt_inside = -kz_in_l[1:-1] + kz_out_l[1:-1]
        qtr_inside = +kz_in_l[1:-1] + kz_out_l[1:-1]
        qrr_inside = +kz_in_l[1:-1] - kz_out_l[1:-1]

        # the overlap is the forward-moving amplitude c in psi_in multiplied by
        # the forward-moving amplitude in the time-reversed psi_out, which
        # ends up being the backward-moving amplitude d in the non-time-reversed psi_out
        # (which is calculated by the wavefunction calculator)
        # ... and vice-verso for d and c in psi_in and psi_out
        overlap = wf_out.c[1:-1] * wf_in.c[1:-1] / (1j * qtt_inside) * (
            exp(1j * qtt_inside * dz) - 1.0) * exp(1j * qtt_inside * z_array)
        overlap += wf_out.d[1:-1] * wf_in.d[1:-1] / (1j * qrr_inside) * (
            exp(1j * qrr_inside * dz) - 1.0) * exp(1j * qrr_inside * z_array)
        overlap += wf_out.c[1:-1] * wf_in.d[1:-1] / (1j * qtr_inside) * (
            exp(1j * qtr_inside * dz) - 1.0) * exp(1j * qtr_inside * z_array)
        overlap += wf_out.d[1:-1] * wf_in.c[1:-1] / (1j * qrt_inside) * (
            exp(1j * qrt_inside * dz) - 1.0) * exp(1j * qrt_inside * z_array)
        self.overlap = overlap
        return overlap
Example #5
0
    def calc_offspec_old(self, show_plot=True, add_specular=True):
        kz_in_0, kz_out_0 = QxQyQz_to_k(self.qx[:, newaxis, newaxis],
                                        self.qy[newaxis, :, newaxis],
                                        self.qz[newaxis,
                                                newaxis, :], self.wavelength)
        kzi_shape = kz_in_0.shape
        kzf_shape = kz_out_0.shape

        kz_out_neg = kz_out_0 < 0
        kz_in_neg = kz_in_0 < 0

        wf_in = dwbaWavefunction((kz_in_0), self.SLDArray)
        wf_out = dwbaWavefunction(
            (-kz_out_0),
            self.SLDArray)  # solve 1d equation for time-reversed state
        self.wf_in = wf_in
        self.wf_out = wf_out

        kz_in_l = wf_in.kz_l  # inside the layers
        #kz_in_l[:, kz_in_neg] *= -1.0
        kz_in_p_l = -kz_in_l  # prime
        kz_out_l = -wf_out.kz_l  # inside the layers
        #kz_out_l[:, kz_out_neg] *= -1.0
        kz_out_p_l = -kz_out_l  # kz_f_prime in the Sinha paper notation

        dz = self.SLDArray[1:-1, 1][:, newaxis, newaxis, newaxis]
        zs = cumsum(self.SLDArray[1:-1, 1]) - self.SLDArray[
            1, 1]  # start at zero with first layer
        z_array = array(zs)[:, newaxis, newaxis, newaxis]
        thickness = sum(self.SLDArray[1:-1, 1])

        qrt_inside = -kz_in_l[1:-1] - kz_out_l[1:-1]
        qtt_inside = -kz_in_l[1:-1] + kz_out_l[1:-1]
        qtr_inside = +kz_in_l[1:-1] + kz_out_l[1:-1]
        qrr_inside = +kz_in_l[1:-1] - kz_out_l[1:-1]

        self.qrt = qrt_inside
        self.qtt = qtt_inside
        self.qtr = qtr_inside
        self.qrr = qrr_inside

        # the overlap is the forward-moving amplitude c in psi_in multiplied by
        # the forward-moving amplitude in the time-reversed psi_out, which
        # ends up being the backward-moving amplitude d in the non-time-reversed psi_out
        # (which is calculated by the wavefunction calculator)
        # ... and vice-verso for d and c in psi_in and psi_out
        overlap = wf_out.c[1:-1] * wf_in.c[1:-1] / (1j * qtt_inside) * (
            exp(1j * qtt_inside * dz) - 1.0) * exp(1j * qtt_inside * z_array)
        overlap += wf_out.d[1:-1] * wf_in.d[1:-1] / (1j * qrr_inside) * (
            exp(1j * qrr_inside * dz) - 1.0) * exp(1j * qrr_inside * z_array)
        overlap += wf_out.c[1:-1] * wf_in.d[1:-1] / (1j * qtr_inside) * (
            exp(1j * qtr_inside * dz) - 1.0) * exp(1j * qtr_inside * z_array)
        overlap += wf_out.d[1:-1] * wf_in.c[1:-1] / (1j * qrt_inside) * (
            exp(1j * qrt_inside * dz) - 1.0) * exp(1j * qrt_inside * z_array)
        self.overlap = overlap
        overlap_BA = 1.0 / (1j * self.qz) * (exp(1j * self.qz * dz) -
                                             1.0) * exp(1j * self.qz * z_array)
        self.overlap_BA = overlap_BA
        offspec = sum(sum(overlap * array(self.dFTs)[:, :, :, newaxis],
                          axis=0),
                      axis=1)  # first over layers, then Qy
        # now need to add specular back in...
        if add_specular == True:
            specular = 2.0 * 1j * kz_in_0 * wf_in.r * self.Lx * self.Ly

            #specular *= 2*pi/self.Lx * normgauss(self.qx[:,newaxis,newaxis], FWHM_to_sigma(2.0*pi/self.Lx), x0=0.0)
            #specular *= 2*pi/self.Ly * normgauss(self.qy[newaxis,:,newaxis], FWHM_to_sigma(2.0*pi/self.Ly), x0=0.0)
            specular = sum(
                specular,
                axis=1) / kz_in_0.shape[1]  # sum over Qy, taking average
            self.specular = specular
            qx_min = find(abs(self.qx) == abs(self.qx).min())[0]
            offspec[qx_min] += specular[qx_min]

            self.R_tilde_o_sq = abs(offspec)**2 / (
                4.0 * self.Lx**2 * self.Ly**2 * kz_in_0[:, 0, :]**2)

        offspec *= 1.0 / (self.Lx * self.Ly)

        offspec_BA = sum(sum(overlap_BA * array(self.FTs)[:, :, :, newaxis],
                             axis=0),
                         axis=1)
        offspec_BA *= 1.0 / (self.Lx * self.Ly)
        extent = [self.qx.min(), self.qx.max(), self.qz.min(), self.qz.max()]
        self.offspec = offspec
        self.offspec_BA = offspec_BA

        if show_plot == True:
            from pylab import imshow, figure, colorbar
            zmax = max(
                log10(abs(offspec)**2).max(),
                log10(abs(offspec_BA)**2).max())
            zmin = min(
                log10(abs(offspec)**2).min(),
                log10(abs(offspec_BA)**2).min())
            figure()
            imshow(log10(self.R_tilde_o_sq.real).T,
                   origin='lower',
                   extent=extent,
                   aspect='auto')
            colorbar()

            figure()
            imshow(log10(abs(offspec)**2).T,
                   origin='lower',
                   extent=extent,
                   aspect='auto',
                   vmax=zmax,
                   vmin=zmin)
            colorbar()

            figure()
            imshow(log10(abs(offspec_BA)**2).T,
                   origin='lower',
                   extent=extent,
                   aspect='auto',
                   vmax=zmax,
                   vmin=zmin)
            colorbar()
Example #6
0
    def calc_gisans(self, alpha_in, show_plot=True, add_specular=False):
        k0 = 2 * pi / self.wavelength
        kz_in_0 = array([k0 * sin(alpha_in * pi / 180.0)], dtype=complex128)
        kx_in_0 = array([k0 * cos(alpha_in * pi / 180.0)], dtype=complex128)
        kz_out_0 = kz_in_0 - self.qz
        self.kz_out_0 = kz_out_0

        ky_out_0 = -self.qy
        kx_out_0 = sqrt(k0**2 - kz_out_0[newaxis, newaxis, :]**2 -
                        ky_out_0[newaxis, :, newaxis]**2)
        qx = kx_in_0 - kx_out_0
        self.qx_derived = qx

        kz_out_neg = kz_out_0 < 0
        kz_in_neg = kz_in_0 < 0

        wf_in = dwbaWavefunction((kz_in_0), self.SLDArray)
        wf_out = dwbaWavefunction(
            (-kz_out_0),
            self.SLDArray)  # solve 1d equation for time-reversed state
        self.wf_in = wf_in
        self.wf_out = wf_out

        kz_in_l = wf_in.kz_l  # inside the layers
        #kz_in_l[:, kz_in_neg] *= -1.0
        kz_in_p_l = -kz_in_l  # prime
        kz_out_l = -wf_out.kz_l  # inside the layers
        #kz_out_l[:, kz_out_neg] *= -1.0
        kz_out_p_l = -kz_out_l  # kz_f_prime in the Sinha paper notation

        dz = self.SLDArray[1:-1, 1][:, newaxis]
        zs = cumsum(self.SLDArray[1:-1, 1]) - self.SLDArray[
            1, 1]  # start at zero with first layer
        z_array = array(zs)[:, newaxis]
        thickness = sum(self.SLDArray[1:-1, 1])

        qrt_inside = -kz_in_l[1:-1] - kz_out_l[1:-1]
        qtt_inside = -kz_in_l[1:-1] + kz_out_l[1:-1]
        qtr_inside = +kz_in_l[1:-1] + kz_out_l[1:-1]
        qrr_inside = +kz_in_l[1:-1] - kz_out_l[1:-1]

        # the overlap is the forward-moving amplitude c in psi_in multiplied by
        # the forward-moving amplitude in the time-reversed psi_out, which
        # ends up being the backward-moving amplitude d in the non-time-reversed psi_out
        # (which is calculated by the wavefunction calculator)
        # ... and vice-verso for d and c in psi_in and psi_out
        overlap = wf_out.c[1:-1] * wf_in.c[1:-1] / (1j * qtt_inside) * (
            exp(1j * qtt_inside * dz) - 1.0) * exp(1j * qtt_inside * z_array)
        overlap += wf_out.d[1:-1] * wf_in.d[1:-1] / (1j * qrr_inside) * (
            exp(1j * qrr_inside * dz) - 1.0) * exp(1j * qrr_inside * z_array)
        overlap += wf_out.c[1:-1] * wf_in.d[1:-1] / (1j * qtr_inside) * (
            exp(1j * qtr_inside * dz) - 1.0) * exp(1j * qtr_inside * z_array)
        overlap += wf_out.d[1:-1] * wf_in.c[1:-1] / (1j * qrt_inside) * (
            exp(1j * qrt_inside * dz) - 1.0) * exp(1j * qrt_inside * z_array)
        self.overlap = overlap
        overlap_BA = 1.0 / (1j * self.qz) * (exp(1j * self.qz * dz) -
                                             1.0) * exp(1j * self.qz * z_array)
        self.overlap_BA = overlap_BA
        gisans = sum(sum(overlap * array(self.dFTs)[:, :, :, newaxis], axis=0),
                     axis=0)  # first over layers, then Qx
        # now if you want to add specular back in...
        if add_specular == True:
            specular = complex128(2) * pi / self.Lx * normgauss(
                qx, FWHM_to_sigma(2.0 * pi / self.Lx), x0=0.0)
            specular *= complex128(2) * pi / self.Ly * normgauss(
                self.qy[newaxis, :, newaxis],
                FWHM_to_sigma(2.0 * pi / self.Ly),
                x0=0.0)
            specular *= 2.0 * 1j * kz_in_0 * wf_in.r[
                newaxis, newaxis, :] * self.Lx * self.Ly
            specular = sum(
                specular,
                axis=0) / self.qx.shape[0]  # sum over Qx, taking average
            self.specular = specular
            gisans += specular

        gisans_BA = sum(sum(overlap_BA * array(self.FTs)[:, :, :, newaxis],
                            axis=0),
                        axis=0)
        extent = [self.qy.min(), self.qy.max(), self.qz.min(), self.qz.max()]

        self.alpha_in = alpha_in
        self.gisans = gisans
        self.gisans_BA = gisans_BA

        if show_plot == True:
            from pylab import imshow, figure, colorbar
            zmax = max(
                log10(abs(gisans)**2).max(),
                log10(abs(gisans_BA)**2).max())
            zmin = min(
                log10(abs(gisans)**2).min(),
                log10(abs(gisans_BA)**2).min())
            figure()
            imshow(log10(abs(gisans)**2).T,
                   origin='lower',
                   extent=extent,
                   aspect='auto',
                   vmax=zmax,
                   vmin=zmin)
            colorbar()

            figure()
            imshow(log10(abs(gisans_BA)**2).T,
                   origin='lower',
                   extent=extent,
                   aspect='auto',
                   vmax=zmax,
                   vmin=zmin)
            colorbar()
Example #7
0
    def calc_gisans(self, alpha_in, show_plot=True, add_specular=False):
        k0 = 2*pi/self.wavelength
        kz_in_0 = array([k0 * sin(alpha_in * pi/180.0)], dtype=complex128)
        kx_in_0 = array([k0 * cos(alpha_in * pi/180.0)], dtype=complex128)
        kz_out_0 = kz_in_0 - self.qz
        self.kz_out_0 = kz_out_0
        
        ky_out_0 = -self.qy
        kx_out_0 = sqrt(k0**2 - kz_out_0[newaxis,newaxis,:]**2 - ky_out_0[newaxis,:,newaxis]**2)
        qx = kx_in_0 - kx_out_0
        self.qx_derived = qx

        kz_out_neg = kz_out_0 < 0
        kz_in_neg = kz_in_0 < 0
        
        wf_in = dwbaWavefunction((kz_in_0), self.SLDArray)
        wf_out = dwbaWavefunction((-kz_out_0), self.SLDArray) # solve 1d equation for time-reversed state
        self.wf_in = wf_in
        self.wf_out = wf_out
        
        kz_in_l = wf_in.kz_l # inside the layers
        #kz_in_l[:, kz_in_neg] *= -1.0     
        kz_in_p_l = -kz_in_l # prime
        kz_out_l = -wf_out.kz_l # inside the layers
        #kz_out_l[:, kz_out_neg] *= -1.0
        kz_out_p_l = -kz_out_l    # kz_f_prime in the Sinha paper notation
        
        dz = self.SLDArray[1:-1,1][:,newaxis]
        zs = cumsum(self.SLDArray[1:-1,1]) - self.SLDArray[1,1] # start at zero with first layer
        z_array = array(zs)[:,newaxis]
        thickness = sum(self.SLDArray[1:-1,1])

        qrt_inside = -kz_in_l[1:-1] - kz_out_l[1:-1]
        qtt_inside = -kz_in_l[1:-1] + kz_out_l[1:-1]
        qtr_inside = +kz_in_l[1:-1] + kz_out_l[1:-1]
        qrr_inside = +kz_in_l[1:-1] - kz_out_l[1:-1]
               
        # the overlap is the forward-moving amplitude c in psi_in multiplied by 
        # the forward-moving amplitude in the time-reversed psi_out, which
        # ends up being the backward-moving amplitude d in the non-time-reversed psi_out
        # (which is calculated by the wavefunction calculator)
        # ... and vice-verso for d and c in psi_in and psi_out
        overlap  = wf_out.c[1:-1] * wf_in.c[1:-1] / (1j * qtt_inside) * (exp(1j * qtt_inside * dz) - 1.0)*exp(1j*qtt_inside*z_array)
        overlap += wf_out.d[1:-1] * wf_in.d[1:-1] / (1j * qrr_inside) * (exp(1j * qrr_inside * dz) - 1.0)*exp(1j*qrr_inside*z_array)
        overlap += wf_out.c[1:-1] * wf_in.d[1:-1] / (1j * qtr_inside) * (exp(1j * qtr_inside * dz) - 1.0)*exp(1j*qtr_inside*z_array)
        overlap += wf_out.d[1:-1] * wf_in.c[1:-1] / (1j * qrt_inside) * (exp(1j * qrt_inside * dz) - 1.0)*exp(1j*qrt_inside*z_array)
        self.overlap = overlap
        overlap_BA  = 1.0 / (1j * self.qz) * (exp(1j * self.qz * dz) - 1.0) * exp(1j*self.qz*z_array)
        self.overlap_BA = overlap_BA
        gisans = sum(sum(overlap * array(self.dFTs)[:,:,:,newaxis], axis=0), axis=0) # first over layers, then Qx
        # now if you want to add specular back in...
        if add_specular == True:
            specular = complex128(2)*pi/self.Lx * normgauss(qx, FWHM_to_sigma(2.0*pi/self.Lx), x0=0.0)
            specular *= complex128(2)*pi/self.Ly * normgauss(self.qy[newaxis,:,newaxis], FWHM_to_sigma(2.0*pi/self.Ly), x0=0.0)
            specular *= 2.0*1j*kz_in_0*wf_in.r[newaxis,newaxis,:]*self.Lx*self.Ly        
            specular = sum(specular, axis=0)/self.qx.shape[0] # sum over Qx, taking average
            self.specular = specular
            gisans += specular
        
        gisans_BA = sum(sum(overlap_BA * array(self.FTs)[:,:,:,newaxis], axis=0), axis=0) 
        extent = [self.qy.min(), self.qy.max(), self.qz.min(), self.qz.max()]
        
        self.alpha_in = alpha_in
        self.gisans = gisans
        self.gisans_BA = gisans_BA
        
        if show_plot == True:
            from pylab import imshow, figure, colorbar
            zmax = max(log10(abs(gisans)**2).max(), log10(abs(gisans_BA)**2).max())
            zmin = min(log10(abs(gisans)**2).min(), log10(abs(gisans_BA)**2).min())
            figure()
            imshow(log10(abs(gisans)**2).T, origin='lower', extent=extent, aspect='auto', vmax=zmax, vmin=zmin)
            colorbar()
            
            figure()
            imshow(log10(abs(gisans_BA)**2).T, origin='lower', extent=extent, aspect='auto', vmax=zmax, vmin=zmin)
            colorbar()
Example #8
0
    def calc_offspec_old(self, show_plot=True, add_specular=True):
        kz_in_0, kz_out_0 = QxQyQz_to_k(self.qx[:,newaxis,newaxis],self.qy[newaxis,:,newaxis],self.qz[newaxis,newaxis,:],self.wavelength)
        kzi_shape = kz_in_0.shape
        kzf_shape = kz_out_0.shape
        
        kz_out_neg = kz_out_0 < 0
        kz_in_neg = kz_in_0 < 0
        
        wf_in = dwbaWavefunction((kz_in_0), self.SLDArray)
        wf_out = dwbaWavefunction((-kz_out_0), self.SLDArray) # solve 1d equation for time-reversed state
        self.wf_in = wf_in
        self.wf_out = wf_out
        
        kz_in_l = wf_in.kz_l # inside the layers
        #kz_in_l[:, kz_in_neg] *= -1.0     
        kz_in_p_l = -kz_in_l # prime
        kz_out_l = -wf_out.kz_l # inside the layers
        #kz_out_l[:, kz_out_neg] *= -1.0
        kz_out_p_l = -kz_out_l    # kz_f_prime in the Sinha paper notation

        dz = self.SLDArray[1:-1,1][:,newaxis,newaxis,newaxis]
        zs = cumsum(self.SLDArray[1:-1,1]) - self.SLDArray[1,1] # start at zero with first layer
        z_array = array(zs)[:,newaxis,newaxis,newaxis]
        thickness = sum(self.SLDArray[1:-1,1])

        qrt_inside = -kz_in_l[1:-1] - kz_out_l[1:-1]
        qtt_inside = -kz_in_l[1:-1] + kz_out_l[1:-1]
        qtr_inside = +kz_in_l[1:-1] + kz_out_l[1:-1]
        qrr_inside = +kz_in_l[1:-1] - kz_out_l[1:-1]
        
        self.qrt = qrt_inside
        self.qtt = qtt_inside
        self.qtr = qtr_inside
        self.qrr = qrr_inside
               
        # the overlap is the forward-moving amplitude c in psi_in multiplied by 
        # the forward-moving amplitude in the time-reversed psi_out, which
        # ends up being the backward-moving amplitude d in the non-time-reversed psi_out
        # (which is calculated by the wavefunction calculator)
        # ... and vice-verso for d and c in psi_in and psi_out
        overlap  = wf_out.c[1:-1] * wf_in.c[1:-1] / (1j * qtt_inside) * (exp(1j * qtt_inside * dz) - 1.0)*exp(1j*qtt_inside*z_array)
        overlap += wf_out.d[1:-1] * wf_in.d[1:-1] / (1j * qrr_inside) * (exp(1j * qrr_inside * dz) - 1.0)*exp(1j*qrr_inside*z_array)
        overlap += wf_out.c[1:-1] * wf_in.d[1:-1] / (1j * qtr_inside) * (exp(1j * qtr_inside * dz) - 1.0)*exp(1j*qtr_inside*z_array)
        overlap += wf_out.d[1:-1] * wf_in.c[1:-1] / (1j * qrt_inside) * (exp(1j * qrt_inside * dz) - 1.0)*exp(1j*qrt_inside*z_array)
        self.overlap = overlap
        overlap_BA  = 1.0 / (1j * self.qz) * (exp(1j * self.qz * dz) - 1.0) * exp(1j*self.qz*z_array)
        self.overlap_BA = overlap_BA
        offspec = sum(sum(overlap * array(self.dFTs)[:,:,:,newaxis], axis=0), axis=1) # first over layers, then Qy
        # now need to add specular back in...
        if add_specular == True:
            specular = 2.0*1j*kz_in_0*wf_in.r*self.Lx*self.Ly
        
            #specular *= 2*pi/self.Lx * normgauss(self.qx[:,newaxis,newaxis], FWHM_to_sigma(2.0*pi/self.Lx), x0=0.0)
            #specular *= 2*pi/self.Ly * normgauss(self.qy[newaxis,:,newaxis], FWHM_to_sigma(2.0*pi/self.Ly), x0=0.0)
            specular = sum(specular, axis=1)/kz_in_0.shape[1] # sum over Qy, taking average
            self.specular = specular
            qx_min = find(abs(self.qx) == abs(self.qx).min())[0]
            offspec[qx_min] += specular[qx_min]
        
            self.R_tilde_o_sq = abs(offspec)**2 / (4.0 * self.Lx**2 * self.Ly**2 * kz_in_0[:,0,:]**2)
        
        offspec *= 1.0/(self.Lx * self.Ly)

        offspec_BA = sum(sum(overlap_BA * array(self.FTs)[:,:,:,newaxis], axis=0), axis=1)
        offspec_BA *= 1.0/(self.Lx * self.Ly)
        extent = [self.qx.min(), self.qx.max(), self.qz.min(), self.qz.max()]
        self.offspec = offspec
        self.offspec_BA = offspec_BA
        
        if show_plot == True:
            from pylab import imshow, figure, colorbar
            zmax = max(log10(abs(offspec)**2).max(), log10(abs(offspec_BA)**2).max())
            zmin = min(log10(abs(offspec)**2).min(), log10(abs(offspec_BA)**2).min())
            figure()
            imshow(log10(self.R_tilde_o_sq.real).T, origin='lower', extent=extent, aspect='auto')
            colorbar()
            
            figure()
            imshow(log10(abs(offspec)**2).T, origin='lower', extent=extent, aspect='auto', vmax=zmax, vmin=zmin)
            colorbar()
            
            figure()
            imshow(log10(abs(offspec_BA)**2).T, origin='lower', extent=extent, aspect='auto', vmax=zmax, vmin=zmin)
            colorbar()