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 a warning in case the considered run is not in the summary table #153

Merged
merged 10 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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"