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

Evb calibrated data #1288

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 0 additions & 6 deletions lstchain/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ def temp_dir_simulated_srcdep_files(tmp_path_factory):
return tmp_path_factory.mktemp("simulated_srcdep_files")


@pytest.mark.private_data
@pytest.fixture(scope="session")
def temp_dir_observed_files(tmp_path_factory):
"""Temporal common directory for processing observed data."""
return tmp_path_factory.mktemp("observed_files")


@pytest.mark.private_data
@pytest.fixture(scope="session")
def temp_dir_observed_srcdep_files(tmp_path_factory):
"""Temporal common directory for processing observed data."""
Expand Down Expand Up @@ -87,7 +85,6 @@ def run_summary_path(temp_dir_observed_files):
return run_summary_path


@pytest.mark.private_data
@pytest.fixture(scope="session")
def observed_dl1_files(temp_dir_observed_files, run_summary_path):
"""
Expand Down Expand Up @@ -209,7 +206,6 @@ def observed_dl1_files(temp_dir_observed_files, run_summary_path):



@pytest.mark.private_data
@pytest.fixture(scope="session")
def interleaved_r1_file(temp_dir_observed_files, run_summary_path):
test_pedcal_run = test_data / 'real/R0/20200218/LST-1.1.Run02006.0000_first50.fits.fz'
Expand Down Expand Up @@ -364,7 +360,6 @@ def rf_models_srcdep(temp_dir_simulated_srcdep_files, simulated_dl1_file, simula
}

@pytest.fixture(scope="session")
@pytest.mark.private_data
def observed_dl2_file(temp_dir_observed_files, observed_dl1_files, rf_models):
"""Produce a dl2 file from an observed dl1 file."""
real_data_dl2_file = temp_dir_observed_files / (observed_dl1_files["dl1_file1"].name.replace("dl1", "dl2"))
Expand All @@ -381,7 +376,6 @@ def observed_dl2_file(temp_dir_observed_files, observed_dl1_files, rf_models):


@pytest.fixture(scope="session")
@pytest.mark.private_data
def observed_srcdep_dl2_file(temp_dir_observed_srcdep_files, observed_dl1_files, rf_models_srcdep):
"""Produce a source-dependent dl2 file from an observed dl1 file."""
real_data_srcdep_dl2_file = temp_dir_observed_srcdep_files / (observed_dl1_files["dl1_file1"].name.replace("dl1", "dl2"))
Expand Down
21 changes: 13 additions & 8 deletions lstchain/reco/r0_to_dl1.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,20 @@ def r0_to_dl1(
# gain select the events
source.r0_r1_calibrator.select_gain = True

r1 = event.r1.tel[tel_id]
r1.selected_gain_channel = source.r0_r1_calibrator.gain_selector(event.r0.tel[tel_id].waveform)
r1.waveform = r1.waveform[r1.selected_gain_channel, PIXEL_INDEX]

event.calibration.tel[tel_id].dl1.time_shift = \
event.calibration.tel[tel_id].dl1.time_shift[r1.selected_gain_channel, PIXEL_INDEX]

event.calibration.tel[tel_id].dl1.relative_factor = \
event.calibration.tel[tel_id].dl1.relative_factor[r1.selected_gain_channel, PIXEL_INDEX]
# perform gain selection after events have been written out so
# they can be processed like regular events
r1 = event.r1.tel[tel_id]
if r1.selected_gain_channel is None:
waveform = event.r0.tel[tel_id].waveform
if waveform is None:
waveform = r1.waveform

r1.selected_gain_channel = source.r0_r1_calibrator.gain_selector(waveform)
r1.waveform = r1.waveform[r1.selected_gain_channel, PIXEL_INDEX]
dl1_calib = event.calibration.tel[tel_id].dl1
dl1_calib.time_shift = dl1_calib.time_shift[r1.selected_gain_channel, PIXEL_INDEX]
dl1_calib.relative_factor = dl1_calib.relative_factor[r1.selected_gain_channel, PIXEL_INDEX]

# Option to add nsb in waveforms
if nsb_tuning:
Expand Down
2 changes: 0 additions & 2 deletions lstchain/scripts/tests/test_lstchain_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ def test_pixmasks_file_validity(observed_dl1_files):
pixmasks = pixmasks_file.root.selected_pixels_masks.col('pixmask')
assert pixmasks.sum() < 0.1 * len(pixmasks.flatten())

@pytest.mark.private_data
@pytest.fixture(scope="session")
def tune_nsb(mc_gamma_testfile, observed_dl1_files):
return run_program(
Expand All @@ -205,7 +204,6 @@ def tune_nsb(mc_gamma_testfile, observed_dl1_files):
)


@pytest.mark.private_data
@pytest.fixture(scope="session")
def tune_nsb_waveform(mc_gamma_testfile, observed_dl1_files):
return run_program(
Expand Down
50 changes: 50 additions & 0 deletions lstchain/tests/test_lstchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
test_r0_path2 = test_data / 'real/R0/20200218/LST-1.1.Run02008.0100_first50.fits.fz'
test_drs4_r0_path = test_data / 'real/R0/20200218/LST-1.1.Run02005.0000_first50.fits.fz'


calib_path = test_data / 'real/monitoring/PixelCalibration/Cat-A'
calib_version = 'ctapipe-v0.17'
test_calib_path = calib_path / f'calibration/20200218/{calib_version}/calibration_filters_52.Run02006.0000.h5'
Expand Down Expand Up @@ -403,3 +404,52 @@ def test_version_not_unknown():
"""
import lstchain
assert lstchain.__version__ != 'unknown'


@pytest.mark.private_data
def test_r1_to_dl1(tmp_path):
"""Test for R1 (precalibrated by EVB)"""
from lstchain.reco.r0_to_dl1 import r0_to_dl1

path = test_data / 'real/R0/20231219/LST-1.1.Run16255.0000_first50.fits.fz'
output_path = tmp_path / ('dl1_' + path.stem + '.h5')


config = deepcopy(standard_config)

lst_event_source = config['source_config']['LSTEventSource']
lst_event_source['PointingSource']['drive_report_path'] = (
test_data / 'real/monitoring/DrivePositioning/DrivePosition_log_20231219.txt'
)

r0_corrections = lst_event_source["LSTR0Corrections"]
r0_corrections['drs4_pedestal_path'] = (
test_data
/ 'real/monitoring/PixelCalibration/Cat-A/drs4_baseline/20231219/v0.10.6/'
/ 'drs4_pedestal.Run16248.0000.h5'
)
r0_corrections['calibration_path'] = (
test_data
/ 'real/monitoring/PixelCalibration/Cat-A/calibration/20231219/v0.10.6'
/ 'calibration_filters_52.Run16249.0000.h5'
)
r0_corrections['drs4_time_calibration_path'] = test_time_calib_path


r0_to_dl1(
path,
output_filename=output_path,
custom_config=config
)

with tables.open_file(output_path, 'r') as f:
images_table = f.root[dl1_images_lstcam_key]
params_table = f.root[dl1_params_lstcam_key]
assert 'image' in images_table.colnames
assert 'peak_time' in images_table.colnames
assert 'tel_id' in images_table.colnames
assert 'obs_id' in images_table.colnames
assert 'event_id' in images_table.colnames
assert 'tel_id' in params_table.colnames
assert 'event_id' in params_table.colnames
assert 'obs_id' in params_table.colnames