Skip to content
Draft
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/esssans/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@

:::

:::{grid-item-card} SKADI
:link: user-guide/skadi/index.md

:::

:::{grid-item-card} ISIS instruments
:link: user-guide/isis/index.md

Expand Down
1 change: 1 addition & 0 deletions packages/esssans/docs/user-guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ maxdepth: 1

installation
loki/index
skadi/index
isis/index
common/index
```
31 changes: 31 additions & 0 deletions packages/esssans/docs/user-guide/skadi/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# SKADI

## Detector diagnostics

::::{grid} 3

:::{grid-item-card} Detector view
:link: skadi-detector-view.ipynb
:text-align: center

```{image} ../../_static/thumbnails/skadi_detector_view_light.svg
:class: only-light
:width: 100%
```

```{image} ../../_static/thumbnails/skadi_detector_view_dark.svg
:class: only-dark
:width: 100%
```

:::

::::

```{toctree}
---
hidden:
---

skadi-detector-view
```
74 changes: 74 additions & 0 deletions packages/esssans/docs/user-guide/skadi/skadi-detector-view.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"# SKADI detector view\n",
"\n",
"This example uses the SKADI McStas workflow to load detector events and display them in an interactive instrument view. The reduced example file is downloaded on first use and cached by pooch."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
"import scippneutron as scn\n",
"\n",
"from ess.skadi import SkadiMcStasWorkflow\n",
"from ess.skadi.data import skadi_mcstas_sample\n",
"from ess.sans.types import Filename, RawDetector, SampleRun"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"workflow = SkadiMcStasWorkflow()\n",
"workflow[Filename[SampleRun]] = skadi_mcstas_sample()\n",
"detector = workflow.compute(RawDetector[SampleRun])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [],
"source": [
"detector_view = scn.instrument_view(\n",
" detector.bins.sum(), size=0.006, norm=\"log\", cbar=True\n",
")\n",
"detector_view"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.15"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 1 addition & 0 deletions packages/esssans/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dynamic = ["version"]
dependencies = [
"dask>=2022.1.0",
"graphviz>=0.20",
"h5py>=3.11",
"essreduce>=26.6.0",
"numpy>=1.26.4",
"pandas>=2.1.2",
Expand Down
44 changes: 44 additions & 0 deletions packages/esssans/src/ess/sans/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Numerator,
Position,
ProcessedWavelengthBands,
RawDetector,
ReducedQ,
ReducedQxQy,
ReturnEvents,
Expand Down Expand Up @@ -90,6 +91,49 @@ def solid_angle(
)


def rectangular_pixel_solid_angle(
detector: RawDetector[RunType],
sample_position: Position[snx.NXsample, RunType],
) -> SolidAngle[RunType]:
r"""Approximate the solid angle of flat rectangular detector pixels.

The approximation is :math:`\Delta\Omega = A |\hat{n}\cdot\hat{r}| / r^2`,
where :math:`A` is the pixel area, :math:`\hat{n}` is its unit normal, and
:math:`r` is the distance from sample to pixel. It is valid when that distance
is much larger than the pixel width and height.

Parameters
----------
detector:
Detector data with calibrated geometry coordinates: ``position`` contains
pixel centers, the x and y components of ``pixel_size`` give the local
pixel width and height, and ``detector_normal`` contains dimensionless
unit normals. Positions and normals must share a coordinate system with
``sample_position``. Pixel sizes and normals may vary between pixels.
sample_position:
Position of the sample.

Returns
-------
:
Solid angles with the detector's pixel coordinates and masks preserved.
"""
scattered_beam = detector.coords['position'] - sample_position
pixel_size = detector.coords['pixel_size']
area = pixel_size.fields.x * pixel_size.fields.y
omega = (
area
* sc.abs(sc.dot(detector.coords['detector_normal'], scattered_beam))
/ sc.norm(scattered_beam) ** 3
).to(unit='dimensionless')

return SolidAngle[RunType](
concepts.rewrap_reduced_data(
prototype=detector, data=omega, dim=set(detector.dims) - set(omega.dims)
)
)


def mask_solid_angle(
solid_angle: SolidAngle[RunType],
masks: DetectorMasks,
Expand Down
24 changes: 24 additions & 0 deletions packages/esssans/src/ess/skadi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2026 Scipp contributors (https://github.com/scipp)

import importlib.metadata

from . import mcstas, workflow
from .mcstas import load_skadi_mcstas
from .workflow import SkadiMcStasWorkflow, SkadiWorkflow, skadi_default_parameters

try:
__version__ = importlib.metadata.version("esssans")
except importlib.metadata.PackageNotFoundError:
__version__ = "0.0.0"

del importlib

__all__ = [
'SkadiMcStasWorkflow',
'SkadiWorkflow',
'load_skadi_mcstas',
'mcstas',
'skadi_default_parameters',
'workflow',
]
25 changes: 25 additions & 0 deletions packages/esssans/src/ess/skadi/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2026 Scipp contributors (https://github.com/scipp)
"""Data for SKADI documentation examples."""

from pathlib import Path

from ess.reduce.data import make_registry

_registry = make_registry(
"ess/skadi",
files={
"skadi_mcstas_1e8_sample10_1_of_50.h5": (
"md5:37883335a05c41d420cff2b38f883fc2"
),
},
version="1",
)


def skadi_mcstas_sample() -> Path:
"""Return the reduced SKADI McStas sample used in the user guide."""
return _registry.get_path("skadi_mcstas_1e8_sample10_1_of_50.h5")


__all__ = ["skadi_mcstas_sample"]
Loading
Loading