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

Make link of the updated longterm datacheck file in a common directory #273

Merged
merged 19 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
22 changes: 22 additions & 0 deletions src/osa/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from osa.configs.datamodel import Sequence
from osa.utils import utils
from osa.utils.logging import myLogger
from osa.utils.utils import date_to_dir

log = myLogger(logging.getLogger(__name__))

Expand Down Expand Up @@ -141,6 +142,7 @@ def get_calibration_filename(run_id: int, prod_id: str) -> Path:
mongodb = cfg.get("database", "caco_db")
try:
# Cast run_id to int to avoid problems with numpy int64 encoding in MongoDB
#options.filters = find_filter_wheels(int(run_id), mongodb)
morcuended marked this conversation as resolved.
Show resolved Hide resolved
options.filters = find_filter_wheels(int(run_id), mongodb)
except IOError:
log.warning("No filter information found in database. Assuming positions 52.")
Expand Down Expand Up @@ -346,3 +348,23 @@ def create_source_directories(source_list: list, cuts_dir: Path):
if source is not None:
source_dir = cuts_dir / source
source_dir.mkdir(parents=True, exist_ok=True)


def get_latest_version_file(longterm_files: List[str]) -> Path:
"""Get the latest version path of the produced longterm DL1 datacheck files for a given date."""
latest_version_path = max(longterm_files, key=lambda path: int(path.parents[1].name.split(".")[1]) if path.parents[1].name.startswith("v") else "")
return latest_version_path


def create_longterm_symlink():
"""If the created longterm DL1 datacheck file corresponds to the latest
version available, make symlink to it in the "all" common directory."""
nightdir = date_to_dir(options.date)
longterm_dir = Path(cfg.get("LST1", "LONGTERM_DIR"))
linked_longterm_file = longterm_dir / f"night_wise/all/DL1_datacheck_{nightdir}.h5"
all_longterm_files = sorted(longterm_dir.rglob(f"v*/{nightdir}/DL1_datacheck_{nightdir}.h5"))
latest_version_file = get_latest_version_file(all_longterm_files)

log.info("Make symlink of the latest version longterm DL1 datacheck file in the common directory.")
linked_longterm_file.unlink()
morcuended marked this conversation as resolved.
Show resolved Hide resolved
linked_longterm_file.symlink_to(latest_version_file)
3 changes: 2 additions & 1 deletion src/osa/scripts/closer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
from osa.nightsummary.extract import extract_runs, extract_sequences
from osa.nightsummary.nightsummary import run_summary_table
from osa.paths import destination_dir
from osa.paths import destination_dir, create_longterm_symlink
from osa.raw import is_raw_data_available
from osa.report import start
from osa.utils.cliopts import closercliparsing
Expand Down Expand Up @@ -165,6 +165,7 @@ def post_process(seq_tuple):
list_job_id = merge_dl1_datacheck(seq_list)
longterm_job_id = daily_datacheck(daily_longterm_cmd(list_job_id))
cherenkov_transparency(cherenkov_transparency_cmd(longterm_job_id))
create_longterm_symlink()

# Extract the provenance info
extract_provenance(seq_list)
Expand Down
2 changes: 2 additions & 0 deletions src/osa/scripts/tests/test_osa_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def test_closer(
drs4_time_calibration_files,
systematic_correction_files,
merged_run_summary,
longterm_dir,
):
# First assure that the end of night flag is not set and remove it otherwise
night_finished_flag = Path(
Expand All @@ -198,6 +199,7 @@ def test_closer(
for obs_file in test_observed_data:
assert obs_file.exists()
assert merged_run_summary.exists()
assert longterm_dir.exists()
morcuended marked this conversation as resolved.
Show resolved Hide resolved

run_program("closer", "-y", "-v", "-t", "-d", "2020-01-17", "LST1")
closed_seq_file = running_analysis_dir / "sequence_LST1_01809.closed"
Expand Down
Loading