Skip to content

Commit

Permalink
pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gipert committed Feb 7, 2024
1 parent 519e835 commit 304d4ab
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 64 deletions.
9 changes: 2 additions & 7 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ coverage:
patch: false

github_checks:
annotations: false
annotations: false

ignore:
- tests
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Configuration file for the Sphinx documentation builder.
from __future__ import annotations

import sys
from pathlib import Path
Expand Down
26 changes: 15 additions & 11 deletions docs/source/exts/optics_plot_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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
Expand All @@ -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"]

Expand Down
2 changes: 2 additions & 0 deletions src/legendoptics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from legendoptics._version import version as __version__

__all__ = ["__version__"]
51 changes: 26 additions & 25 deletions src/legendoptics/lar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.7140.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
Expand All @@ -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. 52795285,
from liquid argon and xenon.” In: Phys. Rev. B 27 (9 May 1983), pp. 5279-5285,
https://doi.org/10.1103/PhysRevB.27.5279
"""

Expand Down Expand Up @@ -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 * (
Expand All @@ -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))

Expand All @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/legendoptics/pen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:518528 (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, 114121 (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
Expand Down
2 changes: 2 additions & 0 deletions src/legendoptics/plot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Callable

import matplotlib.pyplot as plt
Expand Down
7 changes: 4 additions & 3 deletions src/legendoptics/pyg4utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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"]:
Expand Down
3 changes: 2 additions & 1 deletion src/legendoptics/tpb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
8 changes: 4 additions & 4 deletions src/legendoptics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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]))
Expand Down
2 changes: 2 additions & 0 deletions tests/test_data_file_read.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from legendoptics.utils import readdatafile


Expand Down
4 changes: 3 additions & 1 deletion tests/test_import.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import annotations

import numpy as np
import pint

u = pint.get_application_registry()


def test_import():
import legendoptics # noqa: F401
import legendoptics
import legendoptics.copper
import legendoptics.fibers
import legendoptics.germanium
Expand Down
Loading

0 comments on commit 304d4ab

Please sign in to comment.