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
847 changes: 421 additions & 426 deletions pixi.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ select = [
# 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
'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
#'C4', # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
'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
Expand All @@ -234,9 +234,9 @@ select = [
#'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
'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
'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
Expand Down
27 changes: 11 additions & 16 deletions src/easydynamics/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ def analysis_list(self) -> list[Analysis1d]:
return self._analysis_list

@analysis_list.setter
def analysis_list(self, value: list[Analysis1d]) -> None:
def analysis_list(self, _value: list[Analysis1d]) -> None:
"""analysis_list is read-only.

To change the analysis list, modify the experiment, sample
model, or instrument model.

Args:
value (list[Analysis1d]): The new list of Analysis1d objects. This
_value (list[Analysis1d]): The new list of Analysis1d objects. This
argument is ignored, as analysis_list is read-only.

Raises:
Expand Down Expand Up @@ -189,12 +189,10 @@ def fit(
if fit_method == 'independent':
if Q_index is not None:
return self._fit_single_Q(Q_index)
else:
return self._fit_all_Q_independently()
elif fit_method == 'simultaneous':
return self._fit_all_Q_independently()
if fit_method == 'simultaneous':
return self._fit_all_Q_simultaneously()
else:
raise ValueError("Invalid fit method. Choose 'independent' or 'simultaneous'.")
raise ValueError("Invalid fit method. Choose 'independent' or 'simultaneous'.")

def plot_data_and_model(
self,
Expand Down Expand Up @@ -407,20 +405,19 @@ def plot_parameters(

data_to_plot = {name: ds[name] for name in names}
plot_kwargs_defaults = {
'linestyle': {name: 'none' for name in names},
'marker': {name: 'o' for name in names},
'markerfacecolor': {name: 'none' for name in names},
'linestyle': dict.fromkeys(names, 'none'),
'marker': dict.fromkeys(names, 'o'),
'markerfacecolor': dict.fromkeys(names, 'none'),
}

plot_kwargs_defaults.update(kwargs)

import plopp as pp

fig = pp.plot(
return pp.plot(
data_to_plot,
**plot_kwargs_defaults,
)
return fig

#############
# Private methods - updating models when things change
Expand Down Expand Up @@ -514,12 +511,11 @@ def _fit_all_Q_simultaneously(self) -> FitResults:
fit_functions=self.get_fit_functions(),
)

results = mf.fit(
return mf.fit(
x=xs,
y=ys,
weights=ws,
)
return results

def get_fit_functions(self) -> list[callable]:
"""Get fit functions for all Q indices, which can be used for
Expand All @@ -546,11 +542,10 @@ def _create_model_array(self, energy: sc.Variable | None = None) -> sc.DataArray
if energy is None:
energy = self.energy
model = sc.array(dims=['Q', 'energy'], values=self.calculate(energy=energy))
model_data_array = sc.DataArray(
return sc.DataArray(
data=model,
coords={'Q': self.Q, 'energy': energy},
)
return model_data_array

def _create_components_dataset(
self,
Expand Down
20 changes: 9 additions & 11 deletions src/easydynamics/analysis/analysis1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ def _calculate(self, energy: sc.Variable | None = None) -> np.ndarray:

background_intensity = self._evaluate_background(energy=energy)

sample_plus_background = sample_intensity + background_intensity

return sample_plus_background
return sample_intensity + background_intensity

def fit(self) -> FitResults:
"""Fit the model to the experimental data for the chosen Q
Expand Down Expand Up @@ -186,7 +184,9 @@ def fit(self) -> FitResults:
return fit_result

def as_fit_function(
self, x: np.ndarray | sc.Variable | None = None, **kwargs: dict[str, Any]
self,
_x: np.ndarray | sc.Variable | None = None,
**kwargs: dict[str, Any], # noqa: ARG002
) -> callable:
"""Return self._calculate as a fit function.

Expand All @@ -196,7 +196,7 @@ def as_fit_function(
calculated model.

Args:
x (np.ndarray | sc.Variable | None, default=None): Ignored.
_x (np.ndarray | sc.Variable | None, default=None): Ignored.
The energy grid is taken from the experiment.
**kwargs (dict[str, Any]): Ignored. Included for compatibility with the
EasyScience fitter.
Expand All @@ -207,8 +207,8 @@ def as_fit_function(
"""

def fit_function(
x: np.ndarray | sc.Variable | None = None,
**kwargs: dict[str, Any],
_x: np.ndarray | sc.Variable | None = None,
**kwargs: dict[str, Any], # noqa: ARG001
) -> np.ndarray:
return self._calculate()

Expand Down Expand Up @@ -299,11 +299,10 @@ def plot_data_and_model(
# Overwrite defaults with any user-provided kwargs
plot_kwargs_defaults.update(kwargs)

fig = pp.plot(
return pp.plot(
data_and_model,
**plot_kwargs_defaults,
)
return fig

#############
# Private methods: small utilities
Expand Down Expand Up @@ -596,14 +595,13 @@ def _create_convolver(
return None

# TODO: allow convolution options to be set.
convolver = Convolution(
return Convolution(
sample_components=sample_components,
resolution_components=resolution_components,
energy=energy,
temperature=self.temperature,
energy_offset=self.instrument_model.get_energy_offset_at_Q(Q_index),
)
return convolver

#############
# Private methods: create scipp arrays for plotting
Expand Down
15 changes: 8 additions & 7 deletions src/easydynamics/analysis/analysis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ def Q(self) -> sc.Variable | None:
return self.experiment.Q

@Q.setter
def Q(self, value: sc.Variable) -> None:
def Q(self, _value: sc.Variable) -> None:
"""Q cannot be set, as it is a read-only property derived from
the Experiment.

Args:
value (sc.Variable): The Q values to set. This argument is
_value (sc.Variable): The Q values to set. This argument is
ignored, as Q is a read-only property.

Raises:
Expand All @@ -214,12 +214,12 @@ def energy(self) -> sc.Variable | None:
return self.experiment.energy

@energy.setter
def energy(self, value: sc.Variable) -> None:
def energy(self, _value: sc.Variable) -> None:
"""Energy cannot be set, as it is a read-only property derived
from the Experiment.

Args:
value (sc.Variable): The energy values to set. This argument is
_value (sc.Variable): The energy values to set. This argument is
ignored, as energy is a read-only property.

Raises:
Expand All @@ -241,13 +241,14 @@ def temperature(self) -> Parameter | None:
return self.sample_model.temperature

@temperature.setter
def temperature(self, value: np.ndarray | Parameter) -> None:
def temperature(self, _value: np.ndarray | Parameter) -> None:
"""Temperature cannot be set, as it is a read-only property
derived from the SampleModel.

Args:
value (np.ndarray | Parameter): The temperature to set. This argument is
ignored, as temperature is a read-only property.
_value (np.ndarray | Parameter): The temperature to set.
This argument is ignored, as temperature is a read-only
property.

Raises:
AttributeError: If trying to set temperature.
Expand Down
3 changes: 1 addition & 2 deletions src/easydynamics/convolution/analytical_convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ def _convolute_analytic_pair(
# Call the corresponding method
if swapped:
return getattr(self, func_name)(resolution_component, sample_component)
else:
return getattr(self, func_name)(sample_component, resolution_component)
return getattr(self, func_name)(sample_component, resolution_component)

def _convolute_delta_any(
self,
Expand Down
6 changes: 3 additions & 3 deletions src/easydynamics/convolution/convolution_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ def energy_with_offset(self) -> sc.Variable:
return energy_with_offset

@energy_with_offset.setter
def energy_with_offset(self, value: sc.Variable) -> None:
def energy_with_offset(self, _value: sc.Variable) -> None:
"""Energy with offset is a read-only property derived from
energy and energy_offset.

Args:
value (sc.Variable): The value to set (ignored).
_value (sc.Variable): The value to set (ignored).

Raises:
AttributeError: Always raised since energy_with_offset is
Expand Down Expand Up @@ -192,7 +192,7 @@ def energy_unit(self) -> str:
return self._energy_unit

@energy_unit.setter
def energy_unit(self, unit_str: str) -> None:
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.'
Expand Down
4 changes: 1 addition & 3 deletions src/easydynamics/convolution/numerical_convolution_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,14 @@ def _create_energy_grid(
else:
energy_dense_centered = energy_dense

energy_grid = EnergyGrid(
return EnergyGrid(
energy_dense=energy_dense,
energy_dense_centered=energy_dense_centered,
energy_dense_step=energy_dense_step,
energy_span_dense=energy_span_dense,
energy_even_length_offset=energy_even_length_offset,
)

return energy_grid

def _check_width_thresholds(
self,
model: ComponentCollection | ModelComponent,
Expand Down
24 changes: 11 additions & 13 deletions src/easydynamics/experiment/experiment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: 2026 EasyScience contributors <https://github.com/easyscience>
# SPDX-License-Identifier: BSD-3-Clause

import os

from pathlib import Path

import numpy as np
import plopp as pp
Expand Down Expand Up @@ -105,12 +106,12 @@ def binned_data(self) -> sc.DataArray | None:
return self._binned_data

@binned_data.setter
def binned_data(self, value: sc.DataArray) -> None:
def binned_data(self, _value: sc.DataArray) -> None:
"""Set the binned dataset associated with this experiment. Read-
only property. Use rebin() to rebin the data instead.

Args:
value (sc.DataArray): The new binned dataset to associate
_value (sc.DataArray): The new binned dataset to associate
with this experiment (ignored)

Raises:
Expand All @@ -131,12 +132,12 @@ def Q(self) -> sc.Variable | None:
return self._binned_data.coords['Q']

@Q.setter
def Q(self, value: sc.Variable) -> None:
def Q(self, _value: sc.Variable) -> None:
"""Set the Q values for the dataset. Q is a read-only property
derived from the data, so this setter raises an error.

Args:
value (sc.Variable): The new Q values to set (ignored)
_value (sc.Variable): The new Q values to set (ignored)

Raises:
AttributeError: Always, since Q is read-only.
Expand All @@ -156,12 +157,12 @@ def energy(self) -> sc.Variable | None:
return self._binned_data.coords['energy']

@energy.setter
def energy(self, value: sc.Variable) -> None:
def energy(self, _value: sc.Variable) -> None:
"""Set the energy values for the dataset. Energy is a read-only
property derived from the data, so this setter raises an error.

Args:
value (sc.Variable): The new energy values to set (ignored)
_value (sc.Variable): The new energy values to set (ignored)

Raises:
AttributeError: Always, since energy is read-only.
Expand Down Expand Up @@ -197,8 +198,7 @@ def get_masked_energy(self, Q_index: int) -> sc.Variable | None:
_, _, _, mask = self._extract_x_y_weights_only_finite(Q_index=Q_index)

mask_var = sc.array(dims=['energy'], values=mask)
masked_energy = energy[mask_var]
return masked_energy
return energy[mask_var]

###########
# Handle data
Expand Down Expand Up @@ -256,10 +256,8 @@ def save_hdf5(self, filename: str | None = None) -> None:
if self._data is None:
raise ValueError('No data to save.')

dir_name = os.path.dirname(filename)
if dir_name:
os.makedirs(dir_name, exist_ok=True)

path = Path(filename)
path.parent.mkdir(exist_ok=True, parents=True)
sc_save_hdf5(self._data, filename)

def remove_data(self) -> None:
Expand Down
Loading
Loading