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 Cat-B calibration onsite scripts #1147

Merged
merged 64 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
3222b66
first changes for adding cat-B online script
FrancaCassol Jun 22, 2023
c29332a
Add CatA key
FrancaCassol Jul 24, 2023
797b91e
prepare for calibration key change
FrancaCassol Jul 24, 2023
d2c1ad4
Add function to find interleaved files
FrancaCassol Jul 24, 2023
55df1e8
Add trailet to run on few subruns , for debugging
FrancaCassol Jul 24, 2023
c1efdbf
Add CatB default config variable
FrancaCassol Jul 24, 2023
2b7e91f
onsite script for CatB calibration
FrancaCassol Jul 25, 2023
78e49dd
Eliminate double argument and add missing argument
FrancaCassol Jul 25, 2023
9a8e180
improve sintax
FrancaCassol Jul 25, 2023
1d7c33b
Add script to send Cat-B calibration in batch
FrancaCassol Jul 25, 2023
069606b
correct scaling ratio
FrancaCassol Jul 25, 2023
dacf286
remove scaling ratio
FrancaCassol Jul 25, 2023
dc6ddf4
improvements of the scripts
FrancaCassol Jul 25, 2023
2cf8dbb
Merge branch 'main' of github.com:cta-observatory/cta-lstchain into c…
FrancaCassol Aug 30, 2023
a317154
Improve trailet help
FrancaCassol Aug 30, 2023
d66d1b1
Introduce DataCategory class
FrancaCassol Aug 30, 2023
1a4e639
add test for find_calibration_file
FrancaCassol Aug 30, 2023
2c3670f
change argumennt classes in order to overwrite config values
FrancaCassol Aug 30, 2023
47c72d6
correct category type
FrancaCassol Aug 31, 2023
207e802
minor improvements
FrancaCassol Aug 31, 2023
b80bc99
- correct filter search errors
FrancaCassol Sep 4, 2023
ed349cd
Write interleaved in dir DL1/interleaved
FrancaCassol Sep 4, 2023
f297c61
Write interleaved in dir DL1/interleaved
FrancaCassol Sep 4, 2023
b1d8b8b
Keep generic comment
FrancaCassol Sep 4, 2023
dfd4734
check if not simu
FrancaCassol Sep 4, 2023
26200d5
create interleaved output dir in the data tree
FrancaCassol Sep 5, 2023
83d6abe
Add fixture for interleaved r1 file build from pedcal run
maxnoe Sep 5, 2023
ce9d75e
check interleaved production
FrancaCassol Sep 6, 2023
5e50706
Merge branch 'ctaB_online_script' of github.com:cta-observatory/cta-l…
FrancaCassol Sep 6, 2023
4eaba9a
add test for cat-A calibration script
FrancaCassol Sep 8, 2023
f8a24e2
first version to be finalized
FrancaCassol Sep 15, 2023
54ee2a6
minor changes
FrancaCassol Sep 15, 2023
f76cc63
correct format
FrancaCassol Sep 15, 2023
4e272b2
Make test_data path absolute
maxnoe Sep 15, 2023
2cf44da
Remove file accidentaly commited
maxnoe Sep 15, 2023
cc98f78
Fix path in interleaved_r1_file fixture
maxnoe Sep 15, 2023
bdaaee1
correct batch script
FrancaCassol Sep 19, 2023
8bffa63
Merge branch 'ctaB_online_script' of github.com:cta-observatory/cta-l…
FrancaCassol Sep 19, 2023
af6d96c
Put correct default stat
FrancaCassol Sep 19, 2023
b77f61c
correct time correction sign
FrancaCassol Sep 20, 2023
e47afe1
Correct npe cut estimation
FrancaCassol Sep 20, 2023
bdc8a65
minor change
FrancaCassol Sep 20, 2023
9a10672
set maximum of unusable pixels to exclude bad time intervals
FrancaCassol Sep 21, 2023
6b74a64
Add number of unusable pixel
FrancaCassol Oct 3, 2023
48c5955
check dl2 event number
FrancaCassol Oct 3, 2023
1274a12
change default mongo DB url
FrancaCassol Oct 3, 2023
c2c4fb3
specify DB
FrancaCassol Oct 3, 2023
02f4fd1
correct the expected npe std
FrancaCassol Oct 4, 2023
e6d7f73
update test calibration modules
FrancaCassol Oct 4, 2023
9cfce97
Merge branch 'main' of github.com:cta-observatory/cta-lstchain into c…
FrancaCassol Oct 4, 2023
615e46f
Minor improvements
FrancaCassol Oct 4, 2023
1ead293
Add elements to nitpick_ignore
FrancaCassol Oct 4, 2023
7967446
corrent output dir
FrancaCassol Oct 4, 2023
d22f480
Do not write empty dl2 file
FrancaCassol Oct 5, 2023
8d41eb0
Update plot function to write correct units for the two calibration t…
FrancaCassol Oct 6, 2023
d4df4ba
correct if statement
FrancaCassol Oct 10, 2023
5726b64
correct calibration key
FrancaCassol Oct 12, 2023
c7079b8
improve key naming
FrancaCassol Oct 31, 2023
8345bbd
add gti (good time interval) column to calibration table
FrancaCassol Oct 31, 2023
c51353c
change name of data source dependent data frame
FrancaCassol Oct 31, 2023
8b2815e
Add function to select events in GTI
FrancaCassol Oct 31, 2023
30b5226
Sintax corrections
FrancaCassol Nov 2, 2023
4620173
correct name
FrancaCassol Nov 2, 2023
045a5fd
Update lstchain/reco/utils.py
FrancaCassol Nov 3, 2023
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 lstchain/calib/camera/calibration_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class CalibrationCalculator(Component):
).tag(config=True)

hg_lg_ratio = traits.Float(
17.4,
help='HG/LG ratio applied if use_scaled_low_gain is True'
1.,
help='HG/LG ratio applied if use_scaled_low_gain is True. In case of calibrated data the ratio should be 1.'
FrancaCassol marked this conversation as resolved.
Show resolved Hide resolved
).tag(config=True)

classes = (
Expand Down
1 change: 0 additions & 1 deletion lstchain/data/catB_camera_calibration_param.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"LSTCalibrationCalculator": {
"squared_excess_noise_factor": 1.222,
"use_scaled_low_gain": true,
"hg_lg_ratio": 17.4,
"npe_median_cut_outliers": [-5,5],
"flatfield_product": "FlasherFlatFieldCalculator",
"pedestal_product": "PedestalIntegrator"
Expand Down
13 changes: 9 additions & 4 deletions lstchain/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
dl1_params_tel_mon_ped_key = "/dl1/event/telescope/monitoring/pedestal"
dl1_params_tel_mon_cal_key = "/dl1/event/telescope/monitoring/calibration"
dl1_params_tel_mon_flat_key = "/dl1/event/telescope/monitoring/flatfield"
dl1_params_tel_mon_CatA_ped_key = "/dl1/monitoring/telescope/CatA/pedestal"
dl1_params_tel_mon_CatA_flat_key = "/dl1/monitoring/telescope/CatA/flatfield"
dl1_params_tel_mon_CatA_cal_key = "/dl1/monitoring/telescope/CatA/calibration"

dl1_params_lstcam_key = "/dl1/event/telescope/parameters/LST_LSTCam"
dl1_images_lstcam_key = "/dl1/event/telescope/image/LST_LSTCam"
dl2_params_lstcam_key = "/dl2/event/telescope/parameters/LST_LSTCam"
FrancaCassol marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -815,7 +819,7 @@ def recursive_copy_node(src_file, dir_file, path):
recursive_path = os.path.join(recursive_path, p)


def write_calibration_data(writer, mon_index, mon_event, new_ped=False, new_ff=False):
def write_calibration_data(writer, table_group, mon_index, mon_event, new_ped=False, new_ff=False):
FrancaCassol marked this conversation as resolved.
Show resolved Hide resolved
mon_event.pedestal.prefix = ''
mon_event.flatfield.prefix = ''
mon_event.calibration.prefix = ''
Expand All @@ -831,21 +835,22 @@ def write_calibration_data(writer, mon_index, mon_event, new_ped=False, new_ff=F

if new_ped:
# write ped container
print(f"{table_group}/pedestal")
FrancaCassol marked this conversation as resolved.
Show resolved Hide resolved
writer.write(
table_name="telescope/monitoring/pedestal",
table_name=f"{table_group}/pedestal",
containers=[mon_index, mon_event.pedestal],
)

if new_ff:
# write calibration container
writer.write(
table_name="telescope/monitoring/flatfield",
table_name=f"{table_group}/flatfield",
containers=[mon_index, mon_event.flatfield],
)

# write ff container
writer.write(
table_name="telescope/monitoring/calibration",
table_name=f"{table_group}/calibration",
containers=[mon_index, mon_event.calibration],
)

Expand Down
113 changes: 109 additions & 4 deletions lstchain/onsite.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
from pkg_resources import resource_filename
from datetime import datetime
import tempfile
from astropy.time import Time
import pymongo

from .paths import parse_calibration_name

DEFAULT_BASE_PATH = Path('/fefs/aswg/data/real')
DEFAULT_R0_PATH = DEFAULT_BASE_PATH / 'R0'
LEVEL_A_PIXEL_DIR = 'monitoring/PixelCalibration/Cat-A'
DEFAULT_DL1_PATH = DEFAULT_BASE_PATH / 'DL1'
CAT_A_PIXEL_DIR = 'monitoring/PixelCalibration/Cat-A'
CAT_B_PIXEL_DIR = 'monitoring/PixelCalibration/Cat-B'

DEFAULT_CONFIG = Path(resource_filename(
'lstchain',
"data/onsite_camera_calibration_param.json",
))
DEFAULT_CONFIG_CAT_B_CALIB = Path(resource_filename(
'lstchain',
"data/catB_camera_calibration_param.json",
))


def is_date(s):
Expand Down Expand Up @@ -88,7 +96,7 @@

def find_pedestal_file(pro, pedestal_run=None, date=None, base_dir=DEFAULT_BASE_PATH):
# pedestal base dir
ped_dir = Path(base_dir) / LEVEL_A_PIXEL_DIR / "drs4_baseline"
ped_dir = Path(base_dir) / CAT_A_PIXEL_DIR / "drs4_baseline"

if pedestal_run is None and date is None:
raise ValueError('Must give at least `date` or `run`')
Expand Down Expand Up @@ -123,7 +131,7 @@
def find_time_calibration_file(pro, run, time_run=None, base_dir=DEFAULT_BASE_PATH):
'''Find a time calibration file for given run
'''
time_dir = Path(base_dir) / LEVEL_A_PIXEL_DIR / "drs4_time_sampling_from_FF"
time_dir = Path(base_dir) / CAT_A_PIXEL_DIR / "drs4_time_sampling_from_FF"


# search the last time run before or equal to the calibration run
Expand Down Expand Up @@ -155,7 +163,7 @@


def find_systematics_correction_file(pro, date, sys_date=None, base_dir=DEFAULT_BASE_PATH):
sys_dir = Path(base_dir) / LEVEL_A_PIXEL_DIR / "ffactor_systematics"
sys_dir = Path(base_dir) / CAT_A_PIXEL_DIR / "ffactor_systematics"

if sys_date is not None:
path = (sys_dir / sys_date / pro / f"ffactor_systematics_{sys_date}.h5").resolve()
Expand All @@ -171,3 +179,100 @@
selected_date = next((day for day in sys_date_list if day <= date), sys_date_list[-1])

return (sys_dir / selected_date / pro / f"ffactor_systematics_{selected_date}.h5").resolve()

def find_calibration_file(pro, calibration_run=None, date=None, category='Cat_A',base_dir=DEFAULT_BASE_PATH):
FrancaCassol marked this conversation as resolved.
Show resolved Hide resolved
# pedestal base dir

if category == 'Cat_A':
FrancaCassol marked this conversation as resolved.
Show resolved Hide resolved
cal_dir = Path(base_dir) / CAT_A_PIXEL_DIR / "calibration"
elif category == 'Cat_B':
cal_dir = Path(base_dir) / CAT_B_PIXEL_DIR / "calibration"

Check warning on line 189 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L186-L189

Added lines #L186 - L189 were not covered by tests
else:
raise ValueError(f'Argument \'category\' can be only \'Cat_A\' or \'Cat_B\', not {category}')

Check warning on line 191 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L191

Added line #L191 was not covered by tests

if calibration_run is None and date is None:
raise ValueError('Must give at least `date` or `run`')

Check warning on line 194 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L193-L194

Added lines #L193 - L194 were not covered by tests

if calibration_run is not None:

Check warning on line 196 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L196

Added line #L196 was not covered by tests
# search a specific calibration run
file_list = sorted(cal_dir.rglob(f'{pro}/calibration*.Run{calibration_run:05d}.0000.h5'))

Check warning on line 198 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L198

Added line #L198 was not covered by tests

if len(file_list) == 0:
raise IOError(f"Calibration file from run {calibration_run} not found\n")

Check warning on line 201 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L200-L201

Added lines #L200 - L201 were not covered by tests

return file_list[0].resolve()

Check warning on line 203 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L203

Added line #L203 was not covered by tests

# search for a unique calibration file from the same date
file_list = sorted((cal_dir / date / pro).glob('calibration*.0000.h5'))
if len(file_list) == 0:
raise IOError(f"No calibration file found for date {date}")

Check warning on line 208 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L206-L208

Added lines #L206 - L208 were not covered by tests

if len(file_list) > 1:
raise IOError(f"Too many calibration files found for date {date}: {file_list}, choose one run\n")

Check warning on line 211 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L210-L211

Added lines #L210 - L211 were not covered by tests

return file_list[0].resolve()

Check warning on line 213 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L213

Added line #L213 was not covered by tests

def find_DL1_subrun(run, sub_run, dl1_dir=DEFAULT_DL1_PATH):
'''
Find the given subrun DL1 file (i.e. globbing for the date part)
'''
file_list = rglob_symlinks(dl1_dir, f'dl1_LST-1.1.Run{run:05d}.{sub_run:04d}*.h5')

Check warning on line 219 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L219

Added line #L219 was not covered by tests
# ignore directories that are not a date, e.g. "Trash"
file_list = [p for p in file_list if is_date(p.parent.name)]

Check warning on line 221 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L221

Added line #L221 was not covered by tests

if len(file_list) == 0:
raise IOError(f"Run {run} not found\n")

Check warning on line 224 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L223-L224

Added lines #L223 - L224 were not covered by tests

if len(file_list) > 1:
raise IOError(f"Found more than one file for run {run}.{sub_run}: {file_list}")

Check warning on line 227 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L226-L227

Added lines #L226 - L227 were not covered by tests

return file_list[0]

Check warning on line 229 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L229

Added line #L229 was not covered by tests

def find_interleaved_subruns(run, dl1_dir=DEFAULT_DL1_PATH):
'''
Find the given subrun interleaved file (i.e. globbing for the date part)
'''
file_list = rglob_symlinks(dl1_dir, f'interleaved_LST-1.Run{run:05d}.*.h5')

Check warning on line 235 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L235

Added line #L235 was not covered by tests
FrancaCassol marked this conversation as resolved.
Show resolved Hide resolved
# ignore directories that are not a date, e.g. "Trash"
file_list = [p for p in file_list if is_date(p.parent.name)]

Check warning on line 237 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L237

Added line #L237 was not covered by tests

if len(file_list) == 0:
raise IOError(f"Run {run} not found\n")

Check warning on line 240 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L239-L240

Added lines #L239 - L240 were not covered by tests

return file_list

Check warning on line 242 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L242

Added line #L242 was not covered by tests


def find_filter_wheels(run, database_url):
FrancaCassol marked this conversation as resolved.
Show resolved Hide resolved
"""read the employed filters from mongodb"""

# there was a change of Mongo DB data names on 5/12/2022
NEW_DB_NAMES_DATE = Time("2022-12-04T00:00:00")

Check warning on line 249 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L249

Added line #L249 was not covered by tests

filters = None
try:

Check warning on line 252 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L251-L252

Added lines #L251 - L252 were not covered by tests

myclient = pymongo.MongoClient(database_url)

Check warning on line 254 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L254

Added line #L254 was not covered by tests

mydb = myclient["CACO"]
mycol = mydb["RUN_INFORMATION"]
mydoc = mycol.find({"run_number": {"$eq": run}})
for x in mydoc:
date = Time(x["start_time"])
if date < NEW_DB_NAMES_DATE:
w1 = int(x["cbox"]["wheel1 position"])
w2 = int(x["cbox"]["wheel2 position"])

Check warning on line 263 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L256-L263

Added lines #L256 - L263 were not covered by tests
else:
w1 = int(x["cbox"]["CBOX_WheelPosition1"])
w2 = int(x["cbox"]["CBOX_WheelPosition2"])

Check warning on line 266 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L265-L266

Added lines #L265 - L266 were not covered by tests

filters = f"{w1:1d}{w2:1d}"

Check warning on line 268 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L268

Added line #L268 was not covered by tests

except Exception as e:
print(f"\n >>> Exception: {e}")
FrancaCassol marked this conversation as resolved.
Show resolved Hide resolved
raise IOError(

Check warning on line 272 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L270-L272

Added lines #L270 - L272 were not covered by tests
"--> No mongo DB filter information."
" You must pass the filters by argument: -f [filters]"
)

return filters

Check warning on line 277 in lstchain/onsite.py

View check run for this annotation

Codecov / codecov/patch

lstchain/onsite.py#L277

Added line #L277 was not covered by tests

7 changes: 6 additions & 1 deletion lstchain/reco/r0_to_dl1.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@ def r0_to_dl1(
add_config_metadata(container, config)

# write the first calibration event (initialized from calibration h5 file)
# these data a supposed to change table_path with "dl1/monitoring/telescope/CatA" in short future
write_calibration_data(writer,
'telescope/monitoring',
calibration_index,
event.mon.tel[tel_id],
new_ped=True, new_ff=True)
Expand All @@ -520,8 +522,10 @@ def r0_to_dl1(
new_ped_event, new_ff_event = calibration_calculator.process_interleaved(event)

# write monitoring containers if updated
# these data a supposed to be replaced by the Cat_B data in a short future
FrancaCassol marked this conversation as resolved.
Show resolved Hide resolved
if new_ped_event or new_ff_event:
write_calibration_data(writer,
'telescope/monitoring',
calibration_index,
event.mon.tel[tel_id],
new_ped=new_ped_event, new_ff=new_ff_event)
Expand Down Expand Up @@ -756,7 +760,8 @@ def r0_to_dl1(
# at the end of event loop ask calculation of remaining interleaved statistics
new_ped, new_ff = calibration_calculator.output_interleaved_results(event)
# write monitoring events
write_calibration_data(writer,
# these data a supposed to be replaced by the Cat_B data in a short future
FrancaCassol marked this conversation as resolved.
Show resolved Hide resolved
write_calibration_data(writer,'telescope/monitoring',
calibration_index,
event.mon.tel[tel_id],
new_ped=new_ped, new_ff=new_ff)
Expand Down
44 changes: 4 additions & 40 deletions lstchain/scripts/onsite/onsite_create_calibration_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import subprocess
import sys
from pathlib import Path
from astropy.time import Time
import pymongo

import lstchain
import lstchain.visualization.plot_calib as calib
Expand All @@ -23,13 +21,14 @@
from lstchain.onsite import (
DEFAULT_BASE_PATH,
DEFAULT_CONFIG,
LEVEL_A_PIXEL_DIR,
CAT_A_PIXEL_DIR,
create_pro_symlink,
find_r0_subrun,
find_pedestal_file,
find_run_summary,
find_systematics_correction_file,
find_time_calibration_file,
find_filter_wheels,
)

# parse arguments
Expand Down Expand Up @@ -118,7 +117,7 @@

# looks for the filter values in the database if not given
if args.filters is None:
filters = search_filter(run, args.mongodb)
filters = find_filter_wheels(run, args.mongodb)

Check warning on line 120 in lstchain/scripts/onsite/onsite_create_calibration_file.py

View check run for this annotation

Codecov / codecov/patch

lstchain/scripts/onsite/onsite_create_calibration_file.py#L120

Added line #L120 was not covered by tests
else:
filters = args.filters

Expand Down Expand Up @@ -146,7 +145,7 @@
print(f"\n--> Input file: {input_file}")

# verify output dir
calib_dir = args.base_dir / LEVEL_A_PIXEL_DIR
calib_dir = args.base_dir / CAT_A_PIXEL_DIR

Check warning on line 148 in lstchain/scripts/onsite/onsite_create_calibration_file.py

View check run for this annotation

Codecov / codecov/patch

lstchain/scripts/onsite/onsite_create_calibration_file.py#L148

Added line #L148 was not covered by tests
output_dir = calib_dir / "calibration" / date / prod_id
if not output_dir.exists():
print(f"--> Create directory {output_dir}")
Expand Down Expand Up @@ -253,41 +252,6 @@
print("\n--> END")


def search_filter(run, database_url):
"""read the employed filters form mongodb"""

# there was a change of Mongo DB data names on 5/12/2022
NEW_DB_NAMES_DATE = Time("2022-12-04T00:00:00")

filters = None
try:

myclient = pymongo.MongoClient(database_url)

mydb = myclient["CACO"]
mycol = mydb["RUN_INFORMATION"]
mydoc = mycol.find({"run_number": {"$eq": run}})
for x in mydoc:
date = Time(x["start_time"])
if date < NEW_DB_NAMES_DATE:
w1 = int(x["cbox"]["wheel1 position"])
w2 = int(x["cbox"]["wheel2 position"])
else:
w1 = int(x["cbox"]["CBOX_WheelPosition1"])
w2 = int(x["cbox"]["CBOX_WheelPosition2"])

filters = f"{w1:1d}{w2:1d}"

except Exception as e:
print(f"\n >>> Exception: {e}")
raise IOError(
"--> No mongo DB filter information."
" You must pass the filters by argument: -f [filters]"
)

return filters


def define_FF_selection_range(filters):
""" return the range of charges to select the FF events """

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import lstchain
from lstchain.onsite import (
DEFAULT_BASE_PATH,
LEVEL_A_PIXEL_DIR,
CAT_A_PIXEL_DIR,
find_r0_subrun,
DEFAULT_CONFIG,
)
Expand Down Expand Up @@ -111,7 +111,7 @@

output_base_name = args.output_base_name

calib_dir = base_dir / LEVEL_A_PIXEL_DIR
calib_dir = base_dir / CAT_A_PIXEL_DIR

Check warning on line 114 in lstchain/scripts/onsite/onsite_create_calibration_files_with_batch.py

View check run for this annotation

Codecov / codecov/patch

lstchain/scripts/onsite/onsite_create_calibration_files_with_batch.py#L114

Added line #L114 was not covered by tests

if shutil.which('srun') is None:
sys.exit(">>> This script needs a slurm batch system. Stop")
Expand Down Expand Up @@ -178,7 +178,6 @@
f"--sub_run={sub_run}",
f"-b {base_dir}",
f"-s {stat_events}",
f"--r0-dir={r0_dir}",
f"--output_base_name={output_base_name}",
f"--config={config_file}",
]
Expand Down Expand Up @@ -207,6 +206,9 @@
if args.use_flatfield_heuristic is False:
cmd.append("--no-flatfield-heuristic")

if args.no_pro_symlink is True:
cmd.append("--no_pro_symlink")

Check warning on line 210 in lstchain/scripts/onsite/onsite_create_calibration_files_with_batch.py

View check run for this annotation

Codecov / codecov/patch

lstchain/scripts/onsite/onsite_create_calibration_files_with_batch.py#L209-L210

Added lines #L209 - L210 were not covered by tests

cmd.extend(remaining_args)

# join command together with newline, line continuation and indentation
Expand Down
Loading
Loading