Skip to content
Snippets Groups Projects
Commit 54e27cb9 authored by Stefan Reck's avatar Stefan Reck
Browse files

added loading tomls from examples

parent c33bfa56
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,10 @@ If you have an orcasong config file, you can use it via the command line like th
orcasong run aanet_file.h5 orcasong_config.toml --detx_file detector.detx
Check out the git repo here https://git.km3net.de/ml/OrcaSong/-/tree/master/examples for some examples of config files.
For some examples of config files you can check out the git repo here
https://git.km3net.de/ml/OrcaSong/-/tree/master/examples .
These can be loaded from the command line by using the prefix
``orcasong:`` before the filename, e.g. ``orcasong:orcasong_bundle_mupage.toml``.
Alternatively, you can use the python frontend of orcasong.
See :ref:`orcasong_page` for instructions on how to do this.
......
import os
from pathlib import Path
import toml
import orcasong.core
import orcasong.extractors as extractors
......@@ -24,7 +26,9 @@ def add_parser_run(subparsers):
"run",
description='Produce a dl file from an aanet file.')
parser.add_argument('infile', type=str, help="Aanet file in h5 format.")
parser.add_argument('toml_file', type=str, help="Orcasong configuration in toml format.")
parser.add_argument('toml_file', type=str, help=(
"Orcasong configuration in toml format. Use prefix 'orcasong:' to load "
"a toml from OrcaSong/examples."))
parser.add_argument('--detx_file', type=str, default=None, help=(
"Optional detx file to calibrate on the fly. Can not be used if a "
"detx_file has also been given in the toml file."))
......@@ -39,6 +43,8 @@ def run_orcasong(infile, toml_file, detx_file=None, outfile=None):
def setup_processor(infile, toml_file, detx_file=None):
if toml_file.startswith("orcasong:"):
toml_file = _get_from_examples(toml_file[9:])
cfg = toml.load(toml_file)
processor = _get_verbose(cfg.pop("mode"), MODES)
......@@ -64,3 +70,9 @@ def _get_verbose(key, d):
if key not in d:
raise KeyError(f"Unknown key '{key}' (available: {list(d.keys())})")
return d[key]
def _get_from_examples(filename):
direc = os.path.join(Path(orcasong.core.__file__).parents[1], "examples")
files = {file: os.path.join(direc, file) for file in os.listdir(direc)}
return _get_verbose(filename, files)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment