-
Notifications
You must be signed in to change notification settings - Fork 272
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
allow YAML and TOML config files and multiple configs #1856
allow YAML and TOML config files and multiple configs #1856
Conversation
- to avoid confusion - cleaned up imports as well
I am not such a huge fan of yml anymore... way too complex. I'd go for toml to have a simple config file format does not have the short comings of json / the unlimited power of py files |
Codecov Report
@@ Coverage Diff @@
## master #1856 +/- ##
==========================================
+ Coverage 92.00% 92.04% +0.03%
==========================================
Files 189 189
Lines 14805 14842 +37
==========================================
+ Hits 13622 13661 +39
+ Misses 1183 1181 -2
Continue to review full report at Codecov.
|
There is also an old function |
Could add TOML to this as well pretty easily. However, for nested configs, I really don't like TOML as it is harder to quickly see how it is nested. Simple YAML is pretty easy to read, I think, even if it does support some really crazy stuff. Anything is better than JSON, which is not really a configuration language, but rather just a serialization format (no comments, etc). |
Now also supports TOML: [DataWriter]
overwrite = false
write_images = true
write_parameters = true
write_stereo_shower = false
write_mono_shower = false
transform_image = true
transform_peak_time = true
[CameraCalibrator]
image_extractor_type = "NeighborPeakWindowSum"
[ImageProcessor]
image_cleaner_type = "TailcutsImageCleaner"
[DataWriter.Contact]
name = "YOUR-NAME-HERE"
email = "[email protected]"
organization = "YOUR-ORGANIZATION"
[ImageProcessor.TailcutsImageCleaner]
picture_threshold_pe = [ [ "type", "*", 10.0,], [ "type", "LST_LST_LSTCam", 5.0,], [ "type", "MST_MST_NectarCam", 5.0,], [ "type", "SST_ASTRI_CHEC", 3.0,],]
boundary_threshold_pe = [ [ "type", "*", 5.0,], [ "type", "LST_LST_LSTCam", 2.5,], [ "type", "MST_MST_NectarCam", 2.5,], [ "type", "SST_ASTRI_CHEC", 1.5,],]
min_picture_neighbors = [ [ "type", "*", 2,],]
[ImageProcessor.ImageQualityQuery]
quality_criteria = [ [ "enough_pixels", "lambda im: np.count_nonzero(im) > 2",], [ "enough_charge", "lambda im: im.sum() > 50",],]
[ShowerProcessor.ShowerQualityQuery]
quality_criteria = [ [ "enough intensity", "lambda p: p.hillas.intensity > 50",], [ "Positive width", "lambda p: p.hillas.width.value > 0",], [ "enough pixels", "lambda p: p.morphology.num_pixels > 3",],] |
Probably there is a much nicer way to format the TOML version... I need to look at the spec. That was an auto-generated conversion from the JSON. I guess there are ways to wrap the list of lists we use for TelescopeConfigs and QualityCriteria |
Any idea how to write nested lists on multiple lines correctly in TOML? I tried what I thought the manual said, and it doesn't work: This Fails to read: [ImageProcessor.TailcutsImageCleaner]
picture_threshold_pe = [
[ "type", "*", 10.0,],
[ "type", "LST_LST_LSTCam", 5.0,],
[ "type", "MST_MST_NectarCam", 5.0,],
[ "type", "SST_ASTRI_CHEC", 3.0,],
] Ah... TOML seems to be super picky about spaces after sections. Even Github won't render it
|
So TOML so far doesn't work with the
Point 1 seems overly picky. Not sure if this is a problem with the implementation (I'm using |
TOML works fine, the
So I'd just try |
Yes tomli seems to work. |
This reminds me one of the future PRs has to be to make these example files be generated automatically, including help text from the classes and trait options (similar to what traitlets.config does when it writes out sample python config files). For that, I will need to also add a way to specify which sections/classes to include in the example. Right now there are both the internal class and trait descriptions, and comments in the sample config files. That is unnecessary repetition, and things need to be updated in both places. I have to check if YAML or TOML lets you also include comments in the serialized output, or if it has to be done manually... I think not currently (except for some other implementations of yaml). |
Will need to update the config files when #1875 is merged |
…nto feature/allow_yaml_configs
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.
Can you move the configs from ctapipe/tools/tests/resources
to ctapipe/resources
? They are not really only test resources anymore
So that we don't crash if Prod5b files are processed with 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.
LGTM
* support loading config files from a YAML file * a sample YAML version of the config * add yaml example to quickstart * fixed typo * add TOML support * allow multiple config files, fixes #1732 * add config files to provenance tracker * updated help string for config_file * a better config file with lots of explanation * change Tool.config_file -> config_files since list * fix incorrect f-string (now a log statement) * update to reflect the new ShowerProcessor * move ctapipe.tools.test.resources to ctapipe.resources * require pyyaml and remove HAS_YAML
fixes #1047
fixes #1732
This adds a function to load a YAML or TOML config file just like a JSON or Python one. There is more to do to make this fully useful, but it works as is.
It also adds the ability to specify multiple config files for a tool (by using repeated
--config
options, or a list in a config file itself).For example the config file can look like: