diff --git a/optika/chemicals/_chemicals.py b/optika/chemicals/_chemicals.py index 224fff0..b83c52f 100644 --- a/optika/chemicals/_chemicals.py +++ b/optika/chemicals/_chemicals.py @@ -160,6 +160,21 @@ def wavenumber( """ return np.imag(self.n(wavelength)) + def absorption( + self, + wavelength: u.Quantity | na.AbstractScalar, + ): + """ + The absorption coefficient of this chemical for the given wavelength. + + Parameters + ---------- + wavelength + The wavelength of light in vacuum for which to compute the + absorption coefficient. + """ + return 4 * np.pi * self.wavenumber(wavelength) / wavelength + @dataclasses.dataclass(eq=False, repr=False) class Chemical( diff --git a/optika/chemicals/_tests/test_chemicals.py b/optika/chemicals/_tests/test_chemicals.py index 22ecd04..8793c51 100644 --- a/optika/chemicals/_tests/test_chemicals.py +++ b/optika/chemicals/_tests/test_chemicals.py @@ -60,6 +60,16 @@ def test_wavenumber( assert isinstance(result, na.AbstractScalar) assert np.all(result >= 0) + @pytest.mark.parametrize("wavelength", _wavelength) + def test_absorption( + self, + a: optika.chemicals.AbstractChemical, + wavelength: u.Quantity | na.AbstractScalar, + ): + result = a.absorption(wavelength) + assert isinstance(result, na.AbstractScalar) + assert np.all(result >= 0) + @pytest.mark.parametrize( argnames="a", diff --git a/optika/sensors/_materials/_materials.py b/optika/sensors/_materials/_materials.py index 785b94c..869916d 100644 --- a/optika/sensors/_materials/_materials.py +++ b/optika/sensors/_materials/_materials.py @@ -420,9 +420,7 @@ def attenuation( self, rays: optika.rays.AbstractRayVectorArray, ) -> na.ScalarLike: - result = self._chemical.wavenumber(rays.wavelength) - result = 4 * np.pi * result / rays.wavelength - return result + return self._chemical.absorption(rays.wavelength) @property def is_mirror(self) -> bool: