-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
iris.sg.effective_area()
function. (#13)
- Loading branch information
Showing
8 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |