Skip to content

Commit

Permalink
Merge pull request #99 from scipp/update-ess-reduce-nexus
Browse files Browse the repository at this point in the history
Update for restructured NeXus base workflow from `ess.reduce.nexus`
  • Loading branch information
SimonHeybrock authored Oct 11, 2024
2 parents 45b8fd4 + 42534de commit 90e3a57
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 83 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ requires-python = ">=3.10"
# Make sure to list one dependency per line.
dependencies = [
"dask",
"essreduce>=24.10.0",
"essreduce>=24.10.2",
"graphviz",
"numpy",
"plopp",
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# --- END OF CUSTOM SECTION ---
# The following was generated by 'tox -e deps', DO NOT EDIT MANUALLY!
dask
essreduce>=24.10.0
essreduce>=24.10.2
graphviz
numpy
plopp
Expand Down
16 changes: 8 additions & 8 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SHA1:3edca7ef7f02d8df072e91ce62fa7acd26cc0825
# SHA1:86f9288f7221f3a8506d1cc40db8a4584011b0e0
#
# This file is autogenerated by pip-compile-multi
# To update, run:
Expand All @@ -15,15 +15,15 @@ comm==0.2.2
# via ipywidgets
contourpy==1.3.0
# via matplotlib
cyclebane==24.6.0
cyclebane==24.10.0
# via sciline
cycler==0.12.1
# via matplotlib
dask==2024.9.1
# via -r base.in
decorator==5.1.1
# via ipython
essreduce==24.10.0
essreduce==24.10.2
# via -r base.in
exceptiongroup==1.2.2
# via ipython
Expand All @@ -43,7 +43,7 @@ importlib-metadata==8.5.0
# via dask
ipydatawidgets==4.3.5
# via pythreejs
ipython==8.27.0
ipython==8.28.0
# via ipywidgets
ipywidgets==8.1.5
# via
Expand All @@ -65,9 +65,9 @@ matplotlib-inline==0.1.7
# via ipython
mpltoolbox==24.5.1
# via scippneutron
networkx==3.3
networkx==3.4
# via cyclebane
numpy==2.1.1
numpy==2.1.2
# via
# -r base.in
# contourpy
Expand Down Expand Up @@ -125,7 +125,7 @@ scipp==24.9.1
# scippnexus
scippneutron==24.9.0
# via -r base.in
scippnexus==24.9.1
scippnexus==24.10.0
# via
# -r base.in
# essreduce
Expand All @@ -140,7 +140,7 @@ six==1.16.0
# python-dateutil
stack-data==0.6.3
# via ipython
toolz==0.12.1
toolz==1.0.0
# via
# dask
# partd
Expand Down
6 changes: 3 additions & 3 deletions requirements/basetest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
#
certifi==2024.8.30
# via requests
charset-normalizer==3.3.2
charset-normalizer==3.4.0
# via requests
exceptiongroup==1.2.2
# via pytest
idna==3.10
# via requests
iniconfig==2.0.0
# via pytest
numpy==2.1.1
numpy==2.1.2
# via pandas
packaging==24.1
# via
Expand All @@ -39,7 +39,7 @@ requests==2.32.3
# via pooch
six==1.16.0
# via python-dateutil
tomli==2.0.1
tomli==2.0.2
# via pytest
tzdata==2024.2
# via pandas
Expand Down
8 changes: 4 additions & 4 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ certifi==2024.8.30
# via requests
chardet==5.2.0
# via tox
charset-normalizer==3.3.2
charset-normalizer==3.4.0
# via requests
colorama==0.4.6
# via tox
distlib==0.3.8
distlib==0.3.9
# via virtualenv
filelock==3.16.1
# via
Expand Down Expand Up @@ -44,11 +44,11 @@ requests==2.32.3
# via -r ci.in
smmap==5.0.1
# via gitdb
tomli==2.0.1
tomli==2.0.2
# via
# pyproject-api
# tox
tox==4.21.0
tox==4.21.2
# via -r ci.in
typing-extensions==4.12.2
# via tox
Expand Down
4 changes: 2 additions & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pip-compile-multi==2.6.4
# via -r dev.in
pip-tools==7.4.1
# via pip-compile-multi
plumbum==1.8.3
plumbum==1.9.0
# via copier
prometheus-client==0.21.0
# via jupyter-server
Expand Down Expand Up @@ -115,7 +115,7 @@ terminado==0.18.1
# jupyter-server-terminals
toposort==1.10
# via pip-compile-multi
types-python-dateutil==2.9.0.20240906
types-python-dateutil==2.9.0.20241003
# via arrow
uri-template==1.3.0
# via jsonschema
Expand Down
14 changes: 7 additions & 7 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ bleach==6.1.0
# via nbconvert
certifi==2024.8.30
# via requests
charset-normalizer==3.3.2
charset-normalizer==3.4.0
# via requests
debugpy==1.8.6
debugpy==1.8.7
# via ipykernel
defusedxml==0.7.1
# via nbconvert
Expand Down Expand Up @@ -60,7 +60,7 @@ jinja2==3.1.4
# sphinx
jsonschema==4.23.0
# via nbformat
jsonschema-specifications==2023.12.1
jsonschema-specifications==2024.10.1
# via jsonschema
jupyter-client==8.6.3
# via
Expand All @@ -81,7 +81,7 @@ markdown-it-py==3.0.0
# via
# mdit-py-plugins
# myst-parser
markupsafe==2.1.5
markupsafe==3.0.1
# via
# jinja2
# nbconvert
Expand Down Expand Up @@ -150,7 +150,7 @@ snowballstemmer==2.2.0
# via sphinx
soupsieve==2.6
# via beautifulsoup4
sphinx==8.0.2
sphinx==8.1.0
# via
# -r docs.in
# myst-parser
Expand All @@ -160,7 +160,7 @@ sphinx==8.0.2
# sphinx-copybutton
# sphinx-design
# sphinxcontrib-bibtex
sphinx-autodoc-typehints==2.4.4
sphinx-autodoc-typehints==2.5.0
# via -r docs.in
sphinx-copybutton==0.5.2
# via -r docs.in
Expand All @@ -182,7 +182,7 @@ sphinxcontrib-serializinghtml==2.0.0
# via sphinx
tinycss2==1.3.0
# via nbconvert
tomli==2.0.1
tomli==2.0.2
# via sphinx
tornado==6.4.1
# via
Expand Down
8 changes: 4 additions & 4 deletions requirements/nightly.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ comm==0.2.2
# via ipywidgets
contourpy==1.3.0
# via matplotlib
cyclebane==24.6.0
cyclebane==24.10.0
# via sciline
cycler==0.12.1
# via matplotlib
Expand All @@ -42,7 +42,7 @@ importlib-metadata==8.5.0
# via dask
ipydatawidgets==4.3.5
# via pythreejs
ipython==8.27.0
ipython==8.28.0
# via ipywidgets
ipywidgets==8.1.5
# via
Expand All @@ -64,7 +64,7 @@ matplotlib-inline==0.1.7
# via ipython
mpltoolbox==24.5.1
# via scippneutron
networkx==3.3
networkx==3.4
# via cyclebane
parso==0.8.4
# via jedi
Expand Down Expand Up @@ -115,7 +115,7 @@ scipy==1.14.1
# scippnexus
stack-data==0.6.3
# via ipython
toolz==0.12.1
toolz==1.0.0
# via
# dask
# partd
Expand Down
4 changes: 2 additions & 2 deletions requirements/static.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
cfgv==3.4.0
# via pre-commit
distlib==0.3.8
distlib==0.3.9
# via virtualenv
filelock==3.16.1
# via virtualenv
Expand All @@ -17,7 +17,7 @@ nodeenv==1.9.1
# via pre-commit
platformdirs==4.3.6
# via virtualenv
pre-commit==3.8.0
pre-commit==4.0.1
# via -r static.in
pyyaml==6.0.2
# via pre-commit
Expand Down
4 changes: 2 additions & 2 deletions requirements/wheels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#
# pip-compile-multi
#
build==1.2.2
build==1.2.2.post1
# via -r wheels.in
packaging==24.1
# via build
pyproject-hooks==1.2.0
# via build
tomli==2.0.1
tomli==2.0.2
# via build
44 changes: 30 additions & 14 deletions src/ess/dream/io/geant4.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
import numpy as np
import sciline
import scipp as sc
import scippnexus as snx

from ess.powder.types import (
CalibratedDetector,
CalibrationData,
CalibrationFilename,
DetectorData,
Filename,
NeXusDetector,
NeXusComponent,
NeXusDetectorName,
NeXusSample,
NeXusSource,
Position,
RunType,
)
from ess.reduce.nexus.types import CalibratedBeamline
from ess.reduce.nexus.workflow import GenericNeXusWorkflow

MANTLE_DETECTOR_ID = sc.index(7)
Expand Down Expand Up @@ -60,9 +61,23 @@ def load_geant4_csv(file_path: Filename[RunType]) -> AllRawDetectors[RunType]:

def extract_geant4_detector(
detectors: AllRawDetectors[RunType], detector_name: NeXusDetectorName
) -> NeXusDetector[RunType]:
) -> NeXusComponent[snx.NXdetector, RunType]:
"""Extract a single detector from a loaded GEANT4 simulation."""
return NeXusDetector[RunType](detectors["instrument"][detector_name])
return NeXusComponent[snx.NXdetector, RunType](
detectors["instrument"][detector_name]
)


def get_calibrated_geant4_detector(
detector: NeXusComponent[snx.NXdetector, RunType],
) -> CalibratedDetector[RunType]:
"""
Replacement for :py:func:`ess.reduce.nexus.workflow.get_calibrated_detector`.
Since the Geant4 detectors already have computed positions as well as logical shape,
this just extracts the relevant event data.
"""
return detector['events'].copy(deep=False)


def _load_raw_events(file_path: str) -> sc.DataArray:
Expand Down Expand Up @@ -171,21 +186,21 @@ def geant4_load_calibration(filename: CalibrationFilename) -> CalibrationData:


def dummy_assemble_detector_data(
detector: CalibratedDetector[RunType],
detector: CalibratedBeamline[RunType],
) -> DetectorData[RunType]:
"""Dummy assembly of detector data, detector already contains neutron data."""
return DetectorData[RunType](detector)


def dummy_source() -> NeXusSource[RunType]:
return NeXusSource[RunType](
sc.DataGroup(position=sc.vector([np.nan, np.nan, np.nan], unit="mm"))
def dummy_source_position() -> Position[snx.NXsource, RunType]:
return Position[snx.NXsource, RunType](
sc.vector([np.nan, np.nan, np.nan], unit="mm")
)


def dummy_sample() -> NeXusSample[RunType]:
return NeXusSample[RunType](
sc.DataGroup(position=sc.vector([np.nan, np.nan, np.nan], unit="mm"))
def dummy_sample_position() -> Position[snx.NXsample, RunType]:
return Position[snx.NXsample, RunType](
sc.vector([np.nan, np.nan, np.nan], unit="mm")
)


Expand All @@ -197,7 +212,8 @@ def LoadGeant4Workflow() -> sciline.Pipeline:
wf.insert(extract_geant4_detector)
wf.insert(load_geant4_csv)
wf.insert(geant4_load_calibration)
wf.insert(get_calibrated_geant4_detector)
wf.insert(dummy_assemble_detector_data)
wf.insert(dummy_source)
wf.insert(dummy_sample)
wf.insert(dummy_source_position)
wf.insert(dummy_sample_position)
return wf
Loading

0 comments on commit 90e3a57

Please sign in to comment.