diff --git a/pyproject.toml b/pyproject.toml index 83cbb454..1acf1608 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ requires-python = ">=3.10" # Make sure to list one dependency per line. dependencies = [ "dask", - "essreduce", + "essreduce>=24.07.1", "graphviz", "numpy", "plopp", diff --git a/requirements/base.in b/requirements/base.in index eba882d8..48d4d054 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -3,7 +3,7 @@ # --- END OF CUSTOM SECTION --- # The following was generated by 'tox -e deps', DO NOT EDIT MANUALLY! dask -essreduce +essreduce>=24.07.1 graphviz numpy plopp diff --git a/requirements/base.txt b/requirements/base.txt index 942dc4ed..bfada6e6 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,4 +1,4 @@ -# SHA1:d8ffbcd7269e8e6905a85cd09c6df5878084b9e8 +# SHA1:644597105dd89e09109382941ce5eb8d7de1db9d # # This file is autogenerated by pip-compile-multi # To update, run: @@ -7,7 +7,7 @@ # asttokens==2.4.1 # via stack-data -certifi==2024.6.2 +certifi==2024.7.4 # via requests charset-normalizer==3.3.2 # via requests @@ -23,17 +23,19 @@ cyclebane==24.6.0 # via sciline cycler==0.12.1 # via matplotlib -dask==2024.6.0 +dask==2024.7.0 # via -r base.in decorator==5.1.1 # via ipython -essreduce==24.3.11 +essreduce==24.7.1 # via -r base.in +exceptiongroup==1.2.1 + # via ipython executing==2.0.1 # via stack-data -fonttools==4.53.0 +fonttools==4.53.1 # via matplotlib -fsspec==2024.6.0 +fsspec==2024.6.1 # via dask graphviz==0.20.3 # via -r base.in @@ -43,9 +45,11 @@ h5py==3.11.0 # scippnexus idna==3.7 # via requests +importlib-metadata==8.0.0 + # via dask ipydatawidgets==4.3.5 # via pythreejs -ipython==8.25.0 +ipython==8.26.0 # via ipywidgets ipywidgets==8.1.3 # via @@ -59,10 +63,14 @@ kiwisolver==1.4.5 # via matplotlib locket==1.0.0 # via partd -matplotlib==3.9.0 - # via plopp +matplotlib==3.9.1 + # via + # mpltoolbox + # plopp matplotlib-inline==0.1.7 # via ipython +mpltoolbox==24.5.1 + # via scippneutron networkx==3.3 # via cyclebane numpy==2.0.0 @@ -72,6 +80,7 @@ numpy==2.0.0 # h5py # ipydatawidgets # matplotlib + # mpltoolbox # pythreejs # scipp # scippneutron @@ -87,7 +96,7 @@ partd==1.4.2 # via dask pexpect==4.9.0 # via ipython -pillow==10.3.0 +pillow==10.4.0 # via matplotlib platformdirs==4.2.2 # via pooch @@ -117,7 +126,7 @@ pyyaml==6.0.1 # via dask requests==2.32.3 # via pooch -sciline==24.6.0 +sciline==24.6.2 # via -r base.in scipp==24.6.0 # via @@ -125,14 +134,14 @@ scipp==24.6.0 # essreduce # scippneutron # scippnexus -scippneutron==24.5.0 +scippneutron==24.7.0 # via -r base.in scippnexus==24.6.0 # via # -r base.in # essreduce # scippneutron -scipy==1.13.1 +scipy==1.14.0 # via # scippneutron # scippnexus @@ -156,9 +165,13 @@ traitlets==5.14.3 # traittypes traittypes==0.2.1 # via ipydatawidgets +typing-extensions==4.12.2 + # via ipython urllib3==2.2.2 # via requests wcwidth==0.2.13 # via prompt-toolkit widgetsnbextension==4.0.11 # via ipywidgets +zipp==3.19.2 + # via importlib-metadata diff --git a/requirements/ci.txt b/requirements/ci.txt index 5d631e1e..4d81cbd2 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -7,7 +7,7 @@ # cachetools==5.3.3 # via tox -certifi==2024.6.2 +certifi==2024.7.4 # via requests chardet==5.2.0 # via tox @@ -17,7 +17,7 @@ colorama==0.4.6 # via tox distlib==0.3.8 # via virtualenv -filelock==3.15.1 +filelock==3.15.4 # via # tox # virtualenv @@ -38,7 +38,7 @@ platformdirs==4.2.2 # virtualenv pluggy==1.5.0 # via tox -pyproject-api==1.6.1 +pyproject-api==1.7.1 # via tox requests==2.32.3 # via -r ci.in @@ -48,9 +48,9 @@ tomli==2.0.1 # via # pyproject-api # tox -tox==4.15.1 +tox==4.16.0 # via -r ci.in urllib3==2.2.2 # via requests -virtualenv==20.26.2 +virtualenv==20.26.3 # via tox diff --git a/requirements/dev.txt b/requirements/dev.txt index 077dbfc5..cabce220 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -28,9 +28,9 @@ async-lru==2.0.4 # via jupyterlab cffi==1.16.0 # via argon2-cffi-bindings -copier==9.2.0 +copier==9.3.1 # via -r dev.in -dunamai==1.21.1 +dunamai==1.21.2 # via copier fqdn==1.5.1 # via jsonschema @@ -50,7 +50,7 @@ json5==0.9.25 # via jupyterlab-server jsonpointer==3.0.0 # via jsonschema -jsonschema[format-nongpl]==4.22.0 +jsonschema[format-nongpl]==4.23.0 # via # jupyter-events # jupyterlab-server @@ -67,7 +67,7 @@ jupyter-server==2.14.1 # notebook-shim jupyter-server-terminals==0.5.3 # via jupyter-server -jupyterlab==4.2.2 +jupyterlab==4.2.3 # via -r dev.in jupyterlab-server==2.27.2 # via jupyterlab @@ -87,9 +87,9 @@ prometheus-client==0.20.0 # via jupyter-server pycparser==2.22 # via cffi -pydantic==2.7.4 +pydantic==2.8.2 # via copier -pydantic-core==2.18.4 +pydantic-core==2.20.1 # via pydantic python-json-logger==2.0.7 # via jupyter-events diff --git a/requirements/docs.txt b/requirements/docs.txt index b2ab1be9..b0b04012 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -24,7 +24,7 @@ beautifulsoup4==4.12.3 # pydata-sphinx-theme bleach==6.1.0 # via nbconvert -debugpy==1.8.1 +debugpy==1.8.2 # via ipykernel defusedxml==0.7.1 # via nbconvert @@ -40,7 +40,7 @@ fastjsonschema==2.20.0 # via nbformat imagesize==1.4.1 # via sphinx -ipykernel==6.29.4 +ipykernel==6.29.5 # via -r docs.in ipympl==0.9.4 # via -r docs.in @@ -52,7 +52,7 @@ jinja2==3.1.4 # nbconvert # nbsphinx # sphinx -jsonschema==4.22.0 +jsonschema==4.23.0 # via nbformat jsonschema-specifications==2023.12.1 # via jsonschema @@ -114,7 +114,7 @@ pybtex==0.24.0 # sphinxcontrib-bibtex pybtex-docutils==1.0.3 # via sphinxcontrib-bibtex -pydata-sphinx-theme==0.15.3 +pydata-sphinx-theme==0.15.4 # via -r docs.in pytz==2024.1 # via pandas @@ -126,7 +126,7 @@ referencing==0.35.1 # via # jsonschema # jsonschema-specifications -rpds-py==0.18.1 +rpds-py==0.19.0 # via # jsonschema # referencing @@ -144,7 +144,7 @@ sphinx==7.3.7 # sphinx-copybutton # sphinx-design # sphinxcontrib-bibtex -sphinx-autodoc-typehints==2.1.1 +sphinx-autodoc-typehints==2.2.2 # via -r docs.in sphinx-copybutton==0.5.2 # via -r docs.in diff --git a/requirements/mypy.txt b/requirements/mypy.txt index c4b5fb0b..6afffb45 100644 --- a/requirements/mypy.txt +++ b/requirements/mypy.txt @@ -6,7 +6,7 @@ # pip-compile-multi # -r test.txt -mypy==1.10.0 +mypy==1.10.1 # via -r mypy.in mypy-extensions==1.0.0 # via mypy diff --git a/requirements/nightly.in b/requirements/nightly.in index 7bb461f2..3ac68d04 100644 --- a/requirements/nightly.in +++ b/requirements/nightly.in @@ -2,7 +2,7 @@ # --- END OF CUSTOM SECTION --- # The following was generated by 'tox -e deps', DO NOT EDIT MANUALLY! dask -essreduce +essreduce>=24.07.1 graphviz numpy pythreejs diff --git a/requirements/nightly.txt b/requirements/nightly.txt index 17a9546e..a88ebdc2 100644 --- a/requirements/nightly.txt +++ b/requirements/nightly.txt @@ -1,4 +1,4 @@ -# SHA1:612c1f95a91244f0fff95ee08552bee68d1b697b +# SHA1:9db68cd4d40ba40501f7f36513adba4d274e18ae # # This file is autogenerated by pip-compile-multi # To update, run: @@ -8,7 +8,7 @@ -r basetest.txt asttokens==2.4.1 # via stack-data -certifi==2024.6.2 +certifi==2024.7.4 # via requests charset-normalizer==3.3.2 # via requests @@ -24,17 +24,17 @@ cyclebane==24.6.0 # via sciline cycler==0.12.1 # via matplotlib -dask==2024.6.0 +dask==2024.7.0 # via -r nightly.in decorator==5.1.1 # via ipython -essreduce==24.3.11 +essreduce==24.7.1 # via -r nightly.in executing==2.0.1 # via stack-data -fonttools==4.53.0 +fonttools==4.53.1 # via matplotlib -fsspec==2024.6.0 +fsspec==2024.6.1 # via dask graphviz==0.20.3 # via -r nightly.in @@ -44,11 +44,11 @@ h5py==3.11.0 # scippnexus idna==3.7 # via requests -importlib-metadata==7.1.0 +importlib-metadata==8.0.0 # via dask ipydatawidgets==4.3.5 # via pythreejs -ipython==8.25.0 +ipython==8.26.0 # via ipywidgets ipywidgets==8.1.3 # via @@ -62,7 +62,7 @@ kiwisolver==1.4.5 # via matplotlib locket==1.0.0 # via partd -matplotlib==3.9.0 +matplotlib==3.9.1 # via # mpltoolbox # plopp @@ -78,7 +78,7 @@ partd==1.4.2 # via dask pexpect==4.9.0 # via ipython -pillow==10.3.0 +pillow==10.4.0 # via matplotlib platformdirs==4.2.2 # via pooch @@ -119,7 +119,7 @@ scippnexus @ git+https://github.com/scipp/scippnexus@main # -r nightly.in # essreduce # scippneutron -scipy==1.13.1 +scipy==1.14.0 # via # scippneutron # scippnexus diff --git a/requirements/static.txt b/requirements/static.txt index cb03fb85..e106d602 100644 --- a/requirements/static.txt +++ b/requirements/static.txt @@ -9,9 +9,9 @@ cfgv==3.4.0 # via pre-commit distlib==0.3.8 # via virtualenv -filelock==3.15.1 +filelock==3.15.4 # via virtualenv -identify==2.5.36 +identify==2.6.0 # via pre-commit nodeenv==1.9.1 # via pre-commit @@ -21,5 +21,5 @@ pre-commit==3.7.1 # via -r static.in pyyaml==6.0.1 # via pre-commit -virtualenv==20.26.2 +virtualenv==20.26.3 # via pre-commit diff --git a/src/ess/powder/__init__.py b/src/ess/powder/__init__.py index 74869ed4..50ecb914 100644 --- a/src/ess/powder/__init__.py +++ b/src/ess/powder/__init__.py @@ -13,7 +13,6 @@ grouping, masking, smoothing, - uncertainty, ) from .masking import with_pixel_mask_filenames @@ -42,6 +41,5 @@ "masking", "providers", "smoothing", - "uncertainty", "with_pixel_mask_filenames", ] diff --git a/src/ess/powder/correction.py b/src/ess/powder/correction.py index 38049bbe..794b018a 100644 --- a/src/ess/powder/correction.py +++ b/src/ess/powder/correction.py @@ -5,6 +5,7 @@ from typing import Any import scipp as sc +from ess.reduce.uncertainty import broadcast_uncertainties from scippneutron.conversion.graph import beamline, tof from ._util import event_or_outer_coord @@ -23,7 +24,6 @@ UncertaintyBroadcastMode, VanadiumRun, ) -from .uncertainty import broadcast_uncertainties def normalize_by_monitor( @@ -83,8 +83,10 @@ def _normalize_by_vanadium( vanadium: sc.DataArray, uncertainty_broadcast_mode: UncertaintyBroadcastMode, ) -> sc.DataArray: - vanadium = broadcast_uncertainties(vanadium, uncertainty_broadcast_mode) norm = vanadium.hist() + norm = broadcast_uncertainties( + norm, prototype=data, mode=uncertainty_broadcast_mode + ) # Converting to unit 'one' because the division might produce a unit # with a large scale if the proton charges in data and vanadium were # measured with different units. diff --git a/src/ess/powder/types.py b/src/ess/powder/types.py index e4006c5b..658bcc1a 100644 --- a/src/ess/powder/types.py +++ b/src/ess/powder/types.py @@ -8,11 +8,11 @@ """ from collections.abc import Callable -from enum import Enum from typing import Any, NewType, TypeVar import sciline import scipp as sc +from ess.reduce.uncertainty import UncertaintyBroadcastMode as _UncertaintyBroadcastMode # 1 TypeVars used to parametrize the generic parts of the workflow @@ -56,9 +56,7 @@ class Filename(sciline.Scope[RunType, str], str): pixels by scattering angle into bins given by these edges. """ -UncertaintyBroadcastMode = Enum( - "UncertaintyBroadcastMode", ["drop", "upper_bound", "fail"] -) +UncertaintyBroadcastMode = _UncertaintyBroadcastMode """Mode for broadcasting uncertainties. See https://doi.org/10.3233/JNR-220049 for context. diff --git a/src/ess/powder/uncertainty.py b/src/ess/powder/uncertainty.py deleted file mode 100644 index 0d7f1642..00000000 --- a/src/ess/powder/uncertainty.py +++ /dev/null @@ -1,52 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) -"""Tools for handling statistical uncertainties.""" - -import scipp as sc - -from .types import UncertaintyBroadcastMode - - -def broadcast_uncertainties( - data: sc.DataArray, uncertainty_broadcast_mode: UncertaintyBroadcastMode -) -> sc.DataArray: - """Broadcast uncertainties using the specified mode. - - Parameters - ---------- - data: - Data with uncertainties to broadcast. - uncertainty_broadcast_mode: - Selected broadcast mode. - - Returns - ------- - : - Data with broadcast uncertainties. - """ - if ( - not _has_variances(data) - or uncertainty_broadcast_mode == UncertaintyBroadcastMode.fail - ): - return data - - if uncertainty_broadcast_mode == UncertaintyBroadcastMode.drop: - return _without_variances(data) - raise NotImplementedError( - 'Broadcasting uncertainties with the upper bound mode is not implemented' - ) - - -def _has_variances(data: sc.DataArray) -> bool: - return ( - data.bins is not None and data.bins.constituents['data'].variances is not None - ) or data.variances is not None - - -def _without_variances(data: sc.DataArray) -> sc.DataArray: - out = data.copy(deep=False) - if out.bins is not None: - out.bins.constituents['data'].variances = None - else: - out.variances = None - return out