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

Tool to produce a time calibration HDF5 file #533

Closed
wants to merge 14 commits into from
Closed

Tool to produce a time calibration HDF5 file #533

wants to merge 14 commits into from

Conversation

Bultako
Copy link
Collaborator

@Bultako Bultako commented Oct 5, 2020

This PR adds a new Tool lstchain_create_time_calibration_file

lstchain_create_time_calibration_file --help-all
Generate a HDF5 file with time calibration coefficients

Options
-------

Arguments that take values are actually convenience aliases to full
Configurables, whose aliases are listed on the help line. For more information
on full configurables, see '--help-all'.

--input=<Path> (TimeCalibrationHDF5Writer.input)
    Default: None
    Path to the fits.fz events file or directory to glob
--glob=<Unicode> (TimeCalibrationHDF5Writer.glob)
    Default: '*'
    Filename pattern to glob files in the directory
--output=<Unicode> (TimeCalibrationHDF5Writer.output)
    Default: ''
    Path to the hdf5 time calibration file
--pedestal=<Unicode> (LSTR0Corrections.pedestal_path)
    Default: ''
    Path to the LST pedestal binary file
--max_events=<Int> (TimeCalibrationHDF5Writer.max_events)
    Default: 20000
    Maximum numbers of events to read. Default = 20000
--log-level=<Enum> (Application.log_level)
    Default: 30
    Choices: (0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL')
    Set the log level by value or name.
--config=<Path> (Tool.config_file)
    Default: None
    name of a configuration file with parameters to load in addition to command-
    line parameters

Class parameters
----------------

Parameters are set from command-line arguments of the form:
`--Class.trait=value`. This line is evaluated in Python, so simple expressions
are allowed, e.g.:: `--C.a='range(3)'` For setting C.a=[0,1,2].

TimeCalibrationHDF5Writer options
---------------------------------
--TimeCalibrationHDF5Writer.config_file=<Path>
    Default: None
    name of a configuration file with parameters to load in addition to command-
    line parameters
--TimeCalibrationHDF5Writer.glob=<Unicode>
    Default: '*'
    Filename pattern to glob files in the directory
--TimeCalibrationHDF5Writer.input=<Path>
    Default: None
    Path to the fits.fz events file or directory to glob
--TimeCalibrationHDF5Writer.log_datefmt=<Unicode>
    Default: '%Y-%m-%d %H:%M:%S'
    The date format used by logging formatters for %(asctime)s
--TimeCalibrationHDF5Writer.log_format=<Unicode>
    Default: '%(levelname)s [%(name)s] (%(module)s/%(funcName)s): %(messag...
    The Logging format template
--TimeCalibrationHDF5Writer.log_level=<Enum>
    Default: 30
    Choices: (0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL')
    Set the log level by value or name.
--TimeCalibrationHDF5Writer.max_events=<Int>
    Default: 20000
    Maximum numbers of events to read. Default = 20000
--TimeCalibrationHDF5Writer.output=<Unicode>
    Default: ''
    Path to the hdf5 time calibration file
--TimeCalibrationHDF5Writer.pedestal=<Unicode>
    Default: ''
    Path to drs4 fits pedestal file
--TimeCalibrationHDF5Writer.progress_bar=<Bool>
    Default: True
    show progress bar during processing

LSTEventSource options
----------------------
--LSTEventSource.allowed_tels=<Set>
    Default: set()
    list of allowed tel_ids, others will be ignored. If None, all telescopes in
    the input stream will be included
--LSTEventSource.baseline=<Int>
    Default: 400
    r0 waveform baseline (default from EvB v3)
--LSTEventSource.input_url=<Path>
    Default: None
    Path to the input file containing events.
--LSTEventSource.max_events=<Int>
    Default: None
    Maximum number of events that will be read from the file
--LSTEventSource.multi_streams=<Bool>
    Default: True
    Read in parallel all streams
--LSTEventSource.n_gains=<Int>
    Default: 2
    Number of gains at r0/r1 level

LSTR0Corrections options
------------------------
--LSTR0Corrections.offset=<Int>
    Default: 400
    Define the offset of the baseline
--LSTR0Corrections.pedestal_path=<Unicode>
    Default: ''
    Path to the LST pedestal binary file
--LSTR0Corrections.r1_sample_end=<Int>
    Default: 39
    End sample for r1 waveform
--LSTR0Corrections.r1_sample_start=<Int>
    Default: 3
    Start sample for r1 waveform
--LSTR0Corrections.tel_id=<Int>
    Default: 1
    id of the telescope to calibrate

TimeCorrectionCalculate options
-------------------------------
--TimeCorrectionCalculate.calib_file_path=<Unicode>
    Default: ''
    Path to the time calibration file
--TimeCorrectionCalculate.charge_product=<Unicode>
    Default: 'LocalPeakWindowSum'
    Name of the charge extractor to be used
--TimeCorrectionCalculate.minimum_charge=<Float>
    Default: 200
    Cut on charge. Default 200 ADC
--TimeCorrectionCalculate.n_capacitors=<Int>
    Default: 1024
    Number of capacitors (1024 or 4096). Default 1024.
--TimeCorrectionCalculate.n_combine=<Int>
    Default: 8
    How many capacitors are combines in a single bin. Default 8
--TimeCorrectionCalculate.n_harmonics=<Int>
    Default: 16
    Number of harmonic for Fourier series expansion. Default 16
--TimeCorrectionCalculate.tel_id=<Int>
    Default: 1
    Id of the telescope to calibrate

@codecov
Copy link

codecov bot commented Oct 5, 2020

Codecov Report

Merging #533 (e64873c) into master (370ab58) will decrease coverage by 0.23%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #533      +/-   ##
==========================================
- Coverage   37.46%   37.23%   -0.24%     
==========================================
  Files          83       84       +1     
  Lines        7425     7471      +46     
==========================================
  Hits         2782     2782              
- Misses       4643     4689      +46     
Impacted Files Coverage Δ
...ain/tools/lstchain_create_time_calibration_file.py 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 370ab58...e64873c. Read the comment docs.

FrancaCassol
FrancaCassol previously approved these changes Oct 6, 2020
help="Path to the input file containing events (wildcards allowed)",
).tag(config=True)

output_file = traits.Unicode(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paths should be ctapipe.core.traits.Path traitlets

reader = LSTEventSource(input_url=self.path_list[0], max_events=self.max_events)
self.lst_r0 = LSTR0Corrections(
pedestal_path=self.pedestal_file,
config=self.config,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All sub-components of a tool need to be passed parent=self instead of config=self.config to work properly


try:
for j, path in enumerate(self.path_list):
reader = LSTEventSource(input_url=self.path_list[0], max_events=self.max_events)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the eventsource get path as input? Like this you are only looking at the first file.

Copy link
Member

@maxnoe maxnoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All path-like arguments should be changed from traits.Unicode to ctapipe.core.traits.Path.

All sub-components of this tool need to get the tool as parent, not the config.
So everywhere, exchange config=self.config with parent=self.
This is required for the config system to work!

To be able to store the used config in the proveance system, also self.add_component must be called.

So all subcomponents should be created like this:

class MyTool(Tool):
    ...
    def setup(self):
        self.subcomponent = self.add_component(SubComponent(parent=self))

Have a look at the ctapipe stage 1 tool here:

https://github.com/cta-observatory/ctapipe/blob/cf873ce99a42d6785cb9824dc297c8e843fc5a99/ctapipe/tools/stage1.py#L118

@Bultako
Copy link
Collaborator Author

Bultako commented Nov 24, 2020

I have updated this PR with requested changes (when possible) addressed and also new additions:

@maxnoe
Copy link
Member

maxnoe commented Nov 24, 2020

output and pedestal arguments are needed as Unicode types by the TimeCorrectionCalculate and LSTR0Corrections classes respectively

If these are already traitlets of the corresponding classes, there is no need to repeat them.

@Bultako
Copy link
Collaborator Author

Bultako commented Nov 24, 2020

You're right.
I have removed the duplicated declaration of args.

@rlopezcoto
Copy link
Contributor

Continued in #600

@rlopezcoto rlopezcoto closed this Feb 23, 2021
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants