Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hayesla committed Aug 14, 2024
1 parent b06bb19 commit ac26ade
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions stixpy/calibration/tests/test_visibility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import astropy.units as u
import numpy as np
import pytest
from astropy.tests.helper import assert_quantity_allclose
from astropy.time import Time
Expand Down Expand Up @@ -54,3 +55,43 @@ def test_create_meta_pixels(background_cpd):
[0.18701911, 0.18205339, 0.18328145, 0.17945563] * u.ct / (u.keV * u.cm**2 * u.s),
meta_pixels["abcd_rate_kev_cm"][-1, :],
)


def test_create_meta_pixels_timebins(flare_cpd):
energy_range = [6, 12] * u.keV

# check time_range within one bin (i.e. timerange passed is within one bin)
time_range = [flare_cpd.times[0], flare_cpd.times[0] + flare_cpd.duration / 4]
meta_pixels = create_meta_pixels(
flare_cpd,
time_range=time_range,
energy_range=energy_range,
flare_location=STIXImaging(0 * u.arcsec, 0 * u.arcsec),
no_shadowing=True,
)

assert_quantity_allclose(meta_pixels["time_range"].dt.to(u.s), flare_cpd.duration[0].to(u.s))

# check time_range fully outside bins (i.e. all bins contained with timerange)
time_range = [flare_cpd.times[0] - 10 * u.s, flare_cpd.times[-1] + 10 * u.s]
meta_pixels = create_meta_pixels(
flare_cpd,
time_range=time_range,
energy_range=energy_range,
flare_location=STIXImaging(0 * u.arcsec, 0 * u.arcsec),
no_shadowing=True,
)

assert_quantity_allclose(np.sum(flare_cpd.duration), meta_pixels["time_range"].dt.to(u.s))

# check time_range start and end are within bins
time_range = [flare_cpd.times[0], flare_cpd.times[2]]
meta_pixels = create_meta_pixels(
flare_cpd,
time_range=time_range,
energy_range=energy_range,
flare_location=STIXImaging(0 * u.arcsec, 0 * u.arcsec),
no_shadowing=True,
)

assert_quantity_allclose(np.sum(flare_cpd.duration[0:3]), meta_pixels["time_range"].dt.to(u.s))

0 comments on commit ac26ade

Please sign in to comment.