From 2daf6f5e2a663343afa5fbd9710b0550730e844e Mon Sep 17 00:00:00 2001 From: Rodri <rgruiz0001@gmail.com> Date: Mon, 21 Feb 2022 17:24:27 +0100 Subject: [PATCH] optional command line options --- km3io/utils/KModuleRates.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/km3io/utils/KModuleRates.py b/km3io/utils/KModuleRates.py index 58f3620..3c8e5ed 100644 --- a/km3io/utils/KModuleRates.py +++ b/km3io/utils/KModuleRates.py @@ -1,12 +1,12 @@ """ -Usage: extract-dom-rates.py -f INPUT_FILE -o OUTPUT_FILE -a DETECTOR_FILE +Usage: extract-dom-rates.py -i INPUT_FILE [-o OUTPUT_FILE -d DETECTOR_FILE] Options: -h --help Help. - -f --input_file INPUT_FILE Input file. + -i --input_file INPUT_FILE Input file. -o --output_file OUTPUT_FILE Output file. - -a --detector_file DETECTOR_FILE Detector file. - -s --chunk_size CHUNK_SIZE Number of slices dumped to memory at once.[default: 10000] + -d --detector_file DETECTOR_FILE Detector file. + -s --chunk_size CHUNK_SIZE Number of slices dumped to memory at once. [default: 10000] """ from docopt import docopt @@ -16,7 +16,7 @@ import km3pipe.hardware import os import numpy as np import h5py - +from pathlib import Path def create_matrix(dom_ids, dom_rates, dom_map): rows = len(dom_map) @@ -53,8 +53,21 @@ def main(): for key in arguments: data[key.replace("-", "")] = arguments[key] + if (data["output_file"]==None): + data["output_file"]=Path(arguments['--input_file']).stem+'.rates.hdf5' # Read list of modules from detector file, and map to indices. - detector = km3pipe.hardware.Detector(data["detector_file"]) + + reader = km3io.online.SummarysliceReader(data["input_file"], 10000) + + dom_ids = [] + + if (data["detector_file"]==None): + print("No detector file supplied, analysing summaryslices to check for available module IDs.") + for s in reader.summaryslices: + dom_ids.append(np.unique(ak.flatten(s.slices.dom_id))) + np.unique(ak.flatten(dom_ids)) + else: + dom_ids=km3pipe.hardware.Detector(data["detector_file"]).dom_ids dom2index = {} index2dom = {} @@ -70,7 +83,6 @@ def main(): h5.create_dataset("frame_indices", (0,), maxshape=(None,)) # Read the channel rates from the summary slices, calculate the total module rates, and save them to the output file - reader = km3io.online.SummarysliceReader(data["input_file"], 10000) for ss_chunk in reader: frame_indices = ss_chunk.headers.frame_index -- GitLab