Skip to content

Commit

Permalink
Added iris.sg.effective_area() function. (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdie authored Oct 24, 2024
1 parent 2e95a84 commit 5a21bcf
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 0 deletions.
2 changes: 2 additions & 0 deletions iris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

from . import planning
from . import data
from . import response
from . import sg

__all__ = [
"planning",
"data",
"response",
"sg",
]
9 changes: 9 additions & 0 deletions iris/response/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
The IRIS instrument response files.
"""

from ._response import files

__all__ = [
"files",
]
17 changes: 17 additions & 0 deletions iris/response/_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pathlib

__all__ = [
"files",
]


def files() -> list[pathlib.Path]:
"""
A list of the IDL ``.sav`` files storing the IRIS instrument response.
"""

directory = pathlib.Path(__file__).parent

result = sorted(directory.glob("*.geny"))

return result
9 changes: 9 additions & 0 deletions iris/response/_response_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pathlib
import iris


def test_files():
result = iris.response.files()
assert len(result) > 0
for r in result:
assert isinstance(r, pathlib.Path)
Binary file added iris/response/iris_sra_20130211.geny
Binary file not shown.
2 changes: 2 additions & 0 deletions iris/sg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"""

from . import background
from ._effective_area import effective_area
from ._spectrograph import SpectrographObservation

__all__ = [
"background",
"effective_area",
"SpectrographObservation",
]
81 changes: 81 additions & 0 deletions iris/sg/_effective_area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import scipy.io
import astropy.units as u
import named_arrays as na
import iris

__all__ = [
"effective_area",
]


def effective_area(wavelength: u.Quantity | na.AbstractScalar) -> na.AbstractScalar:
"""
Load the effective area of the spectrograph.
Currently only Version 1 is implemented.
Parameters
----------
wavelength
The wavelength of the incident light at which to evaluate the effective
area.
Examples
--------
Plot the effective area of the spectrograph as a function of wavelength.
.. jupyter-execute::
import matplotlib.pyplot as plt
import astropy.units as u
import astropy.visualization
import named_arrays as na
import iris
# Define a wavelength grid
wavelength = na.linspace(
start=1250 * u.AA,
stop=3000 * u.AA,
axis="wavelength",
num=1001,
)
# Compute the effective area
area = iris.sg.effective_area(wavelength)
# Plot the effective area as a function of wavelength
with astropy.visualization.quantity_support():
fig, ax = plt.subplots()
na.plt.plot(
wavelength,
area,
)
ax.set_xlabel(f"wavelength ({ax.get_xlabel()})")
ax.set_ylabel(f"effective area ({ax.get_ylabel()})")
"""

files = iris.response.files()

file_v1 = files[0]

struct_v1 = scipy.io.readsav(file_v1)["p0"]

wavelength_v1 = struct_v1["LAMBDA"][0] * u.nm
area_v1 = struct_v1["AREA_SG"][0] * u.cm**2

axis = "_dummy"
axes = ("channel", axis)

axis = "_dummy"

wavelength_v1 = na.ScalarArray(wavelength_v1, axes=axis)
area_v1 = na.ScalarArray(area_v1, axes=axes).sum("channel")

return na.interp(
x=wavelength,
xp=wavelength_v1,
fp=area_v1,
axis=axis,
)
19 changes: 19 additions & 0 deletions iris/sg/_effective_area_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
import astropy.units as u
import named_arrays as na
import iris


@pytest.mark.parametrize(
argnames="wavelength",
argvalues=[
1330 * u.AA,
na.linspace(1300, 1400, axis="w", num=11) * u.AA,
],
)
def test_effective_area(
wavelength: u.Quantity | na.AbstractScalar,
):
result = iris.sg.effective_area(wavelength)

assert result.sum() > 0 * u.cm**2

0 comments on commit 5a21bcf

Please sign in to comment.