-
Notifications
You must be signed in to change notification settings - Fork 77
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 time calibration script #261
Merged
rlopezcoto
merged 1 commit into
cta-observatory:master
from
FrancaCassol:add_time_script
Jan 16, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
lstchain/scripts/lstchain_data_create_time_calibration_file.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import argparse | ||
import numpy as np | ||
from traitlets.config.loader import Config | ||
from ctapipe.io import event_source | ||
from lstchain.calib.camera.r0 import LSTR0Corrections | ||
from lstchain.io.config import read_configuration_file | ||
from lstchain.calib.camera.time_correction_calculate import TimeCorrectionCalculate | ||
|
||
|
||
''' | ||
Script to create drs4 time correction coefficients | ||
|
||
''' | ||
|
||
parser = argparse.ArgumentParser() | ||
|
||
# Required arguments | ||
parser.add_argument("--input_file", | ||
help="Path to fitz.fz file to create pedestal file.", | ||
type=str) | ||
|
||
parser.add_argument("--output_file", | ||
help="Path where script create pedestal file", | ||
type=str) | ||
|
||
# Optional argument | ||
parser.add_argument("--max_events", | ||
help="Maximum numbers of events to read. Default = 20000", | ||
type=int, | ||
default=20000) | ||
|
||
parser.add_argument('--config_file', '-conf', action='store', type=str, | ||
dest='config_file', | ||
help='Path to a configuration file. If none is given, a standard configuration is applied', | ||
default=None | ||
) | ||
|
||
parser.add_argument('--pedestal_file', '-ped', action='store', type=str, | ||
dest='pedestal_file', | ||
help='Path to drs4 pedestal file ', | ||
default=None | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
|
||
def main(): | ||
print("--> Input file: {}".format(args.input_file)) | ||
print("--> Number of events: {}".format(args.max_events)) | ||
reader = event_source(input_url=args.input_file, max_events=args.max_events) | ||
print("--> Number of files", reader.multi_file.num_inputs()) | ||
|
||
config_dic = {} | ||
if args.config_file is not None: | ||
try: | ||
config_dic = read_configuration_file(args.config_file) | ||
|
||
except("Custom configuration could not be loaded !!!"): | ||
pass | ||
# read the configuration file | ||
config = Config(config_dic) | ||
|
||
# declare the pedestal calibrator | ||
lst_r0 = LSTR0Corrections(pedestal_path=args.pedestal_file, config=config) | ||
|
||
# declare the time corrector | ||
timeCorr = TimeCorrectionCalculate(calib_file_path=args.output_file, | ||
config=config) | ||
|
||
tel_id = timeCorr.tel_id | ||
|
||
for i, event in enumerate(reader): | ||
if event.r0.event_id % 5000 == 0: | ||
print(event.r0.event_id) | ||
|
||
lst_r0.calibrate(event) | ||
|
||
# Cut in signal to avoid cosmic events | ||
if event.r1.tel[tel_id].trigger_type == 4 or ( | ||
np.median(np.sum(event.r1.tel[tel_id].waveform[0], axis=1))> 300): | ||
|
||
timeCorr.calibrate_pulse_time(event) | ||
# write output | ||
timeCorr.finalize() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the default number of events that you are using? Or are you using
None
to read them all?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the default value, I guess @pawel21 suggested it because it is enough to get a good estimation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, thanks, @pawel21 could you confirm that this is enough to get this accepted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rlopezcoto , Yes, this should be enough to fill all bins in relative short time.