diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6b48cbb..79b563b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,12 +3,12 @@ repos: # FORMATTER # ################### - repo: https://github.com/tox-dev/pyproject-fmt - rev: "2.1.4" + rev: "v2.11.1" hooks: - id: pyproject-fmt - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v6.0.0 hooks: - id: check-ast - id: check-builtin-literals @@ -20,7 +20,7 @@ repos: args: [--fix=lf] - repo: https://github.com/PyCQA/docformatter - rev: 06907d0 + rev: v1.7.7 hooks: - id: docformatter additional_dependencies: [tomli] @@ -43,7 +43,7 @@ repos: ################### - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.5.1 + rev: v0.14.10 hooks: - id: ruff name: "ruff sort imports" @@ -58,7 +58,7 @@ repos: name: "ruff lint" - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.10.1 + rev: v1.19.1 hooks: - id: mypy exclude: "docs" @@ -68,7 +68,7 @@ repos: # LINTER DOCS # ################### - repo: https://github.com/PyCQA/flake8 - rev: 7.1.0 + rev: 7.3.0 hooks: - id: flake8 alias: flake8-docs @@ -91,7 +91,7 @@ repos: pass_filenames: false - repo: https://github.com/codespell-project/codespell - rev: v2.3.0 + rev: v2.4.1 hooks: - id: codespell types: [file] @@ -100,6 +100,6 @@ repos: exclude: ^examples/ - repo: https://github.com/rhysd/actionlint - rev: "v1.7.1" + rev: "v1.7.9" hooks: - id: actionlint diff --git a/pyparamgui/generator.py b/pyparamgui/generator.py index 9d49b6b..1b69a11 100644 --- a/pyparamgui/generator.py +++ b/pyparamgui/generator.py @@ -38,8 +38,8 @@ def _generate_decay_model( dict[str, Any] The generated model dictionary. """ - compartments = [f"species_{i+1}" for i in range(nr_compartments)] - rates = [f"rates.species_{i+1}" for i in range(nr_compartments)] + compartments = [f"species_{i + 1}" for i in range(nr_compartments)] + rates = [f"rates.species_{i + 1}" for i in range(nr_compartments)] model: dict[str, Any] = { "megacomplex": { @@ -56,18 +56,18 @@ def _generate_decay_model( "megacomplex_spectral": { "type": "spectral", "shape": { - compartment: f"shape_species_{i+1}" + compartment: f"shape_species_{i + 1}" for i, compartment in enumerate(compartments) }, } } model["shape"] = { - f"shape_species_{i+1}": { + f"shape_species_{i + 1}": { "type": "skewed-gaussian", - "amplitude": f"shapes.species_{i+1}.amplitude", - "location": f"shapes.species_{i+1}.location", - "width": f"shapes.species_{i+1}.width", - "skewness": f"shapes.species_{i+1}.skewness", + "amplitude": f"shapes.species_{i + 1}.amplitude", + "location": f"shapes.species_{i + 1}.location", + "width": f"shapes.species_{i + 1}.width", + "skewness": f"shapes.species_{i + 1}.skewness", } for i in range(nr_compartments) } diff --git a/pyparamgui/schema.py b/pyparamgui/schema.py index 260177c..586dc7a 100644 --- a/pyparamgui/schema.py +++ b/pyparamgui/schema.py @@ -13,9 +13,7 @@ class KineticParameters(BaseModel): """Kinetic parameters for the simulation. - Attributes - ---------- - decay_rates (list[float]): List of decay rates. + Attributes ---------- decay_rates (list[float]): List of decay rates. """ decay_rates: list[float] @@ -24,12 +22,9 @@ class KineticParameters(BaseModel): class SpectralParameters(BaseModel): """Spectral parameters for the simulation. - Attributes - ---------- - amplitude (list[float]): List of amplitudes. - location (list[float]): List of locations. - width (list[float]): List of widths. - skewness (list[float]): List of skewness values. + Attributes ---------- amplitude (list[float]): List of amplitudes. location + (list[float]): List of locations. width (list[float]): List of widths. skewness + (list[float]): List of skewness values. """ amplitude: list[float] @@ -41,10 +36,8 @@ class SpectralParameters(BaseModel): class TimeCoordinates(BaseModel): """Time coordinates for the simulation. - Attributes - ---------- - timepoints_max (int): Maximum number of time points. - timepoints_stepsize (float): Step size between time points. + Attributes ---------- timepoints_max (int): Maximum number of time points. + timepoints_stepsize (float): Step size between time points. """ timepoints_max: int @@ -54,11 +47,8 @@ class TimeCoordinates(BaseModel): class SpectralCoordinates(BaseModel): """Spectral coordinates for the simulation. - Attributes - ---------- - wavelength_min (int): Minimum wavelength. - wavelength_max (int): Maximum wavelength. - wavelength_stepsize (float): Step size between wavelengths. + Attributes ---------- wavelength_min (int): Minimum wavelength. wavelength_max (int): + Maximum wavelength. wavelength_stepsize (float): Step size between wavelengths. """ wavelength_min: int @@ -98,14 +88,11 @@ def generate_simulation_coordinates( class Settings(BaseModel): """Other settings for the simulation. - Attributes - ---------- - stdev_noise (float): Standard deviation of the noise to be added to the simulation data. - seed (int): Seed for the random number generator to ensure reproducibility. - add_gaussian_irf (bool): Whether to add a Gaussian IRF to the simulation. - Default is False. - use_sequential_scheme (bool): Whether to use a sequential scheme in the simulation. - Default is False. + Attributes ---------- stdev_noise (float): Standard deviation of the noise to be added to + the simulation data. seed (int): Seed for the random number generator to ensure + reproducibility. add_gaussian_irf (bool): Whether to add a Gaussian IRF to the simulation. + Default is False. use_sequential_scheme (bool): Whether to use a sequential scheme in the + simulation. Default is False. """ stdev_noise: float @@ -117,10 +104,8 @@ class Settings(BaseModel): class IRF(BaseModel): """Instrument Response Function (IRF) settings for the simulation. - Attributes - ---------- - center (float): The center position of the IRF. - width (float): The width of the IRF. + Attributes ---------- center (float): The center position of the IRF. width (float): + The width of the IRF. """ center: float @@ -130,15 +115,13 @@ class IRF(BaseModel): class SimulationConfig(BaseModel): """Configuration for the simulation, combining various parameters and settings. - Attributes - ---------- - kinetic_parameters (KineticParameters): Kinetic parameters for the simulation. - spectral_parameters (SpectralParameters): Spectral parameters for the simulation. - coordinates (Dict[str, np.ndarray]): Dictionary containing the time and spectral axes as - numpy arrays. - settings (Settings): Other settings for the simulation, including noise standard deviation, - random seed, and flags for adding Gaussian IRF and using a sequential scheme. - irf (IRF): Instrument Response Function (IRF) settings, e.g. center position and width. + Attributes ---------- kinetic_parameters (KineticParameters): Kinetic parameters for the + simulation. spectral_parameters (SpectralParameters): Spectral parameters for the + simulation. coordinates (Dict[str, np.ndarray]): Dictionary containing the time and + spectral axes as numpy arrays. settings (Settings): Other settings for the + simulation, including noise standard deviation, random seed, and flags for adding + Gaussian IRF and using a sequential scheme. irf (IRF): Instrument Response Function (IRF) + settings, e.g. center position and width. """ kinetic_parameters: KineticParameters diff --git a/pyparamgui/widget.py b/pyparamgui/widget.py index c11476b..7ac7b4b 100644 --- a/pyparamgui/widget.py +++ b/pyparamgui/widget.py @@ -23,31 +23,24 @@ class Widget(anywidget.AnyWidget): """A widget class for handling simulation parameters, coordinates and settings. - Attributes - ---------- - _esm (pathlib.Path): Path to the JavaScript file for the widget. - _css (pathlib.Path): Path to the CSS file for the widget. - decay_rates_input (traitlets.List): List of decay rates as floats. - amplitude_input (traitlets.List): List of amplitudes as floats. - location_input (traitlets.List): List of locations as floats. - width_input (traitlets.List): List of widths as floats. - skewness_input (traitlets.List): List of skewness values as floats. - timepoints_max_input (traitlets.Int): Maximum number of timepoints. - timepoints_stepsize_input (traitlets.Float): Step size for timepoints. - wavelength_min_input (traitlets.Float): Minimum wavelength value. - wavelength_max_input (traitlets.Float): Maximum wavelength value. - wavelength_stepsize_input (traitlets.Float): Step size for wavelength. - stdev_noise_input (traitlets.Float): Standard deviation of noise. - seed_input (traitlets.Int): Seed for random number generation. - add_gaussian_irf_input (traitlets.Bool): Flag to add Gaussian IRF. - irf_location_input (traitlets.Float): Location of the IRF center. - irf_width_input (traitlets.Float): Width of the IRF. - use_sequential_scheme_input (traitlets.Bool): Flag to use sequential scheme. - model_file_name_input (traitlets.Unicode): Name of the model file. - parameter_file_name_input (traitlets.Unicode): Name of the parameter file. - data_file_name_input (traitlets.Unicode): Name of the data file. - simulate (traitlets.Unicode): Trigger for simulation. - visualize_data (traitlets.Bool): Flag to visualize data. + Attributes ---------- _esm (pathlib.Path): Path to the JavaScript file for the widget. _css + (pathlib.Path): Path to the CSS file for the widget. decay_rates_input (traitlets.List): + List of decay rates as floats. amplitude_input (traitlets.List): List of amplitudes as + floats. location_input (traitlets.List): List of locations as floats. width_input + (traitlets.List): List of widths as floats. skewness_input (traitlets.List): List of + skewness values as floats. timepoints_max_input (traitlets.Int): Maximum number of + timepoints. timepoints_stepsize_input (traitlets.Float): Step size for timepoints. + wavelength_min_input (traitlets.Float): Minimum wavelength value. wavelength_max_input + (traitlets.Float): Maximum wavelength value. wavelength_stepsize_input (traitlets.Float): + Step size for wavelength. stdev_noise_input (traitlets.Float): Standard deviation of noise. + seed_input (traitlets.Int): Seed for random number generation. add_gaussian_irf_input + (traitlets.Bool): Flag to add Gaussian IRF. irf_location_input (traitlets.Float): Location + of the IRF center. irf_width_input (traitlets.Float): Width of the IRF. + use_sequential_scheme_input (traitlets.Bool): Flag to use sequential scheme. + model_file_name_input (traitlets.Unicode): Name of the model file. parameter_file_name_input + (traitlets.Unicode): Name of the parameter file. data_file_name_input (traitlets.Unicode): Name + of the data file. simulate (traitlets.Unicode): Trigger for simulation. visualize_data + (traitlets.Bool): Flag to visualize data. """ _esm: pathlib.Path = pathlib.Path(__file__).parent / "static" / "form.js" diff --git a/pyproject.toml b/pyproject.toml index 98082cb..397a34c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,7 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ] dynamic = [ "version", diff --git a/tests/test_simulate.py b/tests/test_simulate.py index fbb44c6..db96a59 100644 --- a/tests/test_simulate.py +++ b/tests/test_simulate.py @@ -36,13 +36,13 @@ def _create_mock_widget(): return widget -@pytest.fixture() +@pytest.fixture def mock_widget(): """Return a mock Widget for testing.""" return _create_mock_widget() -@pytest.fixture() +@pytest.fixture def temp_dir(): """Create a temporary directory for testing.""" with tempfile.TemporaryDirectory() as tmpdirname: