diff --git a/km3io/utils/KModuleRates.py b/km3io/utils/KModuleRates.py index 58f3620f00a4422862a50c1b3118afd3ebdb1c12..3c8e5ed8dc8cfff3fdbd4c563670f359b13070c6 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