Skip to content

method missing wedge percentile#2721

Merged
kif merged 2 commits intosilx-kit:mainfrom
EdgarGF93:missingwedge_new_threshold
Dec 10, 2025
Merged

method missing wedge percentile#2721
kif merged 2 commits intosilx-kit:mainfrom
EdgarGF93:missingwedge_new_threshold

Conversation

@EdgarGF93
Copy link
Copy Markdown
Collaborator

@EdgarGF93 EdgarGF93 commented Dec 5, 2025

A simple alternative to optimize the missing wedge mask by using the percentile on result.count array

@EdgarGF93
Copy link
Copy Markdown
Collaborator Author

import time
import numpy
import fabio
import matplotlib.pyplot as plt
from matplotlib.pyplot import subplots
from pyFAI.test.utilstest import UtilsTest
from pyFAI.gui.jupyter import plot1d, plot2d
from pyFAI import load, version as pyFAI_version
from pyFAI.integrator.fiber import get_missing_wedge_mask_by_percentile


y6 = fabio.open(UtilsTest.getimage("Y6.edf")).data
air = fabio.open(UtilsTest.getimage("air.edf")).data
data = y6 - 0.03 * air
def update_style(ax):
    for img in ax.get_images():
        img.set_cmap("viridis")
        img.set_clim(10,500)
t0 = time.perf_counter()
print("pyFAI version:", pyFAI_version) 


poni_filename = UtilsTest.getimage("LaB6_3.poni")
fi = load(filename=poni_filename, type_="pyFAI.integrator.fiber.FiberIntegrator")
params = {
    "sample_orientation" : 6,
    "npt_ip" : 1000,
    "ip_range" : [-5,5],
    "npt_oop" : 1000,
    "oop_range" : [5,7],
    "vertical_integration" : False,
}

res2d_default = fi.integrate2d_grazing_incidence(data=data, method=("full", "csr", "cython"), **params)


fig, axes = subplots(ncols=10, nrows=2, figsize=(15,5))
percentiles = numpy.linspace(0.05, 0.1, 20)
for ax, p in zip(axes.ravel(), percentiles):
    ax.imshow(get_missing_wedge_mask_by_percentile(result=res2d_default, percentile=p), origin="lower")
    ax.set_title(f"{p:.3f}")

plt.show()
Screenshot from 2025-12-05 23-52-27

@EdgarGF93
Copy link
Copy Markdown
Collaborator Author

if percentile=0.058 looks the best one for this map:

res1d_no = fi.integrate1d_grazing_incidence(data=data, method=("no", "csr", "cython"),  **params

                                               )

percentile = 0.058

res2d_full = fi.integrate2d_grazing_incidence(data=data, method=("full", "csr", "cython"), 
                                               use_missing_wedge=True,
                                               missing_wedge_percentile=percentile,
                                               **params
                                               )



res1d_full = fi.integrate1d_grazing_incidence(data=data, method=("full", "csr", "cython"), 
                                               use_missing_wedge=True,
                                               missing_wedge_percentile=percentile,
                                               **params
                                               )



fig, axes = subplots(ncols=3, figsize=(10,5))

ax=axes[0]
plot2d(res2d_full, ax=ax)
update_style(ax)


ax=axes[1]
plot1d(res1d_no, ax=ax, label="no splitting")
update_style(ax)

ax=axes[2]
plot1d(res1d_full, ax=ax, label="full")
update_style(ax)


plt.show()

We can now oversample the integration:
Screenshot from 2025-12-05 23-53-34

@EdgarGF93
Copy link
Copy Markdown
Collaborator Author

EdgarGF93 commented Dec 5, 2025

An example with the whole map:
We estimate that the percentage of bins falling into the empty spaces is 20-30%, and then a simple loop gives a good number

fig, axes = subplots(ncols=10, nrows=4, figsize=(15,15))
percentiles = numpy.linspace(0.2, 0.3, 40)
for ax, p in zip(axes.ravel(), percentiles):
    ax.imshow(get_missing_wedge_mask_by_percentile(result=res2d_default, percentile=p), origin="lower")
    ax.set_title(f"{p:.3f}")
plt.show()

image

@EdgarGF93 EdgarGF93 added the ready to merge Please review label Dec 5, 2025
@EdgarGF93 EdgarGF93 self-assigned this Dec 5, 2025
@EdgarGF93 EdgarGF93 force-pushed the missingwedge_new_threshold branch from 7cd1daf to 93b19bb Compare December 9, 2025 07:54
Copy link
Copy Markdown
Member

@kif kif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, would have been nice to have a unit-test.

@kif kif merged commit 55c5238 into silx-kit:main Dec 10, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge Please review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants