diff --git a/l2com/create-input-json-pulp2.sh b/l2com/create-input-json-pulp2.sh new file mode 100755 index 0000000000000000000000000000000000000000..6ecc223896dd8cdf3d31e8790b26585207fa769d --- /dev/null +++ b/l2com/create-input-json-pulp2.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# +# Script to create input JSON template for Pulp2 pipelines +# (for now 'Pulp2-folding' and 'Pulp2-redigitization') +# given the directory with the input data (.h5 and .raw) +# The output JSON will be printed out to stdout. +# +# Vlad Kondratiev (c) - 06-2025 +# +if [ $# -eq 0 ]; then + echo "Usage: $0 <Pulp2 code> <dir with .h5 files> [extra files filter, e.g. '_B000_' will select all fiels for Beam 0]" + echo " where <Pulp2 code> is:" + echo " 1 - Pulp2-redigitization" + echo " 2 - Pulp2-folding" + exit 0 +fi + +pulp2_code=$1 + +if [[ $# -gt 1 ]]; then + inputdir=$2 +else + echo "Error: You need to provide directory with .h5/.raw files!" + exit 1 +fi + +case $pulp2_code in + 1 | 2) + ;; + *) + echo "Error: unknown Pulp2 pipeline!" + exit 1 +esac + +if [[ $# -gt 2 ]]; then + inputfiles=`ls -1 ${inputdir} | grep h5 | grep $3` +else + inputfiles=`ls -1 ${inputdir} | grep h5` +fi + +is_next=0 + +echo "{" +echo " \"sasid\": \"\"," +case $pulp2_code in + 2) +echo " \"use_pdmp\": false," +echo " \"use_paz\": true," +echo " \"use_clfd\": true," +echo " \"nozap\": false," +echo " \"tsubint\": 5," +echo " \"sp_subint\": false," +echo " \"remove_dm_delays\": false," +echo " \"nbins\": 256," +echo " \"parfile\": null," +echo " \"parfile_string\": \"\"," +echo " \"get_parfile_from_psrcat\": true," +echo " \"extra_channels_factor\": 6," +echo " \"nthreads\": 8," + ;; + 1) +echo " \"output_dir\": \"8-bit\"," +echo " \"nsigma\": 5.1," + ;; +esac +echo " \"h5in\": [" + +for infile in $inputfiles; do + if [ $is_next -eq 1 ]; then + echo " ," + fi + echo " {" + echo " \"class\": \"File\", \"path\": \"${inputdir}/${infile}\"" + echo " }" + is_next=1 +done + +echo " ]" +echo "}" diff --git a/l2com/lofar_bf_h5info.py b/l2com/lofar_bf_h5info.py new file mode 100755 index 0000000000000000000000000000000000000000..7dc17ae1fd027e7af9af59b6ee900dda82f7aba9 --- /dev/null +++ b/l2com/lofar_bf_h5info.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +# +# Prints out the keys and attributes of the root group (/) of HDF5 metadata +# of the LOFAR BF .h5 file +# +# Vlad Kondratiev, ASTRON (c) - 28.05.2025 +# +import os, sys +import numpy as np +import argparse +import h5py + +if __name__ == "__main__": + # Read command line arguments + parser = argparse.ArgumentParser(prog='lofar_bf_h5info.py', usage='%(prog)s [options] <h5_file>', \ + description="Prints out keys/attrs of the Root group of HDF5 metadata") + parser.add_argument('h5_file', nargs='?', help='input .h5 file') + args = parser.parse_args(args=None if sys.argv[1:] else ['--help']) + + try: + h5 = h5py.File(args.h5_file) + group = h5["/"] + keys = sorted(["%s" % item for item in sorted(list(group.attrs))]) + for key in keys: + print(key + " = " + str(group.attrs[key])) + except FileNotFoundError as err: + print ("File not found:\n%s" % (err)) + sys.exit(1) +