-
Notifications
You must be signed in to change notification settings - Fork 270
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
Improvements to Tool and Component functionality #1052
Conversation
- `get_current_config()` returns the *full* configuration of the instance, unlike the `.config` attribute which only returns the non-default settings. This includes even changes made during the running of the program, not from the input configuration files. - added a nicer HTML repr for notebooks -
For an example of the experimental YAML output: print(export_tool_config_to_commented_yaml(tool))
#------------------------------------------------------------------------------
# DisplayIntegrator(Tool) configuration
#------------------------------------------------------------------------------
DisplayIntegrator:
# Channel to view
# Choices: any of [0, 1]
# Default: 0
channel: 0
# name of a configuration file with parameters to load in addition
# to command-line parameters
# Default: ''
config_file: ""
# Event index to view.
# Default: 0
event_index: 0
# ImageExtractor to use.
# Choices: any of ['FullWaveformSum', 'FixedWindowSum',
# 'GlobalPeakWindowSum', 'LocalPeakWindowSum',
# 'NeighborPeakWindowSum',
# 'BaselineSubtractedNeighborPeakWindowSum'] or None
# Default: 'NeighborPeakWindowSum'
extractor_product: "NeighborPeakWindowSum"
# The date format used by logging formatters for %(asctime)s
# Default: '%Y-%m-%d %H:%M:%S'
log_datefmt: "%Y-%m-%d %H:%M:%S"
# The Logging format template
# Default: '%(levelname)s [%(name)s] (%(module)s/%(funcName)s):
# %(message)s'
log_format: "%(levelname)s [%(name)s] (%(module)s/%(funcName)s): %(message)s"
# Set the log level by value or name.
# Choices: any of (0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN',
# 'ERROR', 'CRITICAL')
# Default: 30
log_level: 20
# Telescope to view. Set to None to display the firsttelescope
# with data.
# Default: None
telescope: None
# event_index will obtain an event using event_id instead of
# index.
# Default: False
use_event_id: False |
Codecov Report
@@ Coverage Diff @@
## master #1052 +/- ##
==========================================
+ Coverage 83.44% 83.71% +0.26%
==========================================
Files 181 179 -2
Lines 10439 10548 +109
==========================================
+ Hits 8711 8830 +119
+ Misses 1728 1718 -10
Continue to review full report at Codecov.
|
- properly set the default log_format trait - allow Component *instances* to be registered (so we can get their config later) - added `get_current_config()`, similar to the one in Component, but returning the actual config for the Tool instance + all registered Component instances - add the full instance config to the provenance system - added an HTML repr for notebooks - fixed a type in test_component_current_config() - add tool example - always log the config (as info not debug) - ensure allowed_tels is a set internally - make sure set() is JSON serializable - show difference to default value in written config - added tests for new tool functionality - Update notebooks
1f36b11
to
9e94133
Compare
…nto feature/improve-tool
…nto feature/improve-tool
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.
Just some minor comments for now
ctapipe/core/tool.py
Outdated
help='The Logging format template' | ||
).tag(config=True) | ||
|
||
log_format = Unicode( |
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 duplicate intentional?
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.
Nope! I'll fix it
ctapipe/tools/display_dl1.py
Outdated
True, | ||
help='Display the photoelectron images on-screen as they ' | ||
'are produced.' | ||
True, help="Display the photoelectron images on-screen as they " "are produced." |
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.
Extra "" or new line?
ctapipe/tools/display_dl1.py
Outdated
@@ -137,41 +142,31 @@ class DisplayDL1Calib(Tool): | |||
telescope = Int( | |||
None, | |||
allow_none=True, | |||
help='Telescope to view. Set to None to display all ' | |||
'telescopes.' | |||
help="Telescope to view. Set to None to display all " "telescopes.", |
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.
Extra ""
ctapipe/tools/display_dl1.py
Outdated
"Display the photoelectron images on-screen as they " | ||
"are produced." | ||
{"ImagePlotter": {"display": True}}, | ||
"Display the photoelectron images on-screen as they " "are produced.", |
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.
Extra ""
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.
thanks- seems to be due to reformatting (strings like that get concatenated, but there's no need in this case)
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.
Looks good
This PR is part of an effort to make some standard tools for DL1/DL2 production in ctapipe. One of the things I found lacking was the ability to see what the full configuration that was used in a Tool (i.e. the Tool's
config
attribute only gives you the options the user passed in, not the values used).To make it possible to generate a fully populated config dictionary for a Component or Tool, this adds a few features:
get_current_config()
method that returns the full config for an instance (this was only possibly for a Class withtraitlets.config.Application
). This is automatically registered with the Provenance system duringTool.run()
export_tool_to_commented_yaml
function which takes a tool and its current config and writes out a YAML file with correct comments (it's a bit of a hack based on thetraitlets.Application.write_config()
code,, so perhaps not ready for production use, but it's a step in the direction of being able to read and write YAML configurations (so far only JSON and Python are supported for reading)ctapipe.utils.tools
has now moved toctapipe.core.traits
(both packages had similar scope)e.g.:
Then when one wants to get the full config, it looks like this:
In making this update, I ran into a lot of confusion and undocumented features of
traitlets.config
, so it might be better later to re-implementtraitlets.config.Application
altogether (I started a small notebook to explore that, seen here: https://gist.github.com/kosack/8158a2748a458bbece74a010abb02d3c but found that it is too much effort to get all the functionality now. Perhaps somebody else has the time)