Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PA correction for NIRISS #139

Merged
merged 15 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion amical/mf_pipeline/bispect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,10 @@ def extract_bs(

with fits.open(filename) as hdu:
hdr = hdu[0].header
try:
sci_hdr = hdu["SCI"].header
except KeyError:
sci_hdr = None

infos = _check_input_infos(
hdr, targetname=targetname, filtname=filtname, instrum=instrum, verbose=False
Expand Down Expand Up @@ -1356,7 +1360,7 @@ def extract_bs(

# 13. Compute the absolute oriention (North-up, East-left)
# ------------------------------------------------------------------------
pa = compute_pa(hdr, n_ps, display=display, verbose=verbose)
pa = compute_pa(hdr, n_ps, sci_hdr, display=display, verbose=verbose)
vandalt marked this conversation as resolved.
Show resolved Hide resolved

# Compile informations in the storage infos class
infos = _add_infos_header(infos, hdr, mf, pa, filename, maskname, npix)
Expand Down
4 changes: 2 additions & 2 deletions amical/oifits.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ def save(
hdu.header["ORIGIN"] = origin or hdr.get("ORIGIN", "Sydney University")
hdu.header["CONTENT"] = "OIFITS2"
hdu.header["DATE-OBS"] = hdr.get("date-obs", "")
hdu.header["TELESCOP"] = hdr.get("TELESCOP", "")
hdu.header["INSTRUME"] = hdr.get("INSTRUME", "")
hdu.header["TELESCOP"] = hdr.get("telescop", "")
vandalt marked this conversation as resolved.
Show resolved Hide resolved
hdu.header["INSTRUME"] = hdr.get("INSTRUME", dic["info"]["INSTRUME"])
hdu.header["OBSERVER"] = hdr.get("OBSERVER", "")
hdu.header["OBJECT"] = hdr.get("OBJECT", dic["info"]["TARGET"])
hdu.header["INSMODE"] = "NRM"
Expand Down
1,640 changes: 1,640 additions & 0 deletions amical/tests/data/hdr_niriss_amisim.fits

Large diffs are not rendered by default.

5,703 changes: 5,703 additions & 0 deletions amical/tests/data/hdr_niriss_mirage.fits

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions amical/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

valid_commands = ["clean", "extract", "calibrate"]

pytestmark = pytest.mark.filterwarnings(
"ignore: No SCI header for NIRISS. No PA correction will be applied."
)
vandalt marked this conversation as resolved.
Show resolved Hide resolved


@pytest.fixture()
def close_figures():
Expand Down
5 changes: 5 additions & 0 deletions amical/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
# from amical.mf_pipeline.ami_function import find_bad_holes


pytestmark = pytest.mark.filterwarnings(
"ignore: No SCI header for NIRISS. No PA correction will be applied."
)
vandalt marked this conversation as resolved.
Show resolved Hide resolved


@pytest.fixture()
def close_figures():
plt.close("all")
Expand Down
56 changes: 55 additions & 1 deletion amical/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,60 @@ def test_SPHERE_parang(global_datadir):
with fits.open(global_datadir / "hdr_sphere.fits") as hdu:
hdr = hdu[0].header
n_ps = 1
pa = tools.compute_pa(hdr, n_ps=n_ps)
pa = tools.sphere_parang(hdr, n_dit_ifs=n_ps)
true_pa = 109 # Human value
assert pa == pytest.approx(true_pa, 0.01)


def test_NIRISS_parang(global_datadir):
# TODO: Add this file
vandalt marked this conversation as resolved.
Show resolved Hide resolved
with fits.open(global_datadir / "hdr_niriss_mirage.fits") as hdu:
hdr = hdu["SCI"].header
pa = tools.niriss_parang(hdr)
# TODO: Add real value
vandalt marked this conversation as resolved.
Show resolved Hide resolved
true_pa = 157.9079 # Human value
assert pa == pytest.approx(true_pa, 0.01)


def test_compute_pa_sphere(global_datadir):
with fits.open(global_datadir / "hdr_sphere.fits") as hdul:
hdr = hdul[0].header
sci_hdr = None
n_ps = 1
pa = tools.compute_pa(hdr, n_ps, sci_hdr)
true_pa = 109 # Human value
assert pa == pytest.approx(true_pa, 0.01)


def test_compute_pa_niriss(global_datadir):
with fits.open(global_datadir / "hdr_niriss_mirage.fits") as hdul:
hdr = hdul[0].header
sci_hdr = hdul["SCI"].header
n_ps = hdul["SCI"].data.shape[-1]
pa = tools.compute_pa(hdr, n_ps, sci_hdr)
true_pa = 157.9079 # Human value
assert pa == pytest.approx(true_pa, 0.01)


def test_NIRISS_parang_amisim():
# ami_sim file has no SCI
hdr = None
with pytest.warns(RuntimeWarning) as record:
pa = tools.niriss_parang(hdr)
assert len(record) == 1
assert (
record[0].message.args[0]
== "No SCI header for NIRISS. No PA correction will be applied."
)
assert pa == 0.0


def test_compute_pa_niriss_amisim(global_datadir):
with fits.open(global_datadir / "hdr_niriss_amisim.fits") as hdul:
hdr = hdul[0].header
sci_hdr = None
vandalt marked this conversation as resolved.
Show resolved Hide resolved
n_ps = hdul[0].data.shape[-1]
with pytest.warns(RuntimeWarning) as record:
pa = tools.compute_pa(hdr, n_ps, sci_hdr)
vandalt marked this conversation as resolved.
Show resolved Hide resolved
assert len(record) == 1
assert pa == 0.0
22 changes: 19 additions & 3 deletions amical/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
--------------------------------------------------------------------
"""
import math as m
import warnings

import h5py
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -368,10 +369,11 @@ def jd2lst(lng, jd):
return lst


def compute_pa(hdr, n_ps, verbose=False, display=False):
def compute_pa(hdr, n_ps, sci_hdr, verbose=False, display=False):
vandalt marked this conversation as resolved.
Show resolved Hide resolved

list_fct_pa = {
"SPHERE": sphere_parang,
"SPHERE": (sphere_parang, {"hdr": hdr, "n_dit_ifs": n_ps}),
"NIRISS": (niriss_parang, {"hdr": sci_hdr}),
}

instrument = hdr["INSTRUME"]
Expand All @@ -389,7 +391,8 @@ def compute_pa(hdr, n_ps, verbose=False, display=False):
pa_exist = False
l_pa = np.zeros(nframe)
else:
l_pa = list_fct_pa[instrument](hdr, n_ps)
fct_pa, kwargs_pa = list_fct_pa[instrument]
l_pa = fct_pa(**kwargs_pa)
pa_exist = True

pa = np.mean(l_pa)
Expand All @@ -407,6 +410,19 @@ def compute_pa(hdr, n_ps, verbose=False, display=False):
return pa


def niriss_parang(hdr):
if hdr is None:
warnings.warn(
"No SCI header for NIRISS. No PA correction will be applied.",
RuntimeWarning,
)
return 0.0
v3i_yang = hdr["V3I_YANG"] # Angle from V3 axis to ideal y axis (deg)
roll_ref_pa = hdr["ROLL_REF"] # Offset between V3 and N in local aperture coord

return roll_ref_pa - v3i_yang


def sphere_parang(hdr, n_dit_ifs=None):
"""
Reads the header and creates an array giving the paralactic angle for each frame,
Expand Down