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 e563beb..8ff4765 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,7 +92,7 @@ log_cli_level = "info" testpaths = "tests" [tool.codespell] -ignore-words-list = "manuel" +ignore-words-list = "manuel,tre" [tool.ruff] src = ["src"] @@ -101,7 +101,6 @@ src = ["src"] extend-select = [ "B", # flake8-bugbear "I", # isort - "ARG", # flake8-unused-arguments "C4", # flake8-comprehensions "EM", # flake8-errmsg "ICN", # flake8-import-conventions @@ -126,6 +125,7 @@ ignore = [ "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"] 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