Skip to content

Commit

Permalink
harmonize test plots
Browse files Browse the repository at this point in the history
all detuning angles in µrad and y-axes as reflectivity or transmittivity
  • Loading branch information
kklmn committed Nov 8, 2024
1 parent 47940fe commit 1cde1bd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 38 deletions.
46 changes: 24 additions & 22 deletions tests/raycing/test_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,32 +283,32 @@ def for_one_alpha(crystal, alphaDeg, hkl):
geomPrefix = 'l'
if geom.endswith('transmitted'):
geomPrefix += 't'
ax.set_title(r'{0} Si{1}, $\alpha={2:.1f}^\circ${3}'.format(
ax.set_title(r'{0} Si{1}, α={2:.0f}°{3}'.format(
geom, hkl, alphaDeg, tt), fontsize=14)

path = os.path.join('', 'XOP-RockingCurves') + os.sep
x, R2s = np.loadtxt("{0}{1}Si{2}_{3}_{4:-.0f}_s.xc.gz".format(path,
geomPrefix, hkl, tname, alphaDeg), unpack=True)
p1, = ax.plot(x, R2s, '-C0', label='s XCrystal')
p1, = ax.plot(x/convFactor*1e6, R2s, '-C0', label='s XCrystal')
x, R2p = np.loadtxt("{0}{1}Si{2}_{3}_{4:-.0f}_p.xc.gz".format(path,
geomPrefix, hkl, tname, alphaDeg), unpack=True)
p2, = ax.plot(x, R2p, '--C0', label='p XCrystal')
p2, = ax.plot(x/convFactor*1e6, R2p, '--C0', label='p XCrystal')

x, R2s = np.loadtxt("{0}{1}Si{2}_{3}_{4:-.0f}_s.xin.gz".format(path,
geomPrefix, hkl, tname, alphaDeg), unpack=True)
p3, = ax.plot(x, R2s, '-C1', label='s XInpro')
p3, = ax.plot(x/convFactor*1e6, R2s, '-C1', label='s XInpro')
x, R2p = np.loadtxt("{0}{1}Si{2}_{3}_{4:-.0f}_p.xin.gz".format(path,
geomPrefix, hkl, tname, alphaDeg), unpack=True)
p4, = ax.plot(x, R2p, '--C1', label='p XInpro')
p4, = ax.plot(x/convFactor*1e6, R2p, '--C1', label='p XInpro')

p7, = ax.plot((theta - thetaCenter) * convFactor, abs(curS)**2, '-C2')
p8, = ax.plot((theta - thetaCenter) * convFactor, abs(curP)**2, '--C2')
ax.set_xlabel(r'$\theta-\theta_B$ (arcsec)')
p7, = ax.plot((theta - thetaCenter)*1e6, abs(curS)**2, '-C2')
p8, = ax.plot((theta - thetaCenter)*1e6, abs(curP)**2, '--C2')
ax.set_xlabel(r'$\theta-\theta_B$ (µrad)')
if geom.endswith('transmitted'):
ax.set_ylabel('transmittivity')
else:
ax.set_ylabel('reflectivity')
ax.set_xlim([dtheta[0] * convFactor, dtheta[-1] * convFactor])
ax.set_xlim(dtheta[0]*1e6, dtheta[-1]*1e6)
ax.set_ylim(0, None)

l1 = ax.legend([p1, p2], ['s', 'p'], loc=legendPos1)
Expand All @@ -317,6 +317,8 @@ def for_one_alpha(crystal, alphaDeg, hkl):
ax.legend([p1, p3, p7], ['XCrystal/XOP', 'XInpro/XOP', 'xrt'],
loc=legendPos2)
ax.add_artist(l1)
fig.text(0.02, 0.98, r'$E$ = {0:.0f} keV'.format(E0*1e-3),
transform=ax.transAxes, size=11, ha='left', va='top')

fname = '{0}Si{1}_{2}_{3:-.0f}'.format(
geomPrefix, hkl, tname, alphaDeg)
Expand Down Expand Up @@ -391,25 +393,25 @@ def for_one_alpha(alphaDeg, hkl):

ax.set_title(r'Comparison of Bragg and Laue transmittivity for Si{0}'.
format(hkl), fontsize=14)
p1, = ax.plot((theta-thetaCenter) * convFactor, abs(braggS)**2, '-C0')
p2, = ax.plot((theta-thetaCenter) * convFactor, abs(braggP)**2, '-C1')
p3, = ax.plot((theta-thetaCenter) * convFactor, abs(laueS)**2, '-C0.')
p4, = ax.plot((theta-thetaCenter) * convFactor, abs(laueP)**2, '-C1.')
ax.set_xlabel(r'$\theta-\theta_B$ (arcsec)')
p1, = ax.plot((theta-thetaCenter)*1e6, abs(braggS)**2, '-C0')
p2, = ax.plot((theta-thetaCenter)*1e6, abs(braggP)**2, '-C1')
p3, = ax.plot((theta-thetaCenter)*1e6, abs(laueS)**2, '-C0.')
p4, = ax.plot((theta-thetaCenter)*1e6, abs(laueP)**2, '-C1.')
ax.set_xlabel(r'$\theta-\theta_B$ (µrad)')
ax.set_ylabel('transmittivity')

l1 = ax.legend([p1, p2], ['s', 'p'], loc='lower left')
ax.legend([p1, p3], [u'Bragg t={0:.1f} µm'.format(
siBraggCrystal.t * 1e3), u'Laue t={0:.1f} µm'.format(
siLaueCrystal.t * 1e3)], loc='upper left')
ax.add_artist(l1)
ax.set_xlim([dtheta[0] * convFactor, dtheta[-1] * convFactor])
ax.set_xlim(dtheta[0]*1e6, dtheta[-1]*1e6)

fname = r'BraggLaueTrSi{0}'.format(hkl)
fig.savefig(fname + '.png')

E0 = 10000.
convFactor = 180 / math.pi * 3600. # arcsec
# convFactor = 180 / math.pi * 3600. # arcsec
if hkl == '111': # Si111
dtheta = np.linspace(-100, 100, 400) * 1e-6
dSpacing = 3.13562
Expand Down Expand Up @@ -928,11 +930,11 @@ def run_tests():

# Compare the calculated rocking curves of Si crystals with those calculated by
# XCrystal and XInpro (parts of XOP):
# compare_rocking_curves('333')
# compare_rocking_curves('333', t=0.100) # t is thickness in mm
# compare_rocking_curves('333', t=0.100, geom='Bragg transmitted')
# compare_rocking_curves('333', t=0.100, geom='Laue reflected')
# compare_rocking_curves('333', t=0.100, geom='Laue transmitted')
compare_rocking_curves('333')
compare_rocking_curves('333', t=0.100) # t is thickness in mm
compare_rocking_curves('333', t=0.100, geom='Bragg transmitted')
compare_rocking_curves('333', t=0.100, geom='Laue reflected')
compare_rocking_curves('333', t=0.100, geom='Laue transmitted')

# check that Bragg transmitted and Laue transmitted give the same results if
# the beam path is equal:
Expand Down Expand Up @@ -961,7 +963,7 @@ def run_tests():

# Compare the calculated transmittivity with that by XPower
# (part of XOP):
compare_transmittivity()
# compare_transmittivity()

# Play with Si crystal:
# crystalSi = rm.CrystalSi(hkl=(1, 1, 1), tK=100.)
Expand Down
34 changes: 18 additions & 16 deletions tests/raycing/test_pytte.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@
"name": "Bragg Flat",
"crystal": "Si", # select from ('Si', 'Ge', 'Diamond', 'InSb', 'AlphaQuartz', 'Sapphire')
"geometry": "Bragg reflected", # Combination of Bragg/Laue reflected/transmitted
"hkl": [1, 1, 1],
"hkl": [3, 3, 3],
"thickness": 1., # mm
"asymmetry": 0., # degrees
"in_plane_rotation": 0., # degrees
"bending_Rm": np.inf, # meters
"bending_Rs": np.inf, # meters
"energy": 9000, # eV
"theta_array": np.linspace(-50, 100, 800), # microrad
"energy": 10000, # eV
"theta_array": np.linspace(-40, 40, 800), # microrad
"polarization": "sigma", # or "pi"
"precision": "float32" # Only for opencl backend. "float64" for Laue
}
Expand All @@ -133,14 +133,14 @@
"name": "Bragg 1D bent",
"crystal": "Si", # select from ('Si', 'Ge', 'Diamond', 'InSb', 'AlphaQuartz', 'Sapphire')
"geometry": "Bragg reflected", # Combination of Bragg/Laue reflected/transmitted
"hkl": [1, 1, 1],
"hkl": [3, 3, 3],
"thickness": 0.7, # mm
"asymmetry": 5., # degrees
"in_plane_rotation": 0., # degrees
"bending_Rm": 10., # meters
"bending_Rs": np.inf, # meters
"energy": 9000., # eV
"theta_array": np.linspace(-50, 100, 800), # microrad
"energy": 10000., # eV
"theta_array": np.linspace(-40, 40, 800), # microrad
"polarization": "sigma", # or "pi"
"precision": "float32" # Only for opencl backend. "float64" for Laue
}
Expand All @@ -155,8 +155,8 @@
"in_plane_rotation": 0., # degrees
"bending_Rm": 10., # meters
"bending_Rs": 10, # meters
"energy": 19000, # eV
"theta_array": np.linspace(-50, 50, 800), # microrad
"energy": 20000, # eV
"theta_array": np.linspace(-40, 40, 800), # microrad
"polarization": "sigma", # or "pi"
"precision": "float32" # Only for opencl backend. "float64" for Laue
}
Expand All @@ -171,8 +171,8 @@
"in_plane_rotation": 60., # degrees
"bending_Rm": 10., # meters
"bending_Rs": np.inf, # meters
"energy": 29000, # eV
"theta_array": np.linspace(-50, 50, 1500), # microrad
"energy": 30000, # eV
"theta_array": np.linspace(-50, 50, 1000), # microrad
"polarization": "sigma", # or "pi"
"precision": "float64" # Only for opencl backend. "float64" for Laue
}
Expand All @@ -188,7 +188,7 @@
"bending_Rm": 20., # meters
"bending_Rs": 20, # meters
"energy": 60000, # eV
"theta_array": np.linspace(-40, 100, 1500), # microrad
"theta_array": np.linspace(-40, 100, 1400), # microrad
"polarization": "sigma", # or "pi"
"precision": "float64" # Only for opencl backend. "float64" for Laue
}
Expand All @@ -203,8 +203,8 @@
"in_plane_rotation": 60., # degrees
"bending_Rm": 10., # meters
"bending_Rs": np.inf, # meters
"energy": 29000, # eV
"theta_array": np.linspace(-50, 50, 1500), # microrad
"energy": 30000, # eV
"theta_array": np.linspace(-50, 50, 1000), # microrad
"polarization": "sigma", # or "pi"
"precision": "float64" # Only for opencl backend. "float64" for Laue
}
Expand All @@ -220,7 +220,7 @@
"bending_Rm": 20., # meters
"bending_Rs": 20, # meters
"energy": 60000, # eV
"theta_array": np.linspace(-40, 100, 1500), # microrad
"theta_array": np.linspace(-40, 100, 1400), # microrad
"polarization": "sigma", # or "pi"
"precision": "float64" # Only for opencl backend. "float64" for Laue
}
Expand Down Expand Up @@ -336,8 +336,10 @@ def run_pytte_original(name, crystal, geometry, hkl, thickness, asymmetry,
for icp, kw in enumerate(cases):
plt.figure(icp)
plt.xlabel(r'$\theta-\theta_B$ (µrad)')
plt.ylabel('|Amplitude|²')
title = "{0}, {1}-mm-thick {2}{3} at {4:.1f} keV".format(
ylabel = 'reflectivity' if kw["geometry"].endswith("lected") else \
'transmittivity'
plt.ylabel(ylabel)
title = "{0}, {1}-mm-thick {2}{3} at {4:.0f} keV".format(
kw["name"], kw["thickness"], kw["crystal"],
''.join([str(m) for m in kw["hkl"]]), kw["energy"]*1e-3)
title2 = []
Expand Down

0 comments on commit 1cde1bd

Please sign in to comment.