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

Gain sel tracker #295

Merged
merged 49 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
711b319
Create gainSel_webmaker.py
rcervinoucm Jul 1, 2024
e9c4e8b
Delete src/osa/scripts/gainSel_webmaker.py
rcervinoucm Jul 3, 2024
ff207d2
Create gainSelWebmaker.py
rcervinoucm Jul 3, 2024
73b3bf9
Create gainsel_webmaker.py
rcervinoucm Jul 3, 2024
d2c31a0
Delete src/osa/scripts/gainSelWebmaker.py
rcervinoucm Jul 3, 2024
14f9c57
Update gainsel_webmaker.py
rcervinoucm Jul 3, 2024
17fd640
Update gainsel_webmaker.py
rcervinoucm Jul 3, 2024
eba84c6
Update gainsel_webmaker.py
rcervinoucm Jul 3, 2024
f3f228f
Update gainsel_webmaker.py
rcervinoucm Jul 3, 2024
6d8988b
Update gainsel_webmaker.py
rcervinoucm Jul 3, 2024
886f9e7
Update gainsel_webmaker.py
rcervinoucm Jul 3, 2024
29a3542
Update gainsel_webmaker.py
rcervinoucm Jul 3, 2024
421c7ed
Update gainsel_webmaker.py
rcervinoucm Jul 3, 2024
f3ae27a
Update gainsel_webmaker.py
rcervinoucm Jul 3, 2024
74b4488
Update sequencer_webmaker.py
rcervinoucm Jul 3, 2024
dc8ff36
Update gainsel_webmaker.py
rcervinoucm Jul 3, 2024
e1e085f
Update gainsel_webmaker.py
rcervinoucm Jul 3, 2024
b21201a
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 4, 2024
a5da4c8
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 4, 2024
9f12973
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 4, 2024
5f45df3
Update gainsel_webmaker.py
rcervinoucm Jul 4, 2024
e92e8ef
Update gainsel_webmaker.py
rcervinoucm Jul 4, 2024
13096ed
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 5, 2024
fa825df
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 5, 2024
afdbba0
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 5, 2024
085dcaf
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 5, 2024
dad866d
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 5, 2024
43ab379
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 5, 2024
596a033
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 5, 2024
ae1f506
Update gainsel_webmaker.py
rcervinoucm Jul 5, 2024
00e82f6
Update gainsel_webmaker.py
rcervinoucm Jul 5, 2024
4b64f2f
Update gainsel_webmaker.py
rcervinoucm Jul 5, 2024
0f93dea
Update gainsel_webmaker.py
rcervinoucm Jul 5, 2024
4590557
Update gainsel_webmaker.py
rcervinoucm Jul 8, 2024
bc8aa4c
Update pyproject.toml
rcervinoucm Jul 8, 2024
e105d11
Create test_gainsel_webmaker.py
rcervinoucm Jul 8, 2024
0df8389
Update sequencer.cfg
rcervinoucm Jul 8, 2024
abf6ba1
Delete src/osa/tests/test_gainsel_webmaker.py
rcervinoucm Jul 8, 2024
399b6b5
Update test_osa_scripts.py
rcervinoucm Jul 8, 2024
85542aa
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 8, 2024
4f19407
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 8, 2024
a9b6f5b
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 8, 2024
025156b
Update src/osa/scripts/gainsel_webmaker.py
rcervinoucm Jul 8, 2024
9c9f816
Update test_osa_scripts.py
rcervinoucm Jul 8, 2024
0e8ff43
Update test_osa_scripts.py
rcervinoucm Jul 9, 2024
e982daf
Update gainsel_webmaker.py
rcervinoucm Jul 9, 2024
3ad9629
Update gainsel_webmaker.py
rcervinoucm Jul 9, 2024
1de1b19
some simplifications and cleanup
morcuended Jul 9, 2024
107d558
remove redundant line
morcuended Jul 9, 2024
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
127 changes: 127 additions & 0 deletions src/osa/scripts/gainsel_webmaker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
from pathlib import Path
from astropy.table import Table
from datetime import datetime, timedelta
from osa.utils.utils import date_to_dir, date_to_iso
from osa.configs.config import cfg
from osa.paths import DEFAULT_CFG
from osa.nightsummary.nightsummary import run_summary_table
import numpy as np
import pandas as pd
from argparse import ArgumentParser
from osa.configs import options
from osa.scripts.sequencer_webmaker import html_content

def valid_date(string):
"""Check if the string is a valid date and return a datetime object."""
return datetime.strptime(string, "%Y%m%d")


common_parser = ArgumentParser(add_help=False)
common_parser.add_argument(
"-c",
"--config",
type=Path,
default=DEFAULT_CFG,
help="Use specific config file [default configs/sequencer.cfg]",
)
common_parser.add_argument(
"-d",
"--date",
help="Date (YYYYMMDD) of the start of the night",
type=valid_date,
)


def check_gainsel_jobs_runwise(date: str, run_id: int) -> bool:
morcuended marked this conversation as resolved.
Show resolved Hide resolved
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
"""Search for failed jobs in the log directory."""
base_dir = Path(cfg.get("LST1", "BASE"))
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
log_dir = base_dir / f"R0G/log/{date}"
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
history_files = log_dir.glob(f"gain_selection_{run_id:05d}.????.history")

success_subruns = 0
failed_subruns = 0
pending_subruns = 0

for file in history_files:
if file.read_text() != "":
gainsel_rc = file.read_text().splitlines()[-1][-1]

if gainsel_rc == "1":
failed_subruns = failed_subruns+1

elif gainsel_rc == "0":
success_subruns = success_subruns+1
else:
pending_subruns = pending_subruns+1
return [pending_subruns, success_subruns, failed_subruns]

def check_failed_jobs(date: str):
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
"""Search for failed jobs in the log directory."""
summary_table = run_summary_table(datetime.fromisoformat(date))
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
data_runs = summary_table[summary_table["run_type"] == "DATA"]

gainsel_summary = []
for run in data_runs:
run_id = run["run_id"]
checkgainsel = check_gainsel_jobs_runwise(date.replace('-',''), run_id)
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
gainsel_summary.append([run_id, checkgainsel[0], checkgainsel[1], checkgainsel[2]])
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved

gainsel_df = pd.DataFrame(gainsel_summary, columns=['run_id', 'pending','success','failed'])
gainsel_df['GainSelStatus'] = np.where(gainsel_df['failed'] != 0, 'FAILED', np.where(gainsel_df['pending'] != 0, 'PENDING', 'COMPLETED'))
gainsel_df['GainSel%'] = round(gainsel_df['success']*100/(gainsel_df['pending']+gainsel_df['failed']+gainsel_df['success'])
,1)
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
summary_table = summary_table.to_pandas()
final_table = pd.merge(summary_table, gainsel_df, on="run_id")[['run_id','n_subruns','run_type','pending','success','failed','GainSelStatus', 'GainSel%']]
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved

return final_table

def main():
"""Produce the html file with the processing OSA Gain Selection status."""
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
args = ArgumentParser(
description="Script to make an xhtml from LSTOSA sequencer output", parents=[common_parser]
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
).parse_args()

html_table = ''
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved

if args.date:
flat_date = date_to_dir(args.date)
options.date = args.date

else:
# yesterday by default
yesterday = datetime.now() - timedelta(days=1)
options.date = yesterday
flat_date = date_to_dir(yesterday)

date = date_to_iso(options.date)

run_summary_directory = Path(cfg.get("LST1", "RUN_SUMMARY_DIR"))
run_summary_file = run_summary_directory / f"RunSummary_{flat_date}.ecsv"

if not run_summary_file.is_file() or len(Table.read(run_summary_file)["run_id"]) == 0:

html_table = "<p>No data found</p>"
# Save the HTML file
directory = Path(cfg.get("LST1", "GAIN_SELECTION_FLAG_DIR"))
directory.mkdir(parents=True, exist_ok=True)
html_file = directory / Path(f"osa_gainsel_status_{flat_date}.html")
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
html_file.write_text(html_content(html_table, date, "OSA Gain Selection"), encoding="utf-8")

else:
# Get the table with the sequencer status report:
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
lines = check_failed_jobs(date)
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved

lines.reset_index(drop=True, inplace=True)
if html_table == '':
html_table = lines.to_html()
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved

# Save the HTML file
directory = Path(cfg.get("LST1", "GAIN_SELECTION_FLAG_DIR"))

directory.mkdir(parents=True, exist_ok=True)

html_file = directory / Path(f"osa_gainsel_status_{flat_date}.html")
rcervinoucm marked this conversation as resolved.
Show resolved Hide resolved
html_file.write_text(html_content(html_table, date, "OSA Gain Selection"), encoding="utf-8")

if __name__ == "__main__":
main()
8 changes: 4 additions & 4 deletions src/osa/scripts/sequencer_webmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
log = myLogger(logging.getLogger())


def html_content(body: str, date: str) -> str:
def html_content(body: str, date: str, title: str) -> str:
"""Build the HTML content.

Parameters
Expand All @@ -43,11 +43,11 @@ def html_content(body: str, date: str) -> str:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OSA Sequencer status</title><link href="osa.css" rel="stylesheet"
<title>{title} status</title><link href="osa.css" rel="stylesheet"
type="text/css" /><style>table{{width:152ex;}}</style>
</head>
<body>
<h1>OSA processing status</h1>
<h1>{title} processing status</h1>
<p>Processing data from: {date}. Last updated: {time_update} UTC</p>
{body}
</body>
Expand Down Expand Up @@ -159,7 +159,7 @@ def main():
directory.mkdir(parents=True, exist_ok=True)

html_file = directory / Path(f"osa_status_{flat_date}.html")
html_file.write_text(html_content(html_table, date), encoding="utf-8")
html_file.write_text(html_content(html_table, date, "OSA Sequencer"), encoding="utf-8")

log.info("Done")

Expand Down
Loading