Skip to content

Commit

Permalink
Added optika.sensors.AbstractChemical.absorption() function. (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdie committed Jun 5, 2024
1 parent e5c32d1 commit dd91232
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
15 changes: 15 additions & 0 deletions optika/chemicals/_chemicals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions optika/chemicals/_tests/test_chemicals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions optika/sensors/_materials/_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit dd91232

Please sign in to comment.