diff --git a/.github/workflows/distribution.yml b/.github/workflows/distribution.yml index 63e9c51..61aa724 100644 --- a/.github/workflows/distribution.yml +++ b/.github/workflows/distribution.yml @@ -2,42 +2,47 @@ name: distribute on: workflow_dispatch: + pull_request: push: - tags: "v*" + branches: + - main release: types: - published -jobs: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + FORCE_COLOR: 3 +jobs: dist: + name: Distribution build runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Build SDist and wheel - run: pipx run build - - - uses: actions/upload-artifact@v4 - with: - path: dist/* + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Check metadata - run: pipx run twine check dist/* + - uses: hynek/build-and-inspect-python-package@v2 publish: needs: [dist] + name: Publish to PyPI + environment: pypi + permissions: + id-token: write runs-on: ubuntu-latest if: github.event_name == 'release' && github.event.action == 'published' steps: - - uses: actions/download-artifact@v4 - with: - name: artifact - path: dist - - - uses: pypa/gh-action-pypi-publish@v1.8.11 - with: - password: ${{ secrets.pypi_password }} + - uses: actions/download-artifact@v4 + with: + name: Packages + path: dist + + - uses: pypa/gh-action-pypi-publish@release/v1 + if: github.event_name == 'release' && github.event.action == 'published' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3ee4acf..0041c22 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,41 +1,46 @@ -name: legend-geom-optics +name: legendoptics on: + workflow_dispatch: + pull_request: push: branches: - main - - 'releases/**' - pull_request: - release: + - "releases/**" -jobs: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +env: + FORCE_COLOR: 3 + +jobs: build-and-test: name: Test legendoptics with Python runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - python-version: ['3.9', '3.10', '3.11'] + python-version: ["3.9", "3.10", "3.11"] os: [ubuntu-latest, macOS-latest] steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Get dependencies and install the legendoptics - run: | - python -m pip install --upgrade pip wheel setuptools - python -m pip install --upgrade .[test] - - name: Run unit tests - run: | - pytest + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Get dependencies and install legendoptics + run: | + python -m pip install --upgrade pip wheel setuptools + python -m pip install --upgrade .[test] + - name: Run unit tests + run: | + python -m pytest test-coverage: name: Calculate and upload test coverage - needs: build-and-test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -43,19 +48,18 @@ jobs: fetch-depth: 2 - uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: "3.10" - name: Generate Report run: | python -m pip install --upgrade pip wheel setuptools python -m pip install --upgrade .[test] - pytest --cov=legendoptics --cov-report=xml + python -m pytest --cov=legendoptics --cov-report=xml - name: Upload Coverage to codecov.io uses: codecov/codecov-action@v4 build-docs: name: Build documentation - needs: build-and-test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -63,11 +67,12 @@ jobs: fetch-depth: 0 - uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: "3.10" - name: Setup build environment run: | + sudo apt-get install -y pandoc python -m pip install --upgrade pip wheel setuptools - python -m pip install --upgrade .[docs] + python -m pip install --upgrade .[all] - name: Build docs for current ref run: | cd docs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4e5c718..35e400e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,108 +1,88 @@ ci: autoupdate_commit_msg: "chore: update pre-commit hooks" - autoupdate_schedule: "monthly" + autoupdate_schedule: "quarterly" autofix_commit_msg: "style: pre-commit fixes" repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v4.5.0" - hooks: - - id: check-added-large-files - - id: check-case-conflict - - id: check-executables-have-shebangs - - id: check-merge-conflict - - id: check-symlinks - - id: check-yaml - - id: check-json - - id: check-toml - - id: check-docstring-first - - id: debug-statements - - id: end-of-file-fixer - - id: forbid-new-submodules - - id: mixed-line-ending - - id: requirements-txt-fixer - - id: trailing-whitespace + - repo: https://github.com/adamchainz/blacken-docs + rev: "1.16.0" + hooks: + - id: blacken-docs + additional_dependencies: [black==23.*] -- repo: https://github.com/asottile/setup-cfg-fmt - rev: "v2.5.0" - hooks: - - id: setup-cfg-fmt + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: "v4.5.0" + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: forbid-new-submodules + - id: mixed-line-ending + - id: name-tests-test + args: ["--pytest-test-first"] + - id: requirements-txt-fixer + - id: trailing-whitespace -- repo: https://github.com/PyCQA/isort - rev: "5.13.2" - hooks: - - id: isort + - repo: https://github.com/pre-commit/pygrep-hooks + rev: "v1.10.0" + hooks: + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal -- repo: https://github.com/asottile/pyupgrade - rev: "v3.15.0" - hooks: - - id: pyupgrade - args: ["--py36-plus"] + - repo: https://github.com/pre-commit/mirrors-prettier + rev: "v4.0.0-alpha.8" + hooks: + - id: prettier + types_or: [yaml, markdown, json] + args: [--prose-wrap=always] -- repo: https://github.com/psf/black - rev: "24.1.1" - hooks: - - id: black + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.2.1" + hooks: + - id: ruff + args: ["--fix", "--show-fixes"] + - id: ruff-format -- repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.8.0" - hooks: - - id: mypy - files: src - stages: [manual] + - repo: https://github.com/pre-commit/mirrors-mypy + rev: "v1.8.0" + hooks: + - id: mypy + files: src|tests + stages: [manual] + additional_dependencies: + - pytest -- repo: https://github.com/hadialqattan/pycln - rev: "v2.4.0" - hooks: - - id: pycln - args: ["--all"] + - repo: https://github.com/codespell-project/codespell + rev: "v2.2.6" + hooks: + - id: codespell -- repo: https://github.com/PyCQA/flake8 - rev: "7.0.0" - hooks: - - id: flake8 - additional_dependencies: [ - flake8-bugbear, - flake8-print, - flake8-docstrings, - pep8-naming - ] - args: ["--docstring-convention", "numpy"] # or google, change me + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: "v0.9.0.6" + hooks: + - id: shellcheck -- repo: https://github.com/kynan/nbstripout - rev: "0.7.1" - hooks: - - id: nbstripout - args: ["--strip-empty-cells", - "--extra-keys", "metadata.kernelspec metadata.language_info"] + - repo: local + hooks: + - id: disallow-caps + name: Disallow improper capitalization + language: pygrep + entry: PyBind|Numpy|Cmake|CCache|Github|PyTest + exclude: .pre-commit-config.yaml -- repo: https://github.com/mgedmin/check-manifest - rev: "0.49" - hooks: - - id: check-manifest - stages: [manual] + - repo: https://github.com/abravalheri/validate-pyproject + rev: v0.16 + hooks: + - id: validate-pyproject -- repo: https://github.com/codespell-project/codespell - rev: "v2.2.6" - hooks: - - id: codespell - args: ["-L", "nd,unparseable,compiletime,tre"] - -- repo: https://github.com/shellcheck-py/shellcheck-py - rev: "v0.9.0.6" - hooks: - - id: shellcheck - -- repo: https://github.com/pre-commit/pygrep-hooks - rev: "v1.10.0" - hooks: - - id: python-no-log-warn - - id: rst-backticks - - id: rst-directive-colons - - id: rst-inline-touching-normal - -- repo: https://github.com/pre-commit/mirrors-prettier - rev: "v4.0.0-alpha.8" - hooks: - - id: prettier - types_or: [json] + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.28.0 + hooks: + - id: check-dependabot + - id: check-github-workflows + - id: check-readthedocs diff --git a/.readthedocs.yaml b/.readthedocs.yaml index d340e5d..3bbf214 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -10,13 +10,8 @@ build: jobs: pre_build: - rm -rf docs/source/api - - sphinx-apidoc - --private - --module-first - --force - --output-dir docs/source/api - src/legendoptics - src/legendoptics/_version.py + - sphinx-apidoc --private --module-first --force --output-dir + docs/source/api src/legendoptics src/legendoptics/_version.py python: install: diff --git a/README.md b/README.md index d945414..3fb81ba 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,14 @@ ![License](https://img.shields.io/github/license/legend-exp/legend-pygeom-optics) [![Read the Docs](https://img.shields.io/readthedocs/legend-pygeom-optics?logo=readthedocs)](https://legend-pygeom-optics.readthedocs.io) -This package contains a collection of optical properties of materials used in the LEGEND experiment. +This package contains a collection of optical properties of materials used in +the LEGEND experiment. -As a common interface, each optical property gets its own defining function in the material's module. Those functions can be used directly to just retrieve the value(s) of the property. Most property definitions contain unit information via the `pint` package. For a full list of defined properties refer to the [package documentation](https://legend-pygeom-optics.readthedocs.io). +As a common interface, each optical property gets its own defining function in +the material's module. Those functions can be used directly to just retrieve the +value(s) of the property. Most property definitions contain unit information via +the `pint` package. For a full list of defined properties refer to the +[package documentation](https://legend-pygeom-optics.readthedocs.io). -To ease the use in Geant4-based simulations, every module also provides functions to be used with [`pyg4ometry`](https://pyg4ometry.readthedocs.io). +To ease the use in Geant4-based simulations, every module also provides +functions to be used with [`pyg4ometry`](https://pyg4ometry.readthedocs.io). diff --git a/codecov.yml b/codecov.yml index 3010946..2dd8fba 100644 --- a/codecov.yml +++ b/codecov.yml @@ -9,7 +9,7 @@ coverage: patch: false github_checks: - annotations: false + annotations: false ignore: - tests diff --git a/docs/source/conf.py b/docs/source/conf.py index 81c6c33..8bbcbb4 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,4 +1,5 @@ # Configuration file for the Sphinx documentation builder. +from __future__ import annotations import sys from pathlib import Path diff --git a/docs/source/exts/optics_plot_extension.py b/docs/source/exts/optics_plot_extension.py index 5710d04..553ee8b 100644 --- a/docs/source/exts/optics_plot_extension.py +++ b/docs/source/exts/optics_plot_extension.py @@ -66,18 +66,16 @@ def do_plot( x = x.magnitude # plot all supplied data vectors - i = 0 - for y in ys: - if isinstance(y, pint.Quantity): - ax.set_ylabel(y.u) - y = y.magnitude + for i, val in enumerate(ys): + if isinstance(val, pint.Quantity): + ax.set_ylabel(val.u) + y = val.magnitude plotoptions = {} if "labels" in options: plotoptions["label"] = options["labels"][i] plt.plot(x, y, marker=".", markersize=2, linewidth=0.5, **plotoptions) - i += 1 if len(ys) > 1 and "labels" in options: plt.legend() @@ -116,16 +114,22 @@ def do_const(obj: Callable) -> list[str]: elif isinstance(const, float): description = f":math:`{const}`" else: - raise ValueError("") + msg = "" + raise ValueError(msg) if description is None: return [""] - else: - return [f":returns: constant value {description}"] + + return [f":returns: constant value {description}"] def process_docstring( - app: Sphinx, what: str, name: str, obj: Any, options: Any, lines: list[str] + app: Sphinx, + what: str, + name: str, + obj: Any, + options: Any, + lines: list[str], ) -> None: if inspect.isclass(obj) or what != "function": return @@ -166,4 +170,4 @@ def process_docstring( def setup(app: Sphinx) -> dict[str, bool]: """Register this sphinx extension.""" app.connect("autodoc-process-docstring", process_docstring) - return dict(parallel_read_safe=True) + return {"parallel_read_safe": True} diff --git a/docs/source/index.rst b/docs/source/index.rst index 0e73a71..6c564ef 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -35,7 +35,7 @@ This example demonstrates how to use the :py:mod:`legendoptics.lar` submodule to _liquidargon = g4.Material( name="LiquidArgon", state="liquid", - [...] + # [...] registry=g4_registry, ) diff --git a/pyproject.toml b/pyproject.toml index 6e10b88..8ff4765 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,26 +1,134 @@ [build-system] requires = [ - "setuptools>=42.0.0", - "setuptools_scm[toml]>=3.4" + "setuptools>=61.2", + "setuptools_scm[toml]>=7" ] - build-backend = "setuptools.build_meta" +[project] +name = "legend_pygeom_optics" +description = "Optical properties of the LEGEND experiment" +authors = [ + { name = "Luigi Pertoldi", email = "gipert@pm.me" }, + { name = "Manuel Huber", email = "info@manuelhu.de" }, +] +maintainers = [ + { name = "The LEGEND Collaboration" }, +] +readme = "README.md" +license.file = "LICENSE" +classifiers = [ + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: MacOS", + "Operating System :: POSIX", + "Operating System :: Unix", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Topic :: Scientific/Engineering", +] +requires-python = ">=3.9" +dependencies = [ + "numpy", + "pint", + "pyg4ometry", + "pylegendmeta>=v0.9.0a2", + "pyarrow", +] +dynamic = [ + "version", +] + +[project.urls] +Homepage = "https://github.com/legend-exp/legend-pygeom-optics" +"Bug Tracker" = "https://github.com/legend-exp/legend-pygeom-optics/issues" +Discussions = "https://github.com/legend-exp/legend-pygeom-optics/discussions" +Changelog = "https://github.com/legend-exp/legend-pygeom-optics/releases" + [tool.setuptools_scm] write_to = "src/legendoptics/_version.py" +[project.optional-dependencies] +all = [ + "legend-pygeom-optics[docs,test]", +] +docs = [ + "furo", + "myst-parser", + "sphinx", + "sphinx-copybutton", +] +test = [ + "pre-commit", + "pylegendtestdata", + "pytest>=6.0", + "pytest-cov", +] + +[tool.setuptools] +include-package-data = true +zip-safe = false +license-files = [ + "LICENSE", +] + +[tool.setuptools.package-dir] +"" = "src" + +[tool.setuptools.packages.find] +where = [ + "src", +] +namespaces = false + [tool.pytest.ini_options] minversion = "6.0" addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"] xfail_strict = true -filterwarnings = [ - "error", - "default::PendingDeprecationWarning:pyg4ometry", - "default::DeprecationWarning" -] +filterwarnings = "error" log_cli_level = "info" testpaths = "tests" -[tool.isort] -profile = "black" -multi_line_output = 3 +[tool.codespell] +ignore-words-list = "manuel,tre" + +[tool.ruff] +src = ["src"] + +[tool.ruff.lint] +extend-select = [ + "B", # flake8-bugbear + "I", # isort + "C4", # flake8-comprehensions + "EM", # flake8-errmsg + "ICN", # flake8-import-conventions + "G", # flake8-logging-format + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "PT", # flake8-pytest-style + "PTH", # flake8-use-pathlib + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "T20", # flake8-print + "UP", # pyupgrade + "YTT", # flake8-2020 + "EXE", # flake8-executable + "NPY", # NumPy specific rules + "PD", # pandas-vet +] +ignore = [ + "PLR09", # Too many <...> + "PLR2004", # Magic value used in comparison + "ISC001", # Conflicts with formatter + "PT011", # too picky pytest.raises() complaint + "RUF003", # we like greek letters +] +isort.required-imports = ["from __future__ import annotations"] + +[tool.ruff.lint.per-file-ignores] +"tests/**" = ["T20"] +"noxfile.py" = ["T20"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index fd32044..0000000 --- a/setup.cfg +++ /dev/null @@ -1,65 +0,0 @@ -[metadata] -name = legend_pygeom_optics -version = attr: legendoptics._version.version -description = Optical properties of the LEGEND experiment -long_description = file: README.md -long_description_content_type = text/markdown -url = https://github.com/legend-exp/legend-pygeom-optics -author = Luigi Pertoldi -author_email = gipert@pm.me -maintainer = The LEGEND Collaboration -license = GPL-3.0 -license_files = LICENSE -classifiers = - Development Status :: 4 - Beta - Intended Audience :: Developers - Intended Audience :: Information Technology - Intended Audience :: Science/Research - License :: OSI Approved :: GNU General Public License v3 (GPLv3) - Operating System :: MacOS - Operating System :: POSIX - Operating System :: Unix - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only - Topic :: Scientific/Engineering - Topic :: Scientific/Engineering :: Mathematics - Topic :: Scientific/Engineering :: Physics - Topic :: Software Development - -[options] -packages = find: -install_requires = - importlib-resources - matplotlib - numpy - pint - pyg4ometry - scipy -python_requires = >=3.9 -include_package_data = True -package_dir = - = src -zip_safe = False - -[options.packages.find] -where = src - -[options.extras_require] -all = - legend-pygeom-optics[docs,test] -docs = - furo - myst-parser - sphinx>=7.2.2 - sphinx-copybutton -test = - pre-commit - pytest>=6.0 - pytest-cov - -[options.package_data] -legendoptics = src/legendoptics/data/*.dat - -[flake8] -extend-ignore = E203, E501, D10 diff --git a/setup.py b/setup.py deleted file mode 100644 index f684491..0000000 --- a/setup.py +++ /dev/null @@ -1,4 +0,0 @@ -import setuptools_scm # noqa: F401 -from setuptools import setup - -setup() diff --git a/src/legendoptics/__init__.py b/src/legendoptics/__init__.py index aad1b5c..efa291a 100644 --- a/src/legendoptics/__init__.py +++ b/src/legendoptics/__init__.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from legendoptics._version import version as __version__ __all__ = ["__version__"] diff --git a/src/legendoptics/lar.py b/src/legendoptics/lar.py index 28800c6..181b5b1 100644 --- a/src/legendoptics/lar.py +++ b/src/legendoptics/lar.py @@ -5,7 +5,7 @@ .. [Doke1976] Doke et al. “Estimation of Fano factors in liquid argon, krypton, xenon and xenon-doped liquid argon.” NIM 134 (1976)353, https://doi.org/10.1016/0029-554X(76)90292-5 .. [Bideau-Mehu1980] Bideau-Mehu et al. “Measurement of refractive indices of neon, argon, krypton - and xenon in the 253.7–140.4 nm wavelength range. Dispersion relations and + and xenon in the 253.7-140.4 nm wavelength range. Dispersion relations and estimated oscillator strengths of the resonance lines.” In: Journal of Quantitative Spectroscopy and Radiative Transfer 25.5 (1981)). https://doi.org/10.1016/0022-4073(81)90057-1 @@ -19,7 +19,7 @@ .. [Doke2002] T. Doke et al. “Absolute Scintillation Yields in Liquid Argon and Xenon for Various Particles” Jpn. J. Appl. Phys. 41 1538, https://doi.org/10.1143/JJAP.41.1538 .. [Hitachi1983] A. Hitachi et al. “Effect of ionization density on the time dependence of luminescence - from liquid argon and xenon.” In: Phys. Rev. B 27 (9 May 1983), pp. 5279–5285, + from liquid argon and xenon.” In: Phys. Rev. B 27 (9 May 1983), pp. 5279-5285, https://doi.org/10.1103/PhysRevB.27.5279 """ @@ -59,10 +59,12 @@ def lar_dielectric_constant_bideau_mehu( .. optics-plot:: {'call_x': True} """ if not λ.check("[length]"): - raise ValueError("input does not look like a wavelength") + msg = "input does not look like a wavelength" + raise ValueError(msg) if np.any(λ < 110 * u.nm): - raise ValueError(f"this parametrization is not meaningful below {110*u.nm}") + msg = f"this parametrization is not meaningful below {110*u.nm}" + raise ValueError(msg) # equation for n-1 ϵ = 1.2055e-2 * ( @@ -87,15 +89,15 @@ def lar_dielectric_constant_cern2020( .. optics-plot:: {'call_x': True} """ if not λ.check("[length]"): - raise ValueError("input does not look like a wavelength") + msg = "input does not look like a wavelength" + raise ValueError(msg) λ_uv = 106.6 * u.nm λ_ir = 908.3 * u.nm if np.any(λ < λ_uv + 1 * u.nm) or np.any(λ > λ_ir - 1 * u.nm): - raise ValueError( - f"this parametrization holds only between {λ_uv+1*u.nm} and {λ_ir-1*u.nm}" - ) + msg = f"this parametrization holds only between {λ_uv+1*u.nm} and {λ_ir-1*u.nm}" + raise ValueError(msg) x = 0.334 + ((0.100 * λ**2) / (λ**2 - λ_uv**2) + (0.008 * λ**2) / (λ**2 - λ_ir**2)) @@ -112,9 +114,10 @@ def lar_dielectric_constant(λ: Quantity, method: str = "cern2020") -> Quantity: """ if method == "bideau-mehu": return lar_dielectric_constant_bideau_mehu(λ) - elif method == "cern2020": + if method == "cern2020": return lar_dielectric_constant_cern2020(λ) - raise ValueError(f"Unknown LAr dielectric constant method {method}") + msg = f"Unknown LAr dielectric constant method {method}" + raise ValueError(msg) def lar_refractive_index(λ: Quantity, method: str = "cern2020") -> Quantity: @@ -138,14 +141,12 @@ def lar_emission_spectrum(λ: Quantity) -> Quantity: heindl = readdatafile("lar_emission_heindl2010.dat") # sample the measured emission spectrum and avoid the fluctuations below 115 nm. - scint_em = InterpolatingGraph( + return InterpolatingGraph( *heindl, min_idx=115 * u.nm, max_idx=150 * u.nm, )(λ) - return scint_em - def lar_fano_factor() -> float: """Fano factor. @@ -175,7 +176,8 @@ def lar_rayleigh( .. optics-plot:: {'call_x': True} """ if not temperature.check("[temperature]"): - raise ValueError("input does not look like a temperature") + msg = "input does not look like a temperature" + raise ValueError(msg) dyne = 1.0e-5 * u.newton κ = 2.18e-10 * u.cm**2 / dyne # LAr isothermal compressibility @@ -189,9 +191,8 @@ def lar_rayleigh( inv_l /= λ**4 inv_l *= (2 / 3 * np.pi) ** 3 - assert not np.any(inv_l < 1 / (10.0 * u.km)) and not np.any( - inv_l > 1 / (0.1 * u.nm) - ) + assert not np.any(inv_l < 1 / (10.0 * u.km)) + assert not np.any(inv_l > 1 / (0.1 * u.nm)) return (1 / inv_l).to("cm") # simplify units @@ -219,11 +220,12 @@ def lar_peak_attenuation_length( if isinstance(attenuation_method, str): if attenuation_method == "legend200-llama": return 30 * u.cm - else: - raise ValueError(f"unknown attenuation_method {attenuation_method}") - else: - assert attenuation_method.check("[length]") - return attenuation_method + + msg = f"unknown attenuation_method {attenuation_method}" + raise ValueError(msg) + + assert attenuation_method.check("[length]") + return attenuation_method def lar_lifetimes( @@ -238,9 +240,8 @@ def lar_lifetimes( if triplet_lifetime_method == "legend200-llama": triplet = 1.3 * u.us else: - raise ValueError( - f"unknown triplet_lifetime_method {triplet_lifetime_method}" - ) + msg = f"unknown triplet_lifetime_method {triplet_lifetime_method}" + raise ValueError(msg) else: triplet = triplet_lifetime_method * u.us diff --git a/src/legendoptics/pen.py b/src/legendoptics/pen.py index c9eea9a..c3d0d14 100644 --- a/src/legendoptics/pen.py +++ b/src/legendoptics/pen.py @@ -3,12 +3,12 @@ .. [Manzanillas2022] L. Manzanillas et al. “Optical properties of low background PEN structural components for the LEGEND-200 experiment”. In: JINST 17 P09007 (2022), https://doi.org/10.1088/1748-0221/17/09/P09007 .. [Hong2017] N. Hong et al. “Mueller matrix characterization of flexible plastic substrates”. - In: Applied Surface Science, 421:518–528 (2017), https://doi.org/10.1016/j.apsusc.2017.01.276 + In: Applied Surface Science, 421:518-528 (2017), https://doi.org/10.1016/j.apsusc.2017.01.276 .. [Mary1997] D. Mary et al. “Understanding optical emissions from electrically stressed insulating polymers: electroluminescence in poly(ethylene terephthalate) and poly(ethylene 2,6-naphthalate) films” In: J. Phys. D: Appl. Phys. 30 171 (1997), https://doi.org/10.1088/0022-3727/30/2/004 .. [Ouchi2006] I. Ouchi et al. “Features of Fluorescence Spectra of Polyethylene 2,6-Naphthalate Films” - In: Journal of Applied Polymer Science, Vol. 105, 114–121 (2007), https://doi.org/10.1002/app.26085 + In: Journal of Applied Polymer Science, Vol. 105, 114-121 (2007), https://doi.org/10.1002/app.26085 """ from __future__ import annotations diff --git a/src/legendoptics/plot.py b/src/legendoptics/plot.py index 2cdddbd..0cc5903 100644 --- a/src/legendoptics/plot.py +++ b/src/legendoptics/plot.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Callable import matplotlib.pyplot as plt diff --git a/src/legendoptics/pyg4utils.py b/src/legendoptics/pyg4utils.py index 248449a..f04990c 100644 --- a/src/legendoptics/pyg4utils.py +++ b/src/legendoptics/pyg4utils.py @@ -91,7 +91,8 @@ def _val_pint_to_gdml(v): unit = f"{base_unit:~gdml}" assert unit == f"{base_unit:~}".replace(" ", "").replace("µ", "u") - log.debug(f"Unit pint->gdml: {unit} - {base_unit}") + msg = f"Unit pint->gdml: {unit} - {base_unit}" + log.debug(msg) v = v.m_as(base_unit) return unit, v @@ -107,7 +108,7 @@ def _val_pint_to_gdml(v): ] length_props = ["ABSLENGTH", "WLSABSLENGTH", "RAYLEIGH"] - def addVecPropertyPint(self, name, e, v): # noqa: N802 + def addVecPropertyPint(self, name, e, v): vunit, v = _val_pint_to_gdml(v) eunit, e = _val_pint_to_gdml(e) v = np.array(v) @@ -130,7 +131,7 @@ def addVecPropertyPint(self, name, e, v): # noqa: N802 g4.Material.addVecPropertyPint = addVecPropertyPint g4.solid.OpticalSurface.addVecPropertyPint = addVecPropertyPint - def addConstPropertyPint(self, name, value): # noqa: N802 + def addConstPropertyPint(self, name, value): vunit, value = _val_pint_to_gdml(value) if name in ["SCINTILLATIONYIELD"]: diff --git a/src/legendoptics/tpb.py b/src/legendoptics/tpb.py index 32e334a..a8d34cf 100644 --- a/src/legendoptics/tpb.py +++ b/src/legendoptics/tpb.py @@ -133,7 +133,8 @@ def pyg4_tpb_attach_wls( from legendoptics.pyg4utils import pyg4_sample_λ if emission_spectrum not in ["default", "polystyrene_matrix"]: - raise ValueError("invalid parameter value of emission_spectrum") + msg = "invalid parameter value of emission_spectrum" + raise ValueError(msg) emission_fn = tpb_wls_emission if emission_spectrum == "polystyrene_matrix": diff --git a/src/legendoptics/utils.py b/src/legendoptics/utils.py index 0f77878..707b33a 100644 --- a/src/legendoptics/utils.py +++ b/src/legendoptics/utils.py @@ -30,9 +30,8 @@ def readdatafile(filename: str) -> tuple[Quantity, Quantity]: # parse header header = lines[0].lstrip() if header[0] != "#": - raise RuntimeError( - "input data file does not seem to contain header with (pint) units" - ) + msg = "input data file does not seem to contain header with (pint) units" + raise RuntimeError(msg) units = header.lstrip("#").split() @@ -44,7 +43,8 @@ def readdatafile(filename: str) -> tuple[Quantity, Quantity]: val = line.split() if len(val) < 2: - raise RuntimeError(f"could not parse line {lineno}: '{line}'") + msg = f"could not parse line {lineno}: '{line}'" + raise RuntimeError(msg) x.append(float(val[0])) y.append(float(val[1])) diff --git a/tests/test_data_file_read.py b/tests/test_data_file_read.py index 1d21328..d056020 100644 --- a/tests/test_data_file_read.py +++ b/tests/test_data_file_read.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from legendoptics.utils import readdatafile diff --git a/tests/test_import.py b/tests/test_import.py index c9282d4..6a9b38f 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import numpy as np import pint @@ -5,7 +7,7 @@ def test_import(): - import legendoptics # noqa: F401 + import legendoptics import legendoptics.copper import legendoptics.fibers import legendoptics.germanium diff --git a/tests/test_lar.py b/tests/test_lar.py index 9bd0825..55f2cc0 100644 --- a/tests/test_lar.py +++ b/tests/test_lar.py @@ -1,5 +1,7 @@ +from __future__ import annotations + import pint -from pytest import approx +import pytest from legendoptics import lar @@ -7,7 +9,9 @@ def test_dielectric_constant(): - assert lar.lar_dielectric_constant_bideau_mehu(128 * u.nm) == approx( + assert lar.lar_dielectric_constant_bideau_mehu(128 * u.nm) == pytest.approx( 1.993, rel=1e-3 ) - assert lar.lar_dielectric_constant_cern2020(128 * u.nm) == approx(1.846, rel=1e-3) + assert lar.lar_dielectric_constant_cern2020(128 * u.nm) == pytest.approx( + 1.846, rel=1e-3 + ) diff --git a/tests/test_plot.py b/tests/test_plot.py index 4fddf93..711dc22 100644 --- a/tests/test_plot.py +++ b/tests/test_plot.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import matplotlib.pyplot as plt import numpy as np import pint diff --git a/tests/test_pyg4.py b/tests/test_pyg4.py index ce0622a..d7be3dc 100644 --- a/tests/test_pyg4.py +++ b/tests/test_pyg4.py @@ -1,4 +1,5 @@ """Test the attaching of all properties to Geant4 materials.""" +from __future__ import annotations import pint import pyg4ometry.geant4 as g4