Ejemplo n.º 1
0
    def run(self, constrain):

        self.setup()

        rec = PotentialReconstruction(
            self.thickness + self.offset, self.precision,
            cutoff=self.pot_cutoff)
        reflcalc = ReflectionCalculation(
            None, 0, self.thickness + self.offset, 0.1)

        # plot the exact potential/refl/ for comparison
        self._plot_exact()

        # split the fourier transform up into two parts
        # f1 has the changing input
        # f2 has the non-changing input
        # since f2 contains much more data in general, we can save a lot of computation by
        # caching f2 and just
        # computing f1 each time.

        f1_index = slice(None, self.start_end[1]+1)
        f2_index = slice(self.start_end[1]+1, None)
        # self.real, self.imag contain the reflection coefficient
        f1 = FourierTransform(self.k_space[f1_index],
                              self.real[f1_index], self.imag[f1_index])
        f2 = FourierTransform(self.k_space[f2_index],
                              self.real[f2_index], self.imag[f2_index])

        if self.use_only_real_part:
            f1.method = f1.cosine_transform
            f2.method = f2.cosine_transform

        transform = UpdateableFourierTransform(f1, f2)


        # TODO: change the class name
        # Reconstruct the reflection using the fourier transform at  k =
        # k_interpolation_range (the low k range)
        # rec is used to reconstruct the potential
        # reflcalc is used to calculate the reflection coefficient
        # the constrain function constrains the potential
        interpolation = ReflectivityAmplitudeInterpolation(
            transform, self.k_interpolation_range, rec, reflcalc, constrain)

        interpolation.set_hook(self._plot_hook)
        if self.diagnostic_session:
            interpolation.set_hook(self._diagnostic_hook)

        solution = interpolation.interpolate(self.iterations, tolerance=self.tolerance)

        if self.plot_potential:
            self._potential_axes.legend()
        if self.plot_phase:
            self._phase_axes.legend()
        if self.plot_reflectivity:
            self._reflectivity_axes.legend()
        if self.show_plot:
            pylab.show()

        return solution
    #data[(x_space >= 66) & (x_space <= 77)] = 7e-6
    data[(x_space >= 80) & (x_space <= 405)] = 4.662e-6
    #data[(x_space >= 100) & (x_space <= 400)] = 8e-6


    interpolation = scipy.interpolate.interp1d(x_space, data, fill_value=(0, 0), bounds_error=False)
    return interpolation


legends = []
if plot_potential:
    transform = FourierTransform(k_space, Refl[0], Refl[1], offset)
    # cosine transform doesnt use imaginary part of the reflectivity amplitude
    #transform.method = transform.cosine_transform

    rec = PotentialReconstruction(end, precision, pot_cutoff)

    potential, x_space = rec.reconstruct(transform, shift=offset/2)
    reference_potential = potential

    pylab.plot(exact_potential[0], exact_potential[1])
    pylab.plot(plot_potential_space, potential(plot_potential_space), '-', color='black')
    #pylab.axvline(x_space[pot_cutoff])
    pylab.ylim(-1e-6, 1e-5)
    legends.append('Exact SLD')
    legends.append("Reconstructed SLD (exact)")


if plot_reflectivity:
    pylab.plot(2 * k_space, real ** 2 + imag ** 2)
    pylab.yscale('log')
Ejemplo n.º 3
0
    def _plot_exact(self):

        rec = PotentialReconstruction(self.thickness + self.offset, self.precision,
                                      cutoff=self.pot_cutoff)

        transform = FourierTransform(self.k_space, self.reflectivity.real,
                                     self.reflectivity.imag)
        potential = rec.reconstruct(transform)

        num_plots = int(self.plot_potential) + int(self.plot_phase) + int(self.plot_reflectivity)
        plot_k = 0
        if self.plot_potential:
            plot_k += 1
            self._potential_axes = pylab.subplot(num_plots, 1, plot_k)

            # cosine transform doesnt use imaginary part of the reflectivity amplitude
            # transform.method = transform.cosine_transform

            self.reference_potential = potential

            self.store_data(zip(self.plot_potential_space, self.ideal_potential(
                self.plot_potential_space)),'pot_exact', 'potential')

            self.store_data(zip(self.plot_potential_space, potential(
                self.plot_potential_space)), 'pot_ideal', 'potential')

            ax = self._potential_axes
            ax.plot(self.plot_potential_space,
                    self.ideal_potential(self.plot_potential_space),
                    label='Reconstructed SLD (exact)')
            ax.plot(self.plot_potential_space, potential(self.plot_potential_space), '-',
                    color='black', label='Exact SLD')
            ax.set_ylim(-1e-6, 1e-5)

        if self.plot_phase:
            plot_k += 1
            self._phase_axes = pylab.subplot(num_plots, 1, plot_k)

            ax = self._phase_axes
            if self.plot_phase_angle:
                ax.plot(self.k_space, numpy.angle(self.reflectivity),
                        label="Exact phase")
            else:
                ax.plot(self.k_space, (self.reflectivity.real * self.k_space ** 2),
                        label="Exact reflectivity (real)")

            self.store_data(zip(self.k_space, self.reflectivity.real, self.reflectivity.imag,
                                self.reflectivity.real * self.k_space ** 2,
                                self.reflectivity.imag * self.k_space ** 2),
                            'phase_exact', 'phase')

        if self.plot_reflectivity:
            plot_k += 1
            self._reflectivity_axes = pylab.subplot(num_plots, 1, plot_k)

            refl_ideal = self.reflcalc.refl(2 * self.k_space)

            self.store_data(zip(2 * self.k_space, abs(self.reflectivity) ** 2), 'refl_exact',
                            'reflectivity')
            self.store_data(zip(2 * self.k_space, abs(refl_ideal) ** 2), 'refl_ideal',
                            'reflectivity')

            ax = self._reflectivity_axes
            ax.plot(2 * self.k_space,
                    self.reflectivity.real ** 2 + self.reflectivity.imag ** 2,
                    label='Exact reflectivity (w/o noise)')
            ax.plot(2 * self.k_space, self.real ** 2 + self.imag ** 2, '+',
                    label='Exact reflectivity (w noise)')
            ax.plot(2 * self.k_space, refl_ideal.real ** 2 + refl_ideal.imag ** 2,
                    label='Ideal Reflectivity')

            ax.set_yscale('log')
Ejemplo n.º 4
0
precision = 4
cutoff = 2
q_max = 1.0

x_space = linspace(0, thickness + shift, 10 * (thickness + shift) + 1)
for q_max in [0.5, 1.0, 5.0]:
    q_extrapolation = q_max + 0.1
    k_space = linspace(0, q_max / 2, int(1000 * q_max) + 1)
    k_extrapolation_space = linspace(q_max / 2, q_extrapolation,
                                     (q_extrapolation - q_max) * 1000 + 1)

    potential = load_potential("profile.dat")
    potential = shift_potential(potential, shift)

    reconstruction = PotentialReconstruction(shift + thickness,
                                             precision,
                                             cutoff=cutoff)
    reflection_calc = ReflectionCalculation(lambda x: 0, 0, shift + thickness)

    reflection_calc.set_potential(potential)

    refl = reflection_calc.refl(2 * k_space)
    refl_extrapolation = reflection_calc.refl(2 * k_extrapolation_space)
    #refl_extrapolation = (refl_extrapolation * exp(-1j * angle(refl_extrapolation))).real

    transform_left = FourierTransform(k_space, refl.real, refl.imag)
    transform_extrapolation = FourierTransform(k_extrapolation_space,
                                               refl_extrapolation.real,
                                               refl_extrapolation.imag)

    transform = UpdateableFourierTransform(transform_extrapolation,
Ejemplo n.º 5
0
thickness = 100
precision = 4
cutoff = 2
q_max = 0.5
q_extrapolation = 0.6

x_space = linspace(0, thickness + shift, 10 * (thickness + shift) + 1)
k_space = linspace(0, q_max / 2, int(1000 * q_max) + 1)
k_extrapolation_space = linspace(q_max / 2, q_extrapolation,
                                 (q_extrapolation - q_max) * 1000 + 1)

potential = load_potential("profile.dat")
potential = shift_potential(potential, shift)

reconstruction = PotentialReconstruction(shift + thickness,
                                         precision,
                                         cutoff=cutoff)
reflection_calc = ReflectionCalculation(lambda x: 0, 0, shift + thickness)

reflection_calc.set_potential(potential)

refl = reflection_calc.refl(2 * k_space)
refl_extrapolation = reflection_calc.refl(2 * k_extrapolation_space)
#refl_extrapolation = (refl_extrapolation * exp(-1j * angle(refl_extrapolation))).real

transform_left = FourierTransform(k_space, refl.real, refl.imag)
transform_extrapolation = FourierTransform(k_extrapolation_space,
                                           refl_extrapolation.real,
                                           refl_extrapolation.imag)

transform = UpdateableFourierTransform(transform_extrapolation, transform_left)
Ejemplo n.º 6
0
# Load the exact reflection coefficient
# exact_amplitude = np.loadtxt('sim/reflection.dat').T

pylab.plot(q, 1e4 * r.real * q**2)
pylab.plot(q, 1e4 * r.imag * q**2)

if var.number_measurements == 2:
    var.plot_r_branches()
    var.plot_r_choose(1)
    pylab.show()

    R, _, _ = var.choose(1)

if var.number_measurements > 2:
    var.plot_phase()
    pylab.show()

    R = var.R

from dinv.glm import PotentialReconstruction
from dinv.fourier import FourierTransform

fourier = FourierTransform(var.Q / 2.0, R.real, R.imag, offset=-50)
# fourier.method = fourier.cosine_transform
rec = PotentialReconstruction(250, 4, cutoff=2)
pot = rec.reconstruct(fourier)
x_space = np.linspace(0, 250, 1001)

pylab.plot(x_space, [pot(x) for x in x_space])
pylab.show()