Ejemplo n.º 1
0
 def calc_offspec_BA(self, show_plot=True, add_specular=True):
     overlap = self.calc_overlap_BA()
     offspec = sum(sum(overlap * array(self.dFTs)[:,:,:,newaxis], axis=0), axis=1) # first over layers, then Qy
     
     if add_specular == True:
         specular = ones((self.qx.shape[0], self.qy.shape[1], self.qz.shape[2]), dtype=complex128)
         specular *= complex128(2)*pi/self.Lx * normgauss(self.qx, FWHM_to_sigma(2.0*pi/self.Lx), x0=0.0)
         specular *= complex128(2)*pi/self.Ly * normgauss(self.qy, FWHM_to_sigma(2.0*pi/self.Ly), x0=0.0)
         specular *= 2.0*1j*self.kz_in*self.wf_in.r*self.Lx*self.Ly        
         specular = sum(specular, axis=1)/self.qy.shape[1] # sum over Qy, taking average
         self.specular = specular
         offspec += specular
     self.offspec_BA = offspec
     
     if show_plot == True:
         self.plot_offspec_BA()
Ejemplo n.º 2
0
 def calc_gisans(self, alpha_in=None, show_plot=True, add_specular=False):
     if alpha_in is not None:
         self.update_Qs(alpha_in)
     overlap = self.calc_overlap()
     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 = ones((self.qx.shape[0], self.qy.shape[1], self.qz.shape[2]), dtype=complex128)
         specular *= complex128(2)*pi/self.Lx * normgauss(self.qx, FWHM_to_sigma(2.0*pi/self.Lx), x0=0.0)
         specular *= complex128(2)*pi/self.Ly * normgauss(self.qy, FWHM_to_sigma(2.0*pi/self.Ly), x0=0.0)
         specular *= 2.0*1j*self.kz_in*self.wf_in.r*self.Lx*self.Ly        
         specular = sum(specular, axis=0)/self.qx.shape[0] # sum over Qx, taking average
         self.specular = specular
         gisans += specular
     self.gisans = gisans
     if show_plot == True:
         self.plot_gisans()            
Ejemplo n.º 3
0
    def calc_offspec_BA(self, show_plot=True, add_specular=True):
        overlap = self.calc_overlap_BA()
        offspec = sum(sum(overlap * array(self.dFTs)[:, :, :, newaxis],
                          axis=0),
                      axis=1)  # first over layers, then Qy

        if add_specular == True:
            specular = ones(
                (self.qx.shape[0], self.qy.shape[1], self.qz.shape[2]),
                dtype=complex128)
            specular *= complex128(2) * pi / self.Lx * normgauss(
                self.qx, FWHM_to_sigma(2.0 * pi / self.Lx), x0=0.0)
            specular *= complex128(2) * pi / self.Ly * normgauss(
                self.qy, FWHM_to_sigma(2.0 * pi / self.Ly), x0=0.0)
            specular *= 2.0 * 1j * self.kz_in * self.wf_in.r * self.Lx * self.Ly
            specular = sum(
                specular,
                axis=1) / self.qy.shape[1]  # sum over Qy, taking average
            self.specular = specular
            offspec += specular
        self.offspec_BA = offspec

        if show_plot == True:
            self.plot_offspec_BA()
Ejemplo n.º 4
0
 def calc_gisans(self, alpha_in=None, show_plot=True, add_specular=False):
     if alpha_in is not None:
         self.update_Qs(alpha_in)
     overlap = self.calc_overlap()
     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 = ones(
             (self.qx.shape[0], self.qy.shape[1], self.qz.shape[2]),
             dtype=complex128)
         specular *= complex128(2) * pi / self.Lx * normgauss(
             self.qx, FWHM_to_sigma(2.0 * pi / self.Lx), x0=0.0)
         specular *= complex128(2) * pi / self.Ly * normgauss(
             self.qy, FWHM_to_sigma(2.0 * pi / self.Ly), x0=0.0)
         specular *= 2.0 * 1j * self.kz_in * self.wf_in.r * self.Lx * self.Ly
         specular = sum(
             specular,
             axis=0) / self.qx.shape[0]  # sum over Qx, taking average
         self.specular = specular
         gisans += specular
     self.gisans = gisans
     if show_plot == True:
         self.plot_gisans()
Ejemplo n.º 5
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()
Ejemplo n.º 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()