Skip to content

[ESSREFLECTOMETRY] docs: better ground truth comparison in user guide - #739

Merged
jokasimr merged 9 commits into
mainfrom
better-ground-truth-comparison
Sep 14, 2026
Merged

jokasimr merged 9 commits into
mainfrom
better-ground-truth-comparison

Conversation

@jokasimr

@jokasimr jokasimr commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

It's nice to have a comparison that takes into account the instrument resolution, because then you can actually see that the results matches what we expect.

This is what the added figure looks like:

estia-comparison

@jokasimr
jokasimr requested a review from nvaytet September 8, 2026 14:23
@github-actions github-actions Bot added the essreflectometry Issues for essreflectometry. label Sep 8, 2026
@github-actions github-actions Bot changed the title docs: better ground truth comparison in user guide [ESSREFLECTOMETRY] docs: better ground truth comparison in user guide Sep 8, 2026
@jokasimr
jokasimr force-pushed the better-ground-truth-comparison branch from 33c4e08 to 5aaadce Compare September 8, 2026 17:08
"To compare it with this measurement, we smooth it with a kernel whose width varies with $Q$ and uses this run's `Q_resolution` coordinate.\n",
"This standard deviation includes the wavelength, sample-size, and detector contributions, averaged over the angles contributing to each $Q$ bin.\n",
"\n",
"We use [Refl1D's `convolve_sampled`](https://refl1d.readthedocs.io/en/stable/_modules/refl1d/sample/reflectivity.html), which integrates a tabulated ideal curve against a tabulated kernel.\n",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For some reason this rendered badly in the docs

Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll take a look 👍

" x=q.values[valid.values],\n",
" dx=half_width.values[valid.values],\n",
")\n",
"smoothed_ground_truth = sc.DataArray(\n",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having the plot in the notebook is great. It's unfortunate that we need so much code to produce it. Can we think of another way?

@jokasimr jokasimr Sep 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a helper for smoothing the ideal curve with the resolution of the reduced data.
That let's us remove the code from the notebook.
It's quite special purpose, but I don't think it makes much sense to generalize it more for now.

coords={
'Q': sc.array(dims='Q', values=[0, *ds[Qcol].values], unit='1/angstrom')
},
coords={'Q': sc.array(dims='Q', values=ds[Qcol].values, unit='1/angstrom')},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What was the reason for this change?

@jokasimr jokasimr Sep 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that was a bit of a hack to make the reference curve be displayed as a line instead of as markers in the figures. It should not have been like that to begin with. :/

Uses a symmetric trapezoid with a Q-dependent width, scaled so that its
standard deviation matches ``Q_resolution``. The kernel shape is a modelling
assumption: the standard deviation alone does not determine the response.
Requires the optional Refl1D package (``pip install refl1d``).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was wondering if we needed to use refl1d or if we could do the same with scipy (which is maybe more common)?
I don't mind either way, it's just adding a dep to the tests/docs builds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The feature we're after here that don't exist in scipy is the ability to smooth the signal by a kernel with a width that varies over Q in an irregular way (that is, not constant, not proportional to Q, but possibly different for at every point).

@jokasimr
jokasimr added this pull request to the merge queue Sep 14, 2026
Merged via the queue into main with commit b33aa37 Sep 14, 2026
24 checks passed
@jokasimr
jokasimr deleted the better-ground-truth-comparison branch September 14, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

essreflectometry Issues for essreflectometry.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants