Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .copier-answers.ess.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 847e5e4
_commit: 0951a4b
_src_path: https://github.com/scipp/ess_template
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: afbe5c7
_commit: 6848c57
_src_path: gh:scipp/copier_template
description: Diffraction data reduction for the European Spallation Source
max_python: '3.12'
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/blank.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: blank
about: A blank issue template
name: Blank
about: General issue that does not fit another category
title: ''
labels: ''
assignees: ''
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
name: docs_html
path: html/

- uses: JamesIves/github-pages-deploy-action@v4.6.0
- uses: JamesIves/github-pages-deploy-action@v4.6.1
if: ${{ inputs.publish }}
with:
branch: gh-pages
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
args: [ "--drop-empty-cells",
"--extra-keys 'metadata.language_info.version cell.metadata.jp-MarkdownHeadingCollapsed cell.metadata.pycharm'" ]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
rev: v0.4.3
hooks:
- id: ruff
args: [ --fix ]
Expand Down
3 changes: 2 additions & 1 deletion conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ requirements:
run:
- python>=3.10

{# Conda does not allow spaces between package name and version, so remove them #}
{% for package in dependencies %}
- {% if package == "graphviz" %}python-graphviz{% else %}{{ package }}{% endif %}
- {% if package == "graphviz" %}python-graphviz{% else %}{{ package|replace(" ", "") }}{% endif %}
{% endfor %}


Expand Down
2 changes: 1 addition & 1 deletion docs/_templates/doc_version.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- This will display the version of the docs -->
Current {{ project }} version: {{ version }} (<a href="https://github.com/{{orgname}}/{{ project|lower }}/releases">older versions</a>).
Current ESSdiffraction version: {{ version }} (<a href="https://github.com/scipp/essdiffraction/releases">older versions</a>).
21 changes: 16 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-

import doctest
import os
import sys
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as get_version

from sphinx.util import logging

sys.path.insert(0, os.path.abspath("."))

logger = logging.getLogger(__name__)

# General information about the project.
project = "ESSdiffraction"
copyright = "2024 Scipp contributors"
Expand Down Expand Up @@ -35,6 +38,8 @@
import sciline.sphinxext.domain_types # noqa: F401

extensions.append("sciline.sphinxext.domain_types")
# See https://github.com/tox-dev/sphinx-autodoc-typehints/issues/457
suppress_warnings = ["config.cache"]
except ModuleNotFoundError:
pass

Expand Down Expand Up @@ -111,9 +116,15 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#

release = get_version("essdiffraction")
version = ".".join(release.split(".")[:3]) # CalVer
try:
release = get_version("essdiffraction")
version = ".".join(release.split('.')[:3]) # CalVer
except PackageNotFoundError:
logger.info(
"Warning: determining version from package metadata failed, falling back to "
"a dummy version number."
)
release = version = "0.0.0-dev"

warning_is_error = True

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extend-exclude = [

[tool.ruff.lint]
# See https://docs.astral.sh/ruff/rules/
select = ["B", "C4", "DTZ", "E", "F", "G", "I", "PERF", "PGH", "PT", "PYI", "RUF", "S", "T20", "W"]
select = ["B", "C4", "DTZ", "E", "F", "G", "I", "PERF", "PGH", "PT", "PYI", "RUF", "S", "T20", "UP", "W"]
ignore = [
# Conflict with ruff format, see
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
Expand Down
3 changes: 1 addition & 2 deletions requirements/make_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
from argparse import ArgumentParser
from pathlib import Path
from typing import List

import tomli

Expand All @@ -20,7 +19,7 @@
"""


def write_dependencies(dependency_name: str, dependencies: List[str]) -> None:
def write_dependencies(dependency_name: str, dependencies: list[str]) -> None:
path = Path(f"{dependency_name}.in")
if path.exists():
sections = path.read_text().split(CUSTOM_AUTO_SEPARATOR)
Expand Down
16 changes: 8 additions & 8 deletions src/ess/dream/instrument_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from html import escape
from typing import TYPE_CHECKING, Any, Optional, Union
from typing import TYPE_CHECKING, Any

import plopp as pp
import scipp as sc
Expand All @@ -16,9 +16,9 @@


def instrument_view(
data: Union[sc.DataArray, sc.DataGroup, dict],
dim: Optional[str] = None,
pixel_size: Optional[Union[float, sc.Variable]] = None,
data: sc.DataArray | sc.DataGroup | dict,
dim: str | None = None,
pixel_size: float | sc.Variable | None = None,
**kwargs: Any,
) -> Box:
"""
Expand Down Expand Up @@ -48,7 +48,7 @@ def instrument_view(
return Box(view.children)


def _to_data_group(data: Union[sc.DataArray, sc.DataGroup, dict]) -> sc.DataGroup:
def _to_data_group(data: sc.DataArray | sc.DataGroup | dict) -> sc.DataGroup:
if isinstance(data, sc.DataArray):
data = sc.DataGroup({data.name or "data": data})
elif isinstance(data, dict):
Expand All @@ -71,9 +71,9 @@ class InstrumentView:

def __init__(
self,
data: Union[sc.DataArray, sc.DataGroup, dict],
dim: Optional[str] = None,
pixel_size: Optional[Union[float, sc.Variable]] = None,
data: sc.DataArray | sc.DataGroup | dict,
dim: str | None = None,
pixel_size: float | sc.Variable | None = None,
**kwargs,
):
from plopp.widgets import SliceWidget, slice_dims
Expand Down
12 changes: 5 additions & 7 deletions src/ess/dream/io/geant4.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)

from typing import Dict, Optional

import numpy as np
import sciline
import scipp as sc
Expand Down Expand Up @@ -96,7 +94,7 @@ def _adjust_coords(da: sc.DataArray) -> None:
)


def _group(detectors: Dict[str, sc.DataArray]) -> Dict[str, sc.DataGroup]:
def _group(detectors: dict[str, sc.DataArray]) -> dict[str, sc.DataGroup]:
elements = ("module", "segment", "counter", "wire", "strip")

def group(key: str, da: sc.DataArray) -> sc.DataArray:
Expand All @@ -114,7 +112,7 @@ def group(key: str, da: sc.DataArray) -> sc.DataArray:

def _split_detectors(
data: sc.DataArray, detector_id_name: str = "det ID"
) -> Dict[str, sc.DataArray]:
) -> dict[str, sc.DataArray]:
groups = data.group(
sc.concat(
[
Expand Down Expand Up @@ -162,7 +160,7 @@ def _split_detectors(

def _extract_detector(
detector_groups: sc.DataArray, detector_id_name: str, detector_id: sc.Variable
) -> Optional[sc.DataArray]:
) -> sc.DataArray | None:
events = detector_groups[detector_id_name, detector_id].value
if len(events) == 0:
return None
Expand Down Expand Up @@ -191,10 +189,10 @@ def patch_detector_data(

def geant4_detector_dimensions(
data: RawDetectorData[SampleRun],
) -> NeXusDetectorDimensions[NeXusDetectorName]:
) -> NeXusDetectorDimensions:
# For geant4 data, we group by detector identifier, so the data already has
# logical dimensions, so we simply return the dimensions of the detector.
return NeXusDetectorDimensions[NeXusDetectorName](data.sizes)
return NeXusDetectorDimensions(data.sizes)


def geant4_load_calibration(
Expand Down
6 changes: 3 additions & 3 deletions src/ess/powder/correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
"""Correction algorithms for powder diffraction."""

from typing import Any, Dict, Optional
from typing import Any

import scipp as sc
from scippneutron.conversion.graph import beamline, tof
Expand Down Expand Up @@ -30,8 +30,8 @@ def normalize_by_monitor(
data: sc.DataArray,
*,
monitor: sc.DataArray,
wavelength_edges: Optional[sc.Variable] = None,
smooth_args: Optional[Dict[str, Any]] = None,
wavelength_edges: sc.Variable | None = None,
smooth_args: dict[str, Any] | None = None,
) -> sc.DataArray:
"""
Normalize event data by a monitor.
Expand Down
2 changes: 1 addition & 1 deletion src/ess/powder/masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Masking functions for the powder workflow.
"""

from typing import Iterable
from collections.abc import Iterable

import numpy as np
import sciline
Expand Down
4 changes: 1 addition & 3 deletions src/ess/powder/smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
Smoothing arrays data.
"""

from typing import Optional

import scipp as sc
from scipp.scipy.signal import butter

Expand All @@ -29,7 +27,7 @@ def _ensure_no_variances(var: sc.DataArray) -> sc.DataArray:


def lowpass(
da: sc.DataArray, *, dim: str, N: int, Wn: sc.Variable, coord: Optional[str] = None
da: sc.DataArray, *, dim: str, N: int, Wn: sc.Variable, coord: str | None = None
) -> sc.DataArray:
"""
Smooth data using a lowpass frequency filter.
Expand Down
11 changes: 5 additions & 6 deletions src/ess/powder/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
pipeline.
"""

from collections.abc import Callable
from enum import Enum
from typing import Any, Callable, Dict, NewType, TypeVar
from typing import Any, NewType, TypeVar

import sciline
import scipp as sc
Expand Down Expand Up @@ -89,10 +90,8 @@ class DataWithScatteringCoordinates(sciline.Scope[RunType, sc.DataArray], sc.Dat
d-spacing."""


class NeXusDetectorDimensions(
sciline.Scope[NeXusDetectorName, Dict[str, int]], Dict[str, int]
):
Copy link
Member Author

Choose a reason for hiding this comment

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

This was broken because NeXusDetectorName is not a TypeVar. I don't see a reason why NeXusDetectorDimensions needs to be generic.

"""Logical detector dimensions."""
NeXusDetectorDimensions = NewType("NeXusDetectorDimensions", dict[str, int])
"""Logical detector dimensions."""


class DspacingData(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
Expand Down Expand Up @@ -139,7 +138,7 @@ class MaskedData(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
dspacing regions."""


MaskedDetectorIDs = NewType("MaskedDetectorIDs", Dict[str, sc.Variable])
MaskedDetectorIDs = NewType("MaskedDetectorIDs", dict[str, sc.Variable])
"""1-D variable listing all masked detector IDs."""


Expand Down
6 changes: 2 additions & 4 deletions src/ess/snspowder/powgen/beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ def map_detector_to_spectrum(

def powgen_detector_dimensions(
detector_name: NeXusDetectorName,
) -> NeXusDetectorDimensions[NeXusDetectorName]:
) -> NeXusDetectorDimensions:
"""Dimensions used by POWGEN detectors."""
return NeXusDetectorDimensions[NeXusDetectorName](
DETECTOR_BANK_SIZES[detector_name]
)
return NeXusDetectorDimensions(DETECTOR_BANK_SIZES[detector_name])


providers = (powgen_detector_dimensions,)
Expand Down
17 changes: 8 additions & 9 deletions src/ess/snspowder/powgen/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""

from pathlib import Path
from typing import Dict, Optional, Union

import numpy as np
import scipp as sc
Expand All @@ -28,11 +27,11 @@ def _as_boolean_mask(var: sc.Variable) -> sc.Variable:


def _parse_calibration_instrument_args(
filename: Union[str, Path],
filename: str | Path,
*,
instrument_filename: Optional[str] = None,
instrument_name: Optional[str] = None,
) -> Dict[str, str]:
instrument_filename: str | None = None,
instrument_name: str | None = None,
) -> dict[str, str]:
if instrument_filename is not None:
if instrument_name is not None:
raise ValueError(
Expand All @@ -57,11 +56,11 @@ def _parse_calibration_instrument_args(


def load_calibration(
filename: Union[str, Path],
filename: str | Path,
*,
instrument_filename: Optional[str] = None,
instrument_name: Optional[str] = None,
mantid_args: Optional[dict] = None,
instrument_filename: str | None = None,
instrument_name: str | None = None,
mantid_args: dict | None = None,
) -> sc.Dataset:
"""
Load and return calibration data.
Expand Down
5 changes: 2 additions & 3 deletions src/ess/snspowder/powgen/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
CalibrationFilename,
Filename,
NeXusDetectorDimensions,
NeXusDetectorName,
ProtonCharge,
RawDataAndMetadata,
ReducibleDetectorData,
Expand Down Expand Up @@ -104,7 +103,7 @@ def pooch_load(filename: Filename[RunType]) -> RawDataAndMetadata[RunType]:

def pooch_load_calibration(
filename: CalibrationFilename,
detector_dimensions: NeXusDetectorDimensions[NeXusDetectorName],
detector_dimensions: NeXusDetectorDimensions,
) -> CalibrationData:
"""Load the calibration data for the POWGEN test data."""
if filename is None:
Expand All @@ -120,7 +119,7 @@ def pooch_load_calibration(


def extract_raw_data(
dg: RawDataAndMetadata[RunType], sizes: NeXusDetectorDimensions[NeXusDetectorName]
dg: RawDataAndMetadata[RunType], sizes: NeXusDetectorDimensions
) -> ReducibleDetectorData[RunType]:
"""Return the events from a loaded data group."""
# Remove the tof binning and dimension, as it is not needed and it gets in the way
Expand Down
5 changes: 2 additions & 3 deletions src/ess/snspowder/powgen/instrument_view.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
from typing import Optional

import scipp as sc
import scippneutron as scn
Expand All @@ -9,8 +8,8 @@
def instrument_view(
da: sc.DataArray,
positions: str = "position",
pixel_size: Optional[float] = None,
components: Optional[dict] = None,
pixel_size: float | None = None,
components: dict | None = None,
**kwargs,
):
"""
Expand Down
Loading