Skip to content
Snippets Groups Projects
Commit 5061bb92 authored by Egor Sobolev's avatar Egor Sobolev
Browse files

Add plot of rings on original image, fix number of visible rings, fix radial profile limits

parent 7e89e0ce
No related branches found
No related tags found
1 merge request!3Center refinement using powder diffraction data
import matplotlib.pyplot as plt
import numpy as np
from pyFAI.azimuthalIntegrator import AzimuthalIntegrator
from matplotlib.transforms import Bbox
from .image_tools import find_rings, make_shadow_mask, threshold_gaussian
from .misc import pixel_radii, reciprocal_to_dectector
......@@ -12,7 +13,7 @@ class PowderDiffraction:
min_area=30, sigma=1.8, snr=1, border_mask=None,
make_shadow_mask=True):
self.geom = geom
self.peaks = peaks
self.peaks = peaks[np.square(wave_length * peaks) < 2.0]
self.clen = clen
self.lmd = wave_length
self.min_area = min_area
......@@ -99,6 +100,25 @@ class PowderDiffraction:
return ax
def draw_on_image(self, img, ax=None):
geom = self.transform_geometry()
ax = geom.plot_data(img, ax=ax, colorbar=False,
interpolation="none", norm="log")
xlim = ax.get_xlim()
ylim = ax.get_ylim()
peaks = reciprocal_to_dectector(
self.peaks, self.lmd_hat,
self.clen_hat / geom.pixel_size)
rmax = np.max(pixel_radii(geom))
for r in peaks[peaks < rmax]:
ax.add_patch(
plt.Circle((0, 0), r, fill=False, ls=":", lw=1, ec="w", clip_box=Bbox.unit()))
return ax
def refinement_info(self):
if self.beam_center is None:
raise ValueError("Rings are not fitted yet.")
......@@ -108,7 +128,7 @@ class PowderDiffraction:
print(f"Camera len: {self.clen:.4f} -> {self.clen_hat:.4f} (m)")
print(f"Photon energy: {hc_e / self.lmd_hat:.3f} eV")
def draw_radial_profile(self, img, mask, ax=None, figsize=(10, 5)):
def draw_radial_profile(self, img, mask, rmax=None, ax=None, figsize=(10, 5)):
geom = self.transform_geometry()
peaks = reciprocal_to_dectector(
......@@ -123,6 +143,8 @@ class PowderDiffraction:
)
rmin = np.min(pixel_radii(geom)[~mask]) * geom.pixel_size * 1000
if rmax is None:
rmax = max(peaks[-1] + 1, 80)
msk = mask
if self.shadow is not None:
......@@ -133,7 +155,7 @@ class PowderDiffraction:
mask=msk.reshape(-1, 128),
npt=1000,
unit="r_mm",
radial_range=(rmin, peaks[-1] + 1),
radial_range=(rmin, rmax),
)
if ax is None:
fig, ax = plt.subplots(1, 1, figsize=figsize)
......@@ -142,6 +164,6 @@ class PowderDiffraction:
ax.axvline(r, c="gray", lw=0.5, ls=":")
ax.semilogy(rint, intens)
ax.set_xlim(rmin, peaks[-1] + 1)
ax.set_xlim(rmin, rmax)
return ax
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment