Skip to content

Commit

Permalink
Merge pull request #153 from cta-observatory/run_date
Browse files Browse the repository at this point in the history
add a warning in case the considered run is not in the summary table
  • Loading branch information
morcuended authored May 10, 2022
2 parents 6bb3943 + de7b307 commit 384be71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 10 additions & 1 deletion osa/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ def get_run_date(run_id: int) -> str:
"""
merged_run_summaries_file = cfg.get("LST1", "MERGED_SUMMARY")
summary_table = Table.read(merged_run_summaries_file)
date_string = summary_table[summary_table['run_id'] == run_id]['date'][0]

try:
date_string = summary_table[summary_table["run_id"] == run_id]["date"][0]
except IndexError:
log.warning(
f"Run {run_id} is not in the summary table. "
f"Assuming the date of the run is {options.date}."
)
date_string = utils.date_to_dir(options.date)

return date_string.replace("-", "")


Expand Down
9 changes: 3 additions & 6 deletions osa/tests/test_paths.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from datetime import datetime
from pathlib import Path

import pytest

from osa.configs import options
from osa.configs.config import cfg
from osa.utils.utils import date_to_dir

options.date = datetime.fromisoformat("2020-01-17")

def test_get_calibration_file(r0_data, merged_run_summary):
from osa.paths import get_calibration_file
Expand Down Expand Up @@ -80,7 +79,6 @@ def test_get_datacheck_file(datacheck_dl1_files):
def test_destination_dir():
from osa.paths import destination_dir

options.date = datetime.fromisoformat("2020-01-17")
datedir = date_to_dir(options.date)
options.dl1_prod_id = cfg.get("LST1", "DL1_PROD_ID")
options.dl2_prod_id = cfg.get("LST1", "DL2_PROD_ID")
Expand Down Expand Up @@ -111,12 +109,11 @@ def test_destination_dir():
assert directory == expected_directory


def test_get_run_date(r0_data, merged_run_summary):
def test_get_run_date(merged_run_summary):
from osa.paths import get_run_date

assert merged_run_summary.exists()

assert get_run_date(1808) == "20200117"

with pytest.raises(IndexError):
get_run_date(1200)
assert get_run_date(1200) == "20200117"

0 comments on commit 384be71

Please sign in to comment.