From 05c44a51be77c21fb09ce28c3a96f8b7f5c8a4bf Mon Sep 17 00:00:00 2001 From: Maria Lainez Date: Tue, 10 May 2022 11:16:13 +0200 Subject: [PATCH 01/10] add a warning if the considered run is not in the summary table --- osa/paths.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/osa/paths.py b/osa/paths.py index d661654f..a004935d 100644 --- a/osa/paths.py +++ b/osa/paths.py @@ -69,7 +69,13 @@ 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: + log.warning(f"Run {str(run_id)} is not in the summary table. Assuming the date of the run is {options.date}.") + date_string = options.date + return date_string.replace("-", "") From 17fbb167b72c3824683fac196630a17c1b5b8b43 Mon Sep 17 00:00:00 2001 From: Maria Lainez Date: Tue, 10 May 2022 11:22:21 +0200 Subject: [PATCH 02/10] solve small issue --- osa/paths.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osa/paths.py b/osa/paths.py index a004935d..a128cc32 100644 --- a/osa/paths.py +++ b/osa/paths.py @@ -71,9 +71,9 @@ def get_run_date(run_id: int) -> str: summary_table = Table.read(merged_run_summaries_file) try: - date_string = summary_table[summary_table["run_id"] == run_id]["date"][0] + date_string = summary_table[summary_table["run_id"] == run_id]["date"][0] except: - log.warning(f"Run {str(run_id)} is not in the summary table. Assuming the date of the run is {options.date}.") + log.warning(f"Run {str(run_id)} is not in the summary table. Assuming the date of the run is {options.date}.") date_string = options.date return date_string.replace("-", "") From df9333e03259c011acfd20e3bb66b9a77fb6ef0f Mon Sep 17 00:00:00 2001 From: Maria Lainez Date: Tue, 10 May 2022 11:26:47 +0200 Subject: [PATCH 03/10] add IndexError --- osa/paths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osa/paths.py b/osa/paths.py index a128cc32..cda35c9f 100644 --- a/osa/paths.py +++ b/osa/paths.py @@ -72,7 +72,7 @@ def get_run_date(run_id: int) -> str: try: date_string = summary_table[summary_table["run_id"] == run_id]["date"][0] - except: + except IndexError: log.warning(f"Run {str(run_id)} is not in the summary table. Assuming the date of the run is {options.date}.") date_string = options.date From 8010614599d25ea4ea065107b7c4b8638b25d56a Mon Sep 17 00:00:00 2001 From: Maria Lainez Date: Tue, 10 May 2022 11:46:00 +0200 Subject: [PATCH 04/10] convert date to a string --- osa/paths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osa/paths.py b/osa/paths.py index cda35c9f..27964ca8 100644 --- a/osa/paths.py +++ b/osa/paths.py @@ -74,7 +74,7 @@ def get_run_date(run_id: int) -> str: date_string = summary_table[summary_table["run_id"] == run_id]["date"][0] except IndexError: log.warning(f"Run {str(run_id)} is not in the summary table. Assuming the date of the run is {options.date}.") - date_string = options.date + date_string = str(options.date) return date_string.replace("-", "") From 159e1de713afb76709cd5adb03af861d05d3cb57 Mon Sep 17 00:00:00 2001 From: Maria Lainez Date: Tue, 10 May 2022 11:48:16 +0200 Subject: [PATCH 05/10] remove unnecessary string conversion --- osa/paths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osa/paths.py b/osa/paths.py index 27964ca8..e7731a26 100644 --- a/osa/paths.py +++ b/osa/paths.py @@ -73,7 +73,7 @@ def get_run_date(run_id: int) -> str: try: date_string = summary_table[summary_table["run_id"] == run_id]["date"][0] except IndexError: - log.warning(f"Run {str(run_id)} is not in the summary table. Assuming the date of the run is {options.date}.") + log.warning(f"Run {run_id} is not in the summary table. Assuming the date of the run is {options.date}.") date_string = str(options.date) return date_string.replace("-", "") From 4868a394a74ec33957c65242ab3f70b528399039 Mon Sep 17 00:00:00 2001 From: Maria Lainez Date: Tue, 10 May 2022 12:48:08 +0200 Subject: [PATCH 06/10] change tests --- osa/tests/test_paths.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/osa/tests/test_paths.py b/osa/tests/test_paths.py index 615c5307..a6ce71a6 100644 --- a/osa/tests/test_paths.py +++ b/osa/tests/test_paths.py @@ -7,6 +7,7 @@ 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 @@ -80,7 +81,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") @@ -111,12 +111,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" From d4cd3630801a1070b1d1e5f5eb78c3923c7676c8 Mon Sep 17 00:00:00 2001 From: Maria Lainez Date: Tue, 10 May 2022 12:51:12 +0200 Subject: [PATCH 07/10] use date_to_dir function --- osa/paths.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osa/paths.py b/osa/paths.py index e7731a26..e9ba2302 100644 --- a/osa/paths.py +++ b/osa/paths.py @@ -7,6 +7,7 @@ from osa.configs import options from osa.configs.config import cfg from osa.utils.logging import myLogger +from osa.utils.utils import date_to_dir from osa.utils import utils from osa.configs.config import DEFAULT_CFG @@ -74,7 +75,7 @@ def get_run_date(run_id: int) -> str: 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. Assuming the date of the run is {options.date}.") - date_string = str(options.date) + date_string = date_to_dir(options.date) return date_string.replace("-", "") From 732d7c72ac8399875142e85af1051f4c057c0119 Mon Sep 17 00:00:00 2001 From: Maria Lainez Date: Tue, 10 May 2022 12:53:48 +0200 Subject: [PATCH 08/10] remove unused package --- osa/tests/test_paths.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/osa/tests/test_paths.py b/osa/tests/test_paths.py index a6ce71a6..ebb4c3b0 100644 --- a/osa/tests/test_paths.py +++ b/osa/tests/test_paths.py @@ -1,8 +1,6 @@ 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 From 02a08c0143a2264f801bbe8f7e1a522e64e0940b Mon Sep 17 00:00:00 2001 From: Daniel Morcuende Date: Tue, 10 May 2022 15:18:19 +0200 Subject: [PATCH 09/10] fix a problem with circular import --- osa/paths.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osa/paths.py b/osa/paths.py index e9ba2302..5b456599 100644 --- a/osa/paths.py +++ b/osa/paths.py @@ -7,7 +7,6 @@ from osa.configs import options from osa.configs.config import cfg from osa.utils.logging import myLogger -from osa.utils.utils import date_to_dir from osa.utils import utils from osa.configs.config import DEFAULT_CFG @@ -75,7 +74,7 @@ def get_run_date(run_id: int) -> str: 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. Assuming the date of the run is {options.date}.") - date_string = date_to_dir(options.date) + date_string = utils.date_to_dir(options.date) return date_string.replace("-", "") From de7b30739130b794a65313599950f932d23963d7 Mon Sep 17 00:00:00 2001 From: Daniel Morcuende Date: Tue, 10 May 2022 15:39:06 +0200 Subject: [PATCH 10/10] minor codacy complaints --- osa/paths.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/osa/paths.py b/osa/paths.py index 5b456599..dbb8a3a6 100644 --- a/osa/paths.py +++ b/osa/paths.py @@ -69,11 +69,14 @@ 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) - - try: + + 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. Assuming the date of the run is {options.date}.") + 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("-", "")