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

added STEREO empirical model-based straylight #104

Merged
merged 6 commits into from
Jan 21, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
tests stray light addition
  • Loading branch information
lowderchris committed Jan 10, 2025
commit ec111dd88bcf65221575c271337c0708f63db12c
63 changes: 63 additions & 0 deletions simpunch/tests/test_stray_light.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from datetime import datetime

import numpy as np
import pytest
from astropy.nddata import StdDevUncertainty
from astropy.wcs import WCS
from ndcube import NDCube
from punchbowl.data import NormalizedMetadata

from simpunch.level0 import add_stray_light
from simpunch.util import generate_stray_light


@pytest.fixture()
def sample_ndcube() -> NDCube:
def _sample_ndcube(shape: tuple, code:str = "CR1", level:str = "0") -> NDCube:
data = np.random.random(shape).astype(np.float32) * 1e-12
sqrt_abs_data = np.sqrt(np.abs(data))
uncertainty = StdDevUncertainty(np.interp(sqrt_abs_data, (sqrt_abs_data.min(), sqrt_abs_data.max()),
(0,1)).astype(np.float32))
wcs = WCS(naxis=2)
wcs.wcs.ctype = "HPLN-ARC", "HPLT-ARC"
wcs.wcs.cunit = "deg", "deg"
wcs.wcs.cdelt = 0.1, 0.1
wcs.wcs.crpix = 0, 0
wcs.wcs.crval = 1, 1
wcs.wcs.cname = "HPC lon", "HPC lat"

meta = NormalizedMetadata.load_template(code, level)
meta["DATE-OBS"] = str(datetime(2024, 2, 22, 16, 0, 1))
meta["FILEVRSN"] = "1"
return NDCube(data=data, uncertainty=uncertainty, wcs=wcs, meta=meta)
return _sample_ndcube


def test_generate_stray_light() -> None:
shape = (2048,2048)

stray_light_wfi = generate_stray_light(shape=shape, instrument="WFI")
stray_light_nfi = generate_stray_light(shape=shape, instrument="NFI")

assert np.sum(stray_light_wfi[0]) != 0
assert np.sum(stray_light_wfi[1]) != 0
assert np.sum(stray_light_nfi[0]) != 0
assert np.sum(stray_light_nfi[1]) != 0

assert stray_light_wfi[0].shape == shape
assert stray_light_wfi[1].shape == shape
assert stray_light_nfi[0].shape == shape
assert stray_light_nfi[1].shape == shape


def test_stray_light(sample_ndcube: NDCube) -> None:
"""Test stray light addition."""
input_data = sample_ndcube((2048,2048))

input_data_array = input_data.data.copy()

stray_light_data = add_stray_light(input_data, polar="clear")

assert isinstance(stray_light_data, NDCube)
assert np.sum(stray_light_data.data - input_data_array) != 0
assert (stray_light_data.data != input_data_array).all()
Loading