diff --git a/tests/bottom_reference/generate.py b/tests/bottom_reference/generate.py index 035a856..80ff031 100644 --- a/tests/bottom_reference/generate.py +++ b/tests/bottom_reference/generate.py @@ -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]]) diff --git a/tests/bottom_reference/test_reconstruction.py b/tests/bottom_reference/test_reconstruction.py index 7d93d28..8b29273 100644 --- a/tests/bottom_reference/test_reconstruction.py +++ b/tests/bottom_reference/test_reconstruction.py @@ -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 +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) @@ -13,19 +18,19 @@ 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) @@ -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() diff --git a/tests/rough_reference/generate.py b/tests/rough_reference/generate.py index e88dc1a..4edf03b 100644 --- a/tests/rough_reference/generate.py +++ b/tests/rough_reference/generate.py @@ -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") diff --git a/tests/rough_reference/test_reconstruction.py b/tests/rough_reference/test_reconstruction.py index 1f4bbb8..d60c8e7 100644 --- a/tests/rough_reference/test_reconstruction.py +++ b/tests/rough_reference/test_reconstruction.py @@ -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 @@ -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) @@ -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() diff --git a/tests/top_reference/test_reconstruction.py b/tests/top_reference/test_reconstruction.py index 0ddc0df..b4e2a9b 100644 --- a/tests/top_reference/test_reconstruction.py +++ b/tests/top_reference/test_reconstruction.py @@ -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) @@ -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()