Skip to content

Commit 48c2607

Browse files
committed
add unit test
1 parent 3015978 commit 48c2607

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

irf/tests/test_exposure_map.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
import pytest
3+
import fact.io as fio
4+
import pandas as pd
5+
from irf import estimate_exposure_time
6+
7+
8+
FIXTURE_DIR = os.path.join(
9+
os.path.dirname(os.path.realpath(__file__)),
10+
'test_files',
11+
)
12+
13+
14+
@pytest.fixture
15+
def events():
16+
return fio.read_data(os.path.join(FIXTURE_DIR, 'crab_dl3_sample.hdf5'), key='events')
17+
18+
19+
@pytest.fixture
20+
def runs():
21+
return fio.read_data(os.path.join(FIXTURE_DIR, 'crab_dl3_sample.hdf5'), key='runs')
22+
23+
24+
25+
def test_exposure_time(runs, events):
26+
n_crab_sample = 687226
27+
n_test_sample = len(events)
28+
29+
live_time_crab = runs.ontime.sum() / 3600 # to hours
30+
31+
expected_live_time_sample = n_test_sample / n_crab_sample * live_time_crab
32+
33+
timestamps = pd.to_datetime(events.timestamp).values
34+
exposure = estimate_exposure_time(timestamps).to('h').value
35+
36+
assert expected_live_time_sample == pytest.approx(exposure, 0.05)
4.97 MB
Binary file not shown.

0 commit comments

Comments
 (0)