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

Look for the closest declination line and adequate NSB random forest model for DL2 production #280

Draft
wants to merge 112 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
79ffaf6
Look for the closest declination line to choose the RF model to produ…
marialainez Feb 28, 2024
ce2fab1
Get the path names from the cfg file
marialainez Feb 29, 2024
147e88c
Get the source declination from the TCU database (not from the run ca…
marialainez Feb 29, 2024
045fb01
Get the RF models for a given run (not subrun), run_str is run.subrun
marialainez Feb 29, 2024
5f5071f
Change name of variable
marialainez Feb 29, 2024
0bb0185
Convert date to string in the correct format to create the path
marialainez Feb 29, 2024
2be6466
Adapt tests
marialainez Feb 29, 2024
51d40c4
Add necessary argument
marialainez Feb 29, 2024
cbdee3e
Adapt tests + create dec_list looking into the RF_models directory
marialainez Mar 1, 2024
5ea46a4
Use only the TCU database to get the source coordinates (no access to…
marialainez Mar 18, 2024
f0e1680
Use only dec strings with the format dec_(min)_XXXX
marialainez Mar 21, 2024
4915cc1
Add new step in datasequence to produce the CatB calibration files
marialainez May 28, 2024
53d57b3
add r0-dir to the calibration scripts (e.g. in case R0G is used)
marialainez May 28, 2024
0b43696
Add CatB calibration file as input in dl1ab step
marialainez May 28, 2024
95290da
adapt configuration file
marialainez May 28, 2024
0828b26
add docstring
marialainez May 28, 2024
763ec64
adapt tests
marialainez May 29, 2024
a3f0e1a
add argument in catB_calibration function
marialainez May 29, 2024
9e9193c
adapt tests
marialainez May 29, 2024
5ac3770
fix small issues
marialainez Jun 3, 2024
889508c
adapt tests
marialainez Jun 3, 2024
9b4b441
Merge branch 'main' into dl2_production
morcuended Jun 25, 2024
2d3e2bd
Update src/osa/configs/sequencer.cfg
marialainez Jun 26, 2024
eefba65
adapt name of Cat-A and Cat-B calibration dir to the cfg file
marialainez Jun 26, 2024
f483be3
use lstchain major version as calib_prod_id
marialainez Jun 26, 2024
34c8ab0
add option in the cfg to apply or not catB calibration
marialainez Aug 5, 2024
c67cdd5
add cat A calibration run number
marialainez Aug 6, 2024
d3f5d22
remove unused import
marialainez Sep 19, 2024
434ad9b
check always if the culmination angle is larger than for the source
marialainez Sep 19, 2024
78b918e
return the declination as an astropy quantity
marialainez Sep 19, 2024
22e7a2d
rename directory
marialainez Sep 19, 2024
7207dbb
fix mistake
marialainez Sep 19, 2024
0c15ed7
change directory name
marialainez Sep 19, 2024
d6c45cd
adapt tests
marialainez Sep 19, 2024
0b25f30
adapt tests
marialainez Sep 20, 2024
c3f8608
add filters as an argument of the catB calibration command
marialainez Sep 23, 2024
ccf89db
correct name of catB_calib_dir
marialainez Sep 23, 2024
f8b0edd
wait until the catB file is created if subrun != 0000
marialainez Sep 23, 2024
e94a15a
adapt tests
marialainez Sep 23, 2024
a9ebfdb
remove unused imports
marialainez Sep 23, 2024
d8df805
adapt tests
marialainez Sep 24, 2024
37062cd
adapt historylevel function
marialainez Sep 25, 2024
7bfbdb2
do not check the culmination angle for sources between 22.76 and 34.7…
marialainez Sep 26, 2024
ae9ccc0
get the general value of the two closest values
marialainez Sep 27, 2024
d220c81
add --no-dl1ab option to process data with catB (sequencer launched t…
marialainez Oct 4, 2024
805964b
if option --no-dl1ab, just execute the r0_to_dl1 step
marialainez Oct 10, 2024
48f13b2
do not launch catB_calibration in datasequence
marialainez Oct 14, 2024
cf7b610
fix historylevel
marialainez Oct 14, 2024
754721d
add rf_model_path as an input argument for datasequence + move get_RF…
marialainez Dec 12, 2024
37b8fef
pass the rf_model_path when writing the sequence.py files
marialainez Dec 12, 2024
cc94ccb
adapt tests
marialainez Dec 13, 2024
97f78fe
remove unused imports
marialainez Dec 13, 2024
9f59675
adapt tests
marialainez Dec 15, 2024
5b875b3
remove unnecessary part
marialainez Dec 16, 2024
2137efd
remove unused import
marialainez Dec 16, 2024
bb08a83
Merge branch 'main' into dl2_production
marialainez Dec 16, 2024
56294a8
launch catB and tailcuts_finder in a separate sequencer
marialainez Jan 22, 2025
52d08bb
remove cat-B calibration function from datasequence
marialainez Jan 22, 2025
9f75081
use options.date instead of date
marialainez Jan 22, 2025
19108d1
fix path names
marialainez Jan 22, 2025
564932a
use the config file produced by lstchain_find_tailcuts
marialainez Jan 23, 2025
dab59a0
check if catB and tailcuts_finder finished before launching dl1ab
marialainez Jan 23, 2025
c33586a
allow to use the dl1b standard config file is apply_standard_dl1b_con…
marialainez Jan 23, 2025
20b5eb9
move catB_closed_file_exists function to paths
marialainez Jan 23, 2025
c5ff8ae
Merge branch 'main' into catB_option1
marialainez Jan 23, 2025
d02810c
add necessary imports
marialainez Jan 23, 2025
169b20b
Merge branch 'catB_option1' of https://github.com/cta-observatory/lst…
marialainez Jan 23, 2025
9229ad3
add sequencer_catB_tailcuts to pyproject.toml
marialainez Jan 24, 2025
ac064c9
add verbose option
marialainez Jan 24, 2025
77b5d21
use the date provided in the command line (if given)
marialainez Jan 24, 2025
0e1e799
fix the name of the path of the dl1a files (without tailcut84)
marialainez Jan 24, 2025
360693f
write job_id correctly in the log file of the tailcut finder
marialainez Jan 24, 2025
1a66fee
use the command name given in the cfg
marialainez Jan 24, 2025
17bd18c
[skip ci] Correct language in help string
morcuended Jan 28, 2025
5b51983
use more descriptive names
marialainez Jan 28, 2025
a4a2d5c
check if sequencer is completed by looking at the history files
marialainez Jan 28, 2025
02fc610
set rc to 1 (and not 0) to see that the job failed and be aware of it
marialainez Jan 28, 2025
8b4487e
check if the catB files already exist
marialainez Jan 28, 2025
450ae0d
add dococstrings
marialainez Jan 28, 2025
7b49647
add necessary import
marialainez Jan 28, 2025
a4dd985
adapt tests
marialainez Jan 28, 2025
a30be4a
fix name
marialainez Jan 28, 2025
dcc641b
remove unnecessary f-string
marialainez Jan 28, 2025
f9456e1
add simulate option
marialainez Jan 29, 2025
42c46e1
add abreviation for simulate option
marialainez Jan 29, 2025
c6896ac
select the rf models with the correct NSB settings
marialainez Jan 29, 2025
2d540ca
require at least lstchain v0.10.15
marialainez Jan 29, 2025
e437c8c
add docstrings
marialainez Jan 29, 2025
3aecfff
use the mc_prod (rf_models_prefix) given in the cfg file
marialainez Jan 29, 2025
8070e23
write the DL1b files in the corresponding tailcutXY directory
marialainez Feb 7, 2025
4dc81f3
use pointing dec (as the median of the dec from datacheck files) inst…
marialainez Feb 10, 2025
1d2b2e3
remove unnecessary imports and unnecessary function
marialainez Feb 10, 2025
88f6331
Apply suggestions from code review
morcuended Feb 10, 2025
5a53596
bumo ctapipe io lst version compatible with latest lstchain
morcuended Feb 10, 2025
412eb7e
adapt tests
marialainez Feb 10, 2025
64c74dc
rename input_dir as analysis_dir
marialainez Feb 10, 2025
7658bfe
rename source_dec as pointing_dec
marialainez Feb 10, 2025
e6ea503
get closest NSB among those with the same cleaning
marialainez Feb 10, 2025
309968b
Merge branch 'catB_option1' into dl2_production
marialainez Feb 11, 2025
8b005ba
write the dl2 files in tailcutXY/nsb_tuning_x.xx directories
marialainez Feb 11, 2025
58aead8
use the pointing_dec given in the run catalog
marialainez Feb 11, 2025
3eb000a
fix mistake
marialainez Feb 11, 2025
b13a07b
add necessary import
marialainez Feb 11, 2025
ad45095
avoid writing the RF model if --no-dl1ab option is given
marialainez Feb 14, 2025
391f284
add units to pointing_dec
marialainez Feb 14, 2025
5fa55ff
remove unused import
marialainez Feb 14, 2025
b906992
include all tags in dl2_prod_id[C
marialainez Feb 14, 2025
8f7bab5
avoid calling the find_tailcuts function more than once (to reduce th…
marialainez Feb 18, 2025
f4a84d7
set dl1/2_prod_id for each sequence separately and not for the whole day
marialainez Feb 20, 2025
988b1a7
create two functions to return the dl1/dl2_prod_id + move the files t…
marialainez Feb 20, 2025
e041ced
momentarily use only the tailcut84/datacheck dir for the longterm and…
marialainez Feb 20, 2025
14e4ebc
remove unused imports
marialainez Feb 20, 2025
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
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ dependencies:
- click
- pymongo
- scikit-learn=1.2
- ctapipe_io_lst=0.24
- ctapipe_io_lst >=0.25.1,<0.26a0
- ctaplot~=0.6.4
- pyirf~=0.10
- lstchain>=0.10.13
- lstchain>=0.10.15
- tenacity
- pip:
- lstcam_calib
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ classifiers = [
requires-python = ">=3.10"
dependencies = [
"astropy~=5.0",
"lstchain>=0.10.13",
"lstchain>=0.10.15",
"matplotlib",
"numpy",
"pandas",
Expand Down Expand Up @@ -76,6 +76,7 @@ reprocess_longterm = "osa.scripts.reprocess_longterm:main"
gain_selection = "osa.scripts.gain_selection:main"
update_source_catalog = "osa.scripts.update_source_catalog:main"
gainsel_webmaker = "osa.scripts.gainsel_webmaker:main"
sequencer_catB_tailcuts = "osa.scripts.sequencer_catB_tailcuts:main"

[tool.setuptools.packages.find]
where = ["src"]
Expand Down
2 changes: 2 additions & 0 deletions src/osa/configs/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
warning = None
nocheck = None
no_dl2 = None
no_dl1ab = None
no_gainsel = None
prod_id = None
dl1_prod_id = None
dl2_prod_id = None
Expand Down
15 changes: 11 additions & 4 deletions src/osa/configs/sequencer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ RUN_SUMMARY_DIR: %(MONITORING)s/RunSummary
RUN_CATALOG: %(MONITORING)s/RunCatalog
PEDESTAL_FINDER_DIR: %(BASE)s/auxiliary/PedestalFinder
ANALYSIS_DIR: %(BASE)s/running_analysis
CALIB_BASE_DIR: %(MONITORING)s/PixelCalibration/Cat-A
CALIB_DIR: %(CALIB_BASE_DIR)s/calibration
PEDESTAL_DIR: %(CALIB_BASE_DIR)s/drs4_baseline
CALIB_BASE_DIR: %(MONITORING)s/PixelCalibration
CAT_A_CALIB_BASE: %(CALIB_BASE_DIR)s/Cat-A
CAT_A_CALIB_DIR: %(CAT_A_CALIB_BASE)s/calibration
CAT_A_PEDESTAL_DIR: %(CAT_A_CALIB_BASE)s/drs4_baseline
CAT_B_CALIB_BASE: %(CALIB_BASE_DIR)s/Cat-B
DL1_DIR: %(BASE)s/DL1
DL1AB_DIR: %(BASE)s/DL1
DL2_DIR: %(BASE)s/DL2
DL3_DIR: %(BASE)s/DL3
RF_MODELS: %(BASE)s/models/AllSky
OSA_DIR: %(BASE)s/OSA
CLOSER_DIR: %(OSA_DIR)s/Closer
HIGH_LEVEL_DIR: %(OSA_DIR)s/HighLevel
Expand All @@ -45,22 +48,26 @@ DL2_PROD_ID: model2
#charge_calibration: onsite_create_calibration_file
drs4_baseline: lstcam_calib_onsite_create_drs4_pedestal_file
charge_calibration: lstcam_calib_onsite_create_calibration_file
catB_calibration: onsite_create_cat_B_calibration_file
use_ff_heuristic_id: False

# Data processing steps in datasequence script
r0_to_dl1: lstchain_data_r0_to_dl1
dl1ab: lstchain_dl1ab
check_dl1: lstchain_check_dl1
dl1_to_dl2: lstchain_dl1_to_dl2
tailcuts_finder: lstchain_find_tailcuts

# To be set by the user
dl1a_config: /software/lstchain/data/lstchain_standard_config.json
store_image_dl1ab: True
merge_dl1_datacheck: True
apply_catB_calibration: True
apply_standard_dl1b_config: False
use_ff_heuristic_gain_selection: False
dl1b_config: /software/lstchain/data/lstchain_standard_config.json
dl2_config: /software/lstchain/data/lstchain_standard_config.json
rf_models: /data/models/prod5/zenith_20deg/20201023_v0.6.3
mc_prod: 20240918_v0.10.12
dl3_config: /software/lstchain/data/dl3_std_config.json
max_tries: 3

Expand Down
70 changes: 69 additions & 1 deletion src/osa/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,78 @@ def database(osa_dir):


@pytest.fixture(scope="session")
def gain_selection_flag_file(osa_dir):
def rf_models_allsky_basedir(base_test_dir):
directory = base_test_dir / "models/AllSky"
directory.mkdir(parents=True, exist_ok=True)
return directory


@pytest.fixture(scope="session")
def rf_model_path(rf_models_allsky_basedir):
mc_prod = "20240131_allsky_v0.10.5_all_dec_base"
declination_str = "dec_2276"
rf_model_path = rf_models_allsky_basedir / mc_prod / declination_str
rf_model_path.mkdir(parents=True, exist_ok=True)
return rf_model_path


@pytest.fixture(scope="session")
def gain_selection_flag_file(osa_dir):
GainSel_dir = osa_dir / "GainSel" / "20200117"
GainSel_dir.mkdir(parents=True, exist_ok=True)
file = GainSel_dir / "GainSelFinished.txt"
file.touch()
return file


@pytest.fixture(scope="session")
def catB_closed_file(running_analysis_dir):

catB_closed_file = running_analysis_dir / "catB_00003.closed"
catB_closed_file.touch()
return catB_closed_file


@pytest.fixture(scope="session")
def catB_calib_base_dir(monitoring_dir):

catB_calib_base_dir = monitoring_dir / "PixelCalibration" / "Cat-B"
catB_calib_base_dir.mkdir(parents=True, exist_ok=True)
return catB_calib_base_dir


@pytest.fixture(scope="session")
def catB_calibration_file(catB_calib_dir):

catB_calib_dir = catB_calib_base_dir / "calibration" / nightdir / prod_id
catB_calib_file = catB_calib_dir / "cat_B_calibration_filters_52.Run00003.h5"
catB_calib_file.touch()
return catB_calib_file


@pytest.fixture(scope="session")
def dl1b_config_file(running_analysis_dir):
config_information = dedent(
"""\
{
"tailcuts_clean_with_pedestal_threshold": {
"picture_thresh": 8,
"boundary_thresh": 4,
"sigma": 2.5,
"keep_isolated_pixels": false,
"min_number_picture_neighbors": 2,
"use_only_main_island": false,
"delta_time": 2
},
"dynamic_cleaning": {
"apply": true,
"threshold": 267,
"fraction_cleaning_intensity": 0.03
}
}"""
)
config_file = running_analysis_dir / "dl1ab_Run00003.json"
config_file.touch()
config_file.write_text(config_information)
return config_file

43 changes: 42 additions & 1 deletion src/osa/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
get_drive_file,
get_summary_file,
get_pedestal_ids_file,
get_dl1_prod_id_and_config,
get_dl2_nsb_prod_id,
)
from osa.utils.iofile import write_to_file
from osa.utils.logging import myLogger
from osa.utils.utils import date_to_dir, time_to_seconds, stringify, date_to_iso
from osa.utils.utils import (
date_to_dir,
time_to_seconds,
stringify,
date_to_iso,
get_RF_model,
)

log = myLogger(logging.getLogger(__name__))

Expand Down Expand Up @@ -93,6 +101,14 @@ def are_all_jobs_correctly_finished(sequence_list):
analysis_directory = Path(options.directory)
for sequence in sequence_list:
history_files_list = analysis_directory.rglob(f"*{sequence.seq}*.history")

if not options.test:
try:
next(history_files_list)
except StopIteration:
log.info("no history files found")
flag = False

for history_file in history_files_list:
# TODO: s.history should be SubRunObj attribute not RunObj
# s.history only working for CALIBRATION sequence (run-wise), since it is
Expand All @@ -109,6 +125,12 @@ def are_all_jobs_correctly_finished(sequence_list):
f"finished up to DL1ab, but --no-dl2 option selected"
)
continue
if out == 3 and options.no_dl1ab:
log.debug(
f"Job {sequence.seq} ({sequence.type}) correctly "
f"finished up to DL1A, but --no-dl1ab option selected"
)
continue

log.warning(
f"Job {sequence.seq} (run {sequence.run}) not correctly finished [level {out}]"
Expand Down Expand Up @@ -215,6 +237,8 @@ def historylevel(history_file: Path, data_type: str):
# Data sequence
elif program == cfg.get("lstchain", "r0_to_dl1"):
level = 3 if exit_status == 0 else 4
#elif program == cfg.get("lstchain", "catB_calibration"):
# level = 3 if exit_status == 0 else 4
elif program == cfg.get("lstchain", "dl1ab"):
if (exit_status == 0) and (prod_id == options.dl1_prod_id):
log.debug(f"DL1ab prod ID: {options.dl1_prod_id} already produced")
Expand Down Expand Up @@ -425,6 +449,8 @@ def data_sequence_job_template(sequence):
commandargs.extend(("--config", f"{Path(options.configfile).resolve()}"))
if sequence.type == "DATA" and options.no_dl2:
commandargs.append("--no-dl2")
if sequence.type == "DATA" and options.no_dl1ab:
commandargs.append("--no-dl1ab")

commandargs.extend(
(
Expand All @@ -439,6 +465,21 @@ def data_sequence_job_template(sequence):
)
)

if not options.no_dl1ab:
dl1_prod_id, dl1b_config = get_dl1_prod_id_and_config(sequence.run)
sequence.dl1_prod_id = dl1_prod_id
sequence.dl1b_config = dl1b_config

commandargs.append(f"--dl1b-config={sequence.dl1b_config}")
commandargs.append(f"--dl1-prod-id={sequence.dl1_prod_id}")

if not options.no_dl2 and not options.no_dl1ab:
sequence.rf_model = get_RF_model(sequence.run)
nsb_prod_id = get_dl2_nsb_prod_id(sequence.rf_model)
sequence.dl2_prod_id = f"{sequence.dl1_prod_id}/{nsb_prod_id}"
commandargs.append(f"--rf-model-path={sequence.rf_model}")
commandargs.append(f"--dl2-prod-id={sequence.dl2_prod_id}")

content = job_header + "\n" + PYTHON_IMPORTS

if not options.test:
Expand Down
10 changes: 9 additions & 1 deletion src/osa/nightsummary/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from osa.job import sequence_filenames
from osa.nightsummary import database
from osa.nightsummary.nightsummary import run_summary_table
from osa.paths import sequence_calibration_files, get_run_date
from osa.paths import sequence_calibration_files, get_run_date, get_dl1_prod_id_and_config, get_dl2_prod_id
from osa.utils.logging import myLogger
from osa.utils.utils import date_to_iso, date_to_dir

Expand Down Expand Up @@ -263,6 +263,14 @@ def extract_sequences(date: datetime, run_obj_list: List[RunObj]) -> List[Sequen
f"Data sequence {sequence.seq} from run {run.run} whose parent is "
f"{sequence.parent} (DRS4 {required_drs4_run} & Ped-Cal {required_pedcal_run})"
)
if not options.no_dl1ab and sequence.type=="DATA":
dl1_prod_id, dl1b_config = get_dl1_prod_id_and_config(sequence.run)
sequence.dl1_prod_id = dl1_prod_id
sequence.dl1b_config = dl1b_config

if not options.no_dl2 and not options.no_dl1ab and sequence.type=="DATA":
sequence.dl2_prod_id = get_dl2_prod_id(sequence.run)

sequence_list.append(sequence)

# Add the calibration file names
Expand Down
Loading
Loading