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
10 changes: 2 additions & 8 deletions docs/docs/tutorials/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@
" instrument_model=instrument_model,\n",
")\n",
"\n",
"# We need to hack in the resolution model from the vanadium analysis,\n",
"# since the setters and getters overwrite the model. This will be fixed\n",
"# asap.\n",
"diffusion_analysis.instrument_model._resolution_model = (\n",
"diffusion_analysis.instrument_model.resolution_model = (\n",
" vanadium_analysis.instrument_model.resolution_model\n",
")\n",
"\n",
Expand Down Expand Up @@ -305,10 +302,7 @@
" instrument_model=instrument_model,\n",
")\n",
"\n",
"# We again need to hack in the resolution model from the vanadium\n",
"# analysis, since the setters and getters overwrite the model. This will\n",
"# be fixed asap.\n",
"diffusion_model_analysis.instrument_model._resolution_model = (\n",
"diffusion_model_analysis.instrument_model.resolution_model = (\n",
" vanadium_analysis.instrument_model.resolution_model\n",
")\n",
"diffusion_model_analysis.instrument_model.resolution_model.fix_all_parameters()\n",
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/tutorials/tutorial2_nanoparticles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "bca91d3c",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -70,15 +70,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "4fbb90da",
"metadata": {},
"outputs": [],
"source": [
"resolution_experiment = Experiment(display_name='Nanoparticles, 1.5 K')\n",
"\n",
"file_path = pooch.retrieve(\n",
" url='https://github.com/easyscience/dynamics-lib/raw/refs/heads/tutorial2/docs/docs/tutorials/data/nano_1p5K.h5',\n",
" url='https://github.com/easyscience/dynamics-lib/raw/refs/heads/master/docs/docs/tutorials/data/nano_1p5K.h5',\n",
" known_hash='32935cfaa5e623137ea5f4ba972d0c921bca8d0e067486666cdcf23abf27823e',\n",
")\n",
"\n",
Expand Down Expand Up @@ -216,7 +216,7 @@
"resolution_experiment = Experiment(display_name='Nanoparticles, 1.5 K')\n",
"\n",
"file_path = pooch.retrieve(\n",
" url='https://github.com/easyscience/dynamics-lib/raw/refs/heads/tutorial2/docs/docs/tutorials/data/nano_150K.h5',\n",
" url='https://github.com/easyscience/dynamics-lib/raw/refs/heads/master/docs/docs/tutorials/data/nano_150K.h5',\n",
" known_hash='dc3abdaf6d2165f4dbc5df4e0de1890af8d4cd290f2c79ac7b319ccbe44117b8',\n",
")\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 36 additions & 36 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ select = [
#'FURB', # https://docs.astral.sh/ruff/rules/#refurb-furb
'I', # https://docs.astral.sh/ruff/rules/#isort-i
#'N', # https://docs.astral.sh/ruff/rules/#pep8-naming-n
#'NPY', # https://docs.astral.sh/ruff/rules/#numpy-specific-rules-npy
'NPY', # https://docs.astral.sh/ruff/rules/#numpy-specific-rules-npy
#'PGH', # https://docs.astral.sh/ruff/rules/#pygrep-hooks-pgh
#'PERF', # https://docs.astral.sh/ruff/rules/#perflint-perf
#'RUF', # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
#'TRY', # https://docs.astral.sh/ruff/rules/#tryceratops-try
'PERF', # https://docs.astral.sh/ruff/rules/#perflint-perf
'RUF', # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
#'TRY', # https://docs.astral.sh/ruff/rules/#tryceratops-try # overly restrictive
'UP', # https://docs.astral.sh/ruff/rules/#pyupgrade-up
# pycodestyle (E, W) rules
'E', # https://docs.astral.sh/ruff/rules/#error-e
Expand All @@ -215,49 +215,48 @@ select = [
#'PLC', # https://docs.astral.sh/ruff/rules/#convention-plc
#'PLE', # https://docs.astral.sh/ruff/rules/#error-ple
#'PLR', # https://docs.astral.sh/ruff/rules/#refactor-plr
#'PLW', # https://docs.astral.sh/ruff/rules/#warning-plw
#'PLW', # https://docs.astral.sh/ruff/rules/#warning-plw # Good to enable
# flake8 rules
'A', # https://docs.astral.sh/ruff/rules/#flake8-builtins-a
'ANN', # https://docs.astral.sh/ruff/rules/#flake8-annotations-ann
'ARG', # https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg
#'ASYNC', # https://docs.astral.sh/ruff/rules/#flake8-async-async
'B', # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
#'BLE', # https://docs.astral.sh/ruff/rules/#flake8-blind-except-ble
'A', # https://docs.astral.sh/ruff/rules/#flake8-builtins-a
'ANN', # https://docs.astral.sh/ruff/rules/#flake8-annotations-ann
'ARG', # https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg
'ASYNC', # https://docs.astral.sh/ruff/rules/#flake8-async-async
'B', # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
#'BLE', # https://docs.astral.sh/ruff/rules/#flake8-blind-except-ble # enable when base classes have been merged in
'C4', # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
'COM', # https://docs.astral.sh/ruff/rules/#flake8-commas-com
#'DTZ', # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz
#'EM', # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em
'DTZ', # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz
#'EM', # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em # Unsure if I want it - requires all error messages to be rewritten
'FA', # https://docs.astral.sh/ruff/rules/#flake8-future-annotations-fa
#'FBT', # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
#'FIX', # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix
#'G', # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
#'ICN', # https://docs.astral.sh/ruff/rules/#flake8-import-conventions-icn
#'INP', # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp
#'ISC', # https://docs.astral.sh/ruff/rules/#flake8-implicit-str-concat-isc
#'LOG', # https://docs.astral.sh/ruff/rules/#flake8-logging-log
#'PIE', # https://docs.astral.sh/ruff/rules/#flake8-pie-pie
#'PT', # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
'PTH', # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
#'PYI', # https://docs.astral.sh/ruff/rules/#flake8-pyi-pyi
'RET', # https://docs.astral.sh/ruff/rules/#flake8-return-ret
#'RSE', # https://docs.astral.sh/ruff/rules/#flake8-raise-rse
'S', # https://docs.astral.sh/ruff/rules/#flake8-bandit-s
'SIM', # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
#'SLF', # https://docs.astral.sh/ruff/rules/#flake8-self-slf
#'SLOT', # https://docs.astral.sh/ruff/rules/#flake8-slots-slot
#'T20', # https://docs.astral.sh/ruff/rules/#flake8-print-t20
'TC', # https://docs.astral.sh/ruff/rules/#flake8-type-checking-tc
#'TD', # https://docs.astral.sh/ruff/rules/#flake8-todos-td
'TID', # https://docs.astral.sh/ruff/rules/#flake8-tidy-imports-tid
#'FBT', # https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt # should eventually be enabled, but may break serialization
'FIX', # https://docs.astral.sh/ruff/rules/#flake8-fixme-fix
'G', # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
'ICN', # https://docs.astral.sh/ruff/rules/#flake8-import-conventions-icn
'INP', # https://docs.astral.sh/ruff/rules/#flake8-no-pep420-inp
'ISC', # https://docs.astral.sh/ruff/rules/#flake8-implicit-str-concat-isc
'LOG', # https://docs.astral.sh/ruff/rules/#flake8-logging-log
'PIE', # https://docs.astral.sh/ruff/rules/#flake8-pie-pie
#'PT', # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt # Should eventually be enabled, but quite a few errors to fix
'PTH', # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
'PYI', # https://docs.astral.sh/ruff/rules/#flake8-pyi-pyi
'RET', # https://docs.astral.sh/ruff/rules/#flake8-return-ret
'RSE', # https://docs.astral.sh/ruff/rules/#flake8-raise-rse
'S', # https://docs.astral.sh/ruff/rules/#flake8-bandit-s
'SIM', # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
'SLF', # https://docs.astral.sh/ruff/rules/#flake8-self-slf
'SLOT', # https://docs.astral.sh/ruff/rules/#flake8-slots-slot
'T20', # https://docs.astral.sh/ruff/rules/#flake8-print-t20
'TC', # https://docs.astral.sh/ruff/rules/#flake8-type-checking-tc
'TD', # https://docs.astral.sh/ruff/rules/#flake8-todos-td
'TID', # https://docs.astral.sh/ruff/rules/#flake8-tidy-imports-tid
]

# Exceptions to the linting rules

# Ignore specific rules globally
ignore = [
'COM812', # https://docs.astral.sh/ruff/rules/missing-trailing-comma/
# The following is replaced by 'D'/[tool.ruff.lint.pydocstyle] and [tool.pydoclint]
'DOC', # https://docs.astral.sh/ruff/rules/#pydoclint-doc
# The following is replaced by 'D'/[tool.ruff.lint.pydocstyle] and [tool.pydoclint] 'DOC', # https://docs.astral.sh/ruff/rules/#pydoclint-doc
# Disable, as [tool.format_docstring] split one-line docstrings into the canonical multi-line layout
'D200', # https://docs.astral.sh/ruff/rules/unnecessary-multiline-docstring/
]
Expand All @@ -273,6 +272,7 @@ ignore = [
'DOC', # https://docs.astral.sh/ruff/rules/#pydoclint-doc
'INP001', # https://docs.astral.sh/ruff/rules/implicit-namespace-package/
'S101', # https://docs.astral.sh/ruff/rules/assert/
'SLF', # https://docs.astral.sh/ruff/rules/#flake8-self-slf # may want to eventually enable it, but accessing private methods is quite useful in tests
]
'docs/**' = [
'INP001', # https://docs.astral.sh/ruff/rules/implicit-namespace-package/
Expand Down
14 changes: 9 additions & 5 deletions src/easydynamics/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,14 +567,18 @@ def _fit_all_Q_simultaneously(self) -> FitResults:
ys = []
ws = []

for analysis in self.analysis_list:
x, y, weight, _ = self.experiment._extract_x_y_weights_only_finite(analysis.Q_index)
for analysis1d in self.analysis_list:
x, y, weight, _ = self.experiment._extract_x_y_weights_only_finite( # noqa: SLF001
analysis1d.Q_index
)
xs.append(x)
ys.append(y)
ws.append(weight)

# Make sure the convolver is up to date for this Q index
analysis._convolver = analysis._create_convolver(energy=x)
analysis1d._convolver = analysis1d._create_convolver( # noqa: SLF001
energy=x
)

mf = MultiFitter(
fit_objects=self.analysis_list,
Expand Down Expand Up @@ -655,10 +659,10 @@ def _create_components_dataset(
energy = self.energy

datasets = [
analysis._create_components_dataset_single_Q(
analysis1d._create_components_dataset_single_Q( # noqa: SLF001
add_background=add_background, energy=energy
)
for analysis in self.analysis_list
for analysis1d in self.analysis_list
]

return sc.concat(datasets, dim='Q')
Expand Down
3 changes: 1 addition & 2 deletions src/easydynamics/analysis/analysis1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def fit(self) -> FitResults:
fit_function=self.as_fit_function(),
)

x, y, weights, _ = self.experiment._extract_x_y_weights_only_finite(
x, y, weights, _ = self.experiment._extract_x_y_weights_only_finite( # noqa: SLF001
Q_index=self._require_Q_index()
)
fit_result = fitter.fit(x=x, y=y, weights=weights)
Expand Down Expand Up @@ -671,7 +671,6 @@ def _create_convolver(
if resolution_components.is_empty:
return None

# TODO: allow convolution options to be set.
return Convolution(
sample_components=sample_components,
resolution_components=resolution_components,
Expand Down
4 changes: 3 additions & 1 deletion src/easydynamics/convolution/analytical_convolution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-FileCopyrightText: 2026 EasyScience contributors <https://github.com/easyscience>
# SPDX-License-Identifier: BSD-3-Clause

from typing import ClassVar

import numpy as np
import scipp as sc
from easyscience.variable import Parameter
Expand All @@ -26,7 +28,7 @@ class AnalyticalConvolution(ConvolutionBase):

# Mapping of supported component type pairs to convolution methods.
# Delta functions are handled separately.
_CONVOLUTIONS = {
_CONVOLUTIONS: ClassVar[dict[str, object]] = {
('Gaussian', 'Gaussian'): '_convolute_gaussian_gaussian',
('Gaussian', 'Lorentzian'): '_convolute_gaussian_lorentzian',
('Gaussian', 'Voigt'): '_convolute_gaussian_voigt',
Expand Down
13 changes: 7 additions & 6 deletions src/easydynamics/convolution/convolution.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-FileCopyrightText: 2026 EasyScience contributors <https://github.com/easyscience>
# SPDX-License-Identifier: BSD-3-Clause

from typing import ClassVar

import numpy as np
import scipp as sc
from easyscience.variable import Parameter
Expand Down Expand Up @@ -33,7 +35,7 @@ class Convolution(NumericalConvolutionBase):

# When these attributes are changed, the convolution plan
# needs to be rebuilt
_invalidate_plan_on_change = {
_invalidate_plan_on_change: ClassVar[dict[str, object]] = {
'energy',
'_energy',
'_energy_grid',
Expand Down Expand Up @@ -231,11 +233,10 @@ def _build_convolution_plan(self) -> None:
# If temperature is not set, check if all
# resolution components can be convolved analytically with
# this sample component
pair_is_analytic = []
for resolution_component in self._resolution_components.components:
pair_is_analytic.append(
self._check_if_pair_is_analytic(sample_component, resolution_component)
)
pair_is_analytic = [
self._check_if_pair_is_analytic(sample_component, resolution_component)
for resolution_component in self._resolution_components.components
]
# If all resolution components can be convolved analytically
# with this sample component, add it to analytical
# sample model. If not, it goes to numerical sample model.
Expand Down
2 changes: 1 addition & 1 deletion src/easydynamics/convolution/convolution_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def energy_unit(self, _unit_str: str) -> None:
raise AttributeError(
f'Unit is read-only. Use convert_unit to change the unit between allowed types '
f'or create a new {self.__class__.__name__} with the desired unit.'
) # noqa: E501
)

def convert_energy_unit(self, energy_unit: str | sc.Unit) -> None:
"""
Expand Down
4 changes: 2 additions & 2 deletions src/easydynamics/convolution/numerical_convolution_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ def __repr__(self) -> str:
return (
f'{self.__class__.__name__}('
f'energy=array of shape {self.energy.values.shape},\n '
f'sample_components={repr(self.sample_components)}, \n'
f'resolution_components={repr(self.resolution_components)},\n '
f'sample_components={self.sample_components!r}, \n'
f'resolution_components={self.resolution_components!r},\n '
f'energy_unit={self._energy_unit}, '
f'upsample_factor={self.upsample_factor}, '
f'extension_factor={self.extension_factor}, '
Expand Down
18 changes: 9 additions & 9 deletions src/easydynamics/sample_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
from easydynamics.sample_model.sample_model import SampleModel

__all__ = [
'BackgroundModel',
'BrownianTranslationalDiffusion',
'ComponentCollection',
'DampedHarmonicOscillator',
'DeltaFunction',
'Exponential',
'ExpressionComponent',
'Gaussian',
'InstrumentModel',
'Lorentzian',
'Voigt',
'DeltaFunction',
'DampedHarmonicOscillator',
'Polynomial',
'Exponential',
'BrownianTranslationalDiffusion',
'SampleModel',
'ResolutionModel',
'BackgroundModel',
'InstrumentModel',
'ExpressionComponent',
'SampleModel',
'Voigt',
]
2 changes: 1 addition & 1 deletion src/easydynamics/sample_model/component_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def unit(self, _unit_str: str) -> None:
raise AttributeError(
f'Unit is read-only. Use convert_unit to change the unit between allowed types '
f'or create a new {self.__class__.__name__} with the desired unit.'
) # noqa: E501
)

def convert_unit(self, unit: str | sc.Unit) -> None:
"""
Expand Down
10 changes: 5 additions & 5 deletions src/easydynamics/sample_model/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
from easydynamics.sample_model.components.voigt import Voigt

__all__ = [
'Gaussian',
'Lorentzian',
'Voigt',
'DeltaFunction',
'DampedHarmonicOscillator',
'Polynomial',
'DeltaFunction',
'Exponential',
'ExpressionComponent',
'Gaussian',
'Lorentzian',
'Polynomial',
'Voigt',
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import ClassVar

import sympy as sp
from easyscience.variable import Parameter
Expand All @@ -29,7 +30,7 @@ class ExpressionComponent(ModelComponent):
# -------------------------
# Allowed symbolic functions
# -------------------------
_ALLOWED_FUNCS = {
_ALLOWED_FUNCS: ClassVar[dict[str, object]] = {
# Exponentials & logs
'exp': sp.exp,
'log': sp.log,
Expand Down Expand Up @@ -62,12 +63,12 @@ class ExpressionComponent(ModelComponent):
# -------------------------
# Allowed constants
# -------------------------
_ALLOWED_CONSTANTS = {
_ALLOWED_CONSTANTS: ClassVar[dict[str, object]] = {
'pi': sp.pi,
'E': sp.E,
}

_RESERVED_NAMES = {'x'}
_RESERVED_NAMES: ClassVar[dict[str, object]] = {'x'}

def __init__(
self,
Expand Down
Loading
Loading