Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
"source": [
"from scipp.scipy.interpolate import interp1d\n",
"\n",
"Iq_theory = sc.io.load_hdf5(loki.data.loki_tutorial_poly_gauss_I0())\n",
"Iq_theory = loki.data.loki_tutorial_poly_gauss_I0_data()\n",
"f = interp1d(Iq_theory, 'Q')\n",
"I0 = f(sc.midpoints(workflow.compute(QBins))).data[0]\n",
"I0"
Expand Down
27 changes: 27 additions & 0 deletions packages/esssans/src/ess/loki/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
from pathlib import Path

import numpy as np
import scipp as sc
from ess.sans.types import (
BackgroundRun,
DirectBeamFilename,
Expand Down Expand Up @@ -164,6 +166,31 @@ def loki_tutorial_poly_gauss_I0() -> Path:
return Path(_registry.get_path('PolyGauss_I0-50_Rg-60.h5'))


def loki_tutorial_poly_gauss_I0_data() -> sc.DataArray:
"""Return the analytical I(Q) model for the tutorial Poly-Gauss sample.

The model is the SasView ``poly_gauss_coil`` model with an intensity at zero
Q of 50, a radius of gyration of 60 angstrom, a polydispersity of 1.02, and
a background of 0.2.
Comment on lines +172 to +174

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 think the function would be more useful if all the parameters would be values we can tune?
You can still give them the default values you list here, but it would make it useful in case we want a new intensity at Q=0, different Q range, etc..

@SimonHeybrock SimonHeybrock Aug 7, 2026

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.

Yes, the goal of the issue was to make the computation part of a production code (not just a tutorial helper function), i.e., a graph node computing the model. I don't know if the params should all be workflow params, check with Judidth.

"""
q = sc.geomspace(
dim='Q',
start=0.0005237261180003165,
stop=0.5,
num=150,
unit='1/angstrom',
)
radius_of_gyration = sc.scalar(60.0, unit='angstrom')
# Preserve the float32 parameter values used to compute the original reference.
polydispersity = float(np.float32(1.02))
background = float(np.float32(0.2))

u = polydispersity - 1.0
z = (q * radius_of_gyration) ** 2 / (1.0 + 2.0 * u)
form_factor = 2.0 * ((1.0 + u * z) ** (-1.0 / u) + z - 1.0) / ((1.0 + u) * z**2)
return sc.DataArray(50.0 * form_factor + background, coords={'Q': q})


def loki_tutorial_direct_beam_all_pixels() -> DirectBeamFilename:
"""File containing direct beam function computed using the direct beam iterations
notebook, summing all pixels."""
Expand Down
2 changes: 1 addition & 1 deletion packages/esssans/tests/loki/directbeam_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def _get_I0(qbins: sc.Variable) -> sc.Variable:
Iq_theory = sc.io.load_hdf5(loki.data.loki_tutorial_poly_gauss_I0())
Iq_theory = loki.data.loki_tutorial_poly_gauss_I0_data()
f = interp1d(Iq_theory, 'Q')
return f(sc.midpoints(qbins)).data[0]

Expand Down
Loading