Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Kienzle committed Feb 26, 2020
1 parent faabc98 commit 0f3d9b3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion tests/bottom_reference/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

# Calculate the exact reflection coefficient (not the reflectivity!)
ampl = models[3].amplitude()
numpy.savetxt("sim/reflection.dat", zip(ampl[0], ampl[1].real, -ampl[1].imag))
np.savetxt("sim/reflection.dat", zip(ampl[0], ampl[1].real, -ampl[1].imag))

# plot the reflectivity
problem = MultiFitProblem([models[0], models[1], models[2]])
21 changes: 13 additions & 8 deletions tests/bottom_reference/test_reconstruction.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
from os.path import dirname, realpath, join as joinpath
import pylab
import numpy
import numpy as np

from refl1d.names import *

from direfl.api.reference_layer import BottomReferenceVariation
from direfl.api.sld_profile import ConcatSLDProfile, ConstantSLDProfile, FunctionSLDProfile

ROOT = dirname(realpath(__file__))
def getdata(filename):
return joinpath(ROOT, "sim", filename)

# SLD: Si: ~2.1 (2.1 is set precisely in generate.py)
# Air: 0
var = BottomReferenceVariation(0e-6, 2.1e-6)

sld = FunctionSLDProfile(lambda x: 4e-6 if x < 15 else 5e-6, [0, 30], 15)
sld_concat = ConcatSLDProfile([ConstantSLDProfile(5.0e-6, 15), ConstantSLDProfile(5.5e-6, 35)])

var.load('sim/generate-1-refl.datA', sld)
var.load('sim/generate-2-refl.datA', sld_concat)
# var.load('sim/generate-3-refl.datA', ConstantSLDProfile(6.0e-6, 70))
var.load(getdata("generate-1-refl.datA"), sld)
var.load(getdata("generate-2-refl.datA"), sld_concat)
# var.load(getdata("generate-3-refl.datA"), ConstantSLDProfile(6.0e-6, 70))
var.run()

def load_reflection(file):
q, real, imag = numpy.loadtxt(file).T
q, real, imag = np.loadtxt(file).T
return q, real + 1j * imag

q, r = load_reflection("sim/reflection.dat")
q, r = load_reflection(getdata("reflection.dat"))

# Load the exact reflection coefficient
# exact_amplitude = numpy.loadtxt('sim/reflection.dat').T
# exact_amplitude = np.loadtxt('sim/reflection.dat').T

pylab.plot(q, 1e4 * r.real * q ** 2)
pylab.plot(q, 1e4 * r.imag * q ** 2)
Expand All @@ -50,7 +55,7 @@ def load_reflection(file):
# fourier.method = fourier.cosine_transform
rec = PotentialReconstruction(250, 4, cutoff=2)
pot = rec.reconstruct(fourier)
x_space = numpy.linspace(0, 250, 1001)
x_space = np.linspace(0, 250, 1001)

pylab.plot(x_space, [pot(x) for x in x_space])
pylab.show()
2 changes: 1 addition & 1 deletion tests/rough_reference/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Call via: refl1d generate.py --store=sim --steps=0 --simulate --noise=1e-10
data = load4("sim/generate-1-refl.datA", name="data", columns="Q dQ R dR", radiation="neutron",
L=4, dL=1e-9, simulation_range=numpy.linspace(0, 1, 5001))
L=4, dL=1e-9, simulation_range=np.linspace(0, 1, 5001))

Si = Material("Si", name="Si")
Cu = Material("Cu")
Expand Down
31 changes: 18 additions & 13 deletions tests/rough_reference/test_reconstruction.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from os.path import dirname, realpath, join as joinpath
import pylab
import numpy
import numpy as np

from refl1d.names import *

from direfl.api.reference_layer import BottomReferenceVariation
from direfl.api.sld_profile import ConcatSLDProfile, ConstantSLDProfile, FunctionSLDProfile, MircoSlabSLDProfile

ROOT = dirname(realpath(__file__))
def getdata(filename):
return joinpath(ROOT, "sim", filename)

# SLD: Si: ~2.1 (2.1 is set precisely in generate.py)
# Air: 0
b = 1.5e-6
Expand All @@ -26,26 +31,26 @@
t6 = MircoSlabSLDProfile([0, 30.1], [7], [b, 5e-6], 4)


var.load('sim/generate-1-refl.datA', ConcatSLDProfile([t1, t5]))
#var.load('sim/generate-1-refl.datA', t1)
#var.load('sim/generate-2-refl.datA', t2)
#var.load('sim/generate-3-refl.datA', t3)
#var.load('sim/generate-2-refl.datA', ConcatSLDProfile([t2, t5]))
#var.load('sim/generate-3-refl.datA', ConcatSLDProfile([t3, t5]))
var.load('sim/generate-4-refl.datA', ConcatSLDProfile([t4, t5]))
var.load('sim/generate-5-refl.datA', t6)
var.load(getdata("generate-1-refl.datA"), ConcatSLDProfile([t1, t5]))
#var.load(getdata("generate-1-refl.datA"), t1)
#var.load(getdata("generate-2-refl.datA"), t2)
#var.load(getdata("generate-3-refl.datA"), t3)
#var.load(getdata("generate-2-refl.datA"), ConcatSLDProfile([t2, t5]))
#var.load(getdata("generate-3-refl.datA"), ConcatSLDProfile([t3, t5]))
var.load(getdata("generate-4-refl.datA"), ConcatSLDProfile([t4, t5]))
var.load(getdata("generate-5-refl.datA"), t6)
var.run()


def load_reflection(file):
q, real, imag = numpy.loadtxt(file).T
q, real, imag = np.loadtxt(file).T
return q, real + 1j * imag


q, r = load_reflection("sim/reflection.dat")
q, r = load_reflection(getdata("reflection.dat"))

# Load the exact reflection coefficient
# exact_amplitude = numpy.loadtxt('sim/reflection.dat').T
# exact_amplitude = np.loadtxt('sim/reflection.dat').T

pylab.plot(q, 1e4 * r.real * q ** 2)
pylab.plot(q, 1e4 * r.imag * q ** 2)
Expand All @@ -72,7 +77,7 @@ def load_reflection(file):
# fourier.method = fourier.cosine_transform
rec = PotentialReconstruction(250, 4, cutoff=2)
pot = rec.reconstruct(fourier)
x_space = numpy.linspace(0, 250, 1001)
x_space = np.linspace(0, 250, 1001)

pylab.plot(x_space, [pot(x) for x in x_space])
pylab.show()
23 changes: 14 additions & 9 deletions tests/top_reference/test_reconstruction.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
from os.path import dirname, realpath, join as joinpath
import pylab
import numpy
import numpy as np

from refl1d.names import *

from direfl.api.reference_layer import TopReferenceVariation
from direfl.api.sld_profile import ConcatSLDProfile, ConstantSLDProfile, FunctionSLDProfile

ROOT = dirname(realpath(__file__))
def getdata(filename):
return joinpath(ROOT, "sim", filename)

# SLD: Si: ~2.1 (2.1 is set precisely in generate.py)
# Air: 0
var = TopReferenceVariation(0e-6, 1.5e-6)

var.load('sim/generate-1-refl.datA', ConstantSLDProfile(4e-6, 0))
var.load('sim/generate-2-refl.datA', ConstantSLDProfile(4e-6, 35))
var.load('sim/generate-3-refl.datA', ConstantSLDProfile(4e-6, 36))
var.load('sim/generate-4-refl.datA', ConstantSLDProfile(5.64e-6, 38.35))
var.load(getdata("generate-1-refl.datA"), ConstantSLDProfile(4e-6, 0))
var.load(getdata("generate-2-refl.datA"), ConstantSLDProfile(4e-6, 35))
var.load(getdata("generate-3-refl.datA"), ConstantSLDProfile(4e-6, 36))
var.load(getdata("generate-4-refl.datA"), ConstantSLDProfile(5.64e-6, 38.35))
var.run()


def load_reflection(file):
q, real, imag = numpy.loadtxt(file).T
q, real, imag = np.loadtxt(file).T
return q, real + 1j * imag


q, r = load_reflection("sim/reflection.dat")
q, r = load_reflection(getdata("reflection.dat"))

# Load the exact reflection coefficient
# exact_amplitude = numpy.loadtxt('sim/reflection.dat').T
# exact_amplitude = np.loadtxt('sim/reflection.dat').T

pylab.plot(q, 1e4 * r.real * q ** 2)
pylab.plot(q, 1e4 * r.imag * q ** 2)
Expand Down Expand Up @@ -55,7 +60,7 @@ def load_reflection(file):
# fourier.method = fourier.cosine_transform
rec = PotentialReconstruction(400, 4, cutoff=2)
pot = rec.reconstruct(fourier)
x_space = numpy.linspace(0, 400, 1001)
x_space = np.linspace(0, 400, 1001)

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

0 comments on commit 0f3d9b3

Please sign in to comment.