pygama.hit package

Routines for applying columnar transformations to tabular data. Specifically, to produce the hit-tier from the dsp-tier.

Submodules

pygama.hit.aggregations module

Utilities for working with bit-aggregation columns produced by build_hit().

pygama.hit.aggregations.unpack_bitmask(aggregation, bit_names=None)

Unpack a bit-aggregation column into an awkward record array.

The returned array has one boolean field per bit, with field names taken from bit_names or from the bit_names attribute of aggregation when it is an lgdo.LGDO. Bit i maps to bit_names[i], matching the encoding used by build_hit().

Works on flat columns (e.g. lgdo.Array) as well as jagged ones (e.g. lgdo.VectorOfVectors): the returned record array preserves the input shape.

Parameters:
  • aggregation (LGDO | ArrayLike) – a bit-aggregation column. Either an lgdo.LGDO carrying a bit_names attribute, or a plain integer numpy/awkward array — in the latter case bit_names must be passed explicitly.

  • bit_names (Iterable[str] | None) – ordered names for each bit. If None and aggregation is an lgdo.LGDO, names are read from its bit_names attribute (a comma-separated string).

Return type:

Array

pygama.hit.build_hit module

This module implements routines to evaluate expressions to columnar data.

pygama.hit.build_hit._get_dependencies(config, par, pars=None)

Recursive func to iterate back through tree of input blocks for a given output block

pygama.hit.build_hit._remove_uneeded_operations(config, outpars)

Function that removes any operations not needed to generate outpars from the config dictionary Returns the config without these blocks as well as a list of input keys from the dsp file needed to generate outpars

pygama.hit.build_hit._reorder_table_operations(config)

Reorder operations in config according to mutual dependency.

Return type:

OrderedDict[str, Mapping]

pygama.hit.build_hit.build_hit(infile, outfile=None, hit_config=None, lh5_tables=None, lh5_tables_config=None, n_max=inf, wo_mode='write_safe', buffer_len=3200)

Transform a Table into a new Table by evaluating strings describing column operations.

Operates on columns only, not specific rows or elements. Relies on eval().

Parameters:
  • infile (str) – input LH5 file name containing tables to be processed.

  • outfile (str | None) – name of the output LH5 file. If None, create a file in the same directory and append _hit to its name.

  • hit_config (str | Mapping | None) –

    dictionary or name of JSON file defining column transformations. Must contain an outputs and an operations keys. For example:

    {
      "outputs": ["calE", "AoE"],
      "operations": {
        "calE": {
          "expression": "sqrt(a + b * trapEmax**2)",
          "parameters": {"a": "1.23", "b": "42.69"},
        },
        "AoE": {"expression": "A_max/calE"},
      }
    }
    

    The outputs array lists columns that will be effectively written in the output LH5 file. Add here columns that will be simply forwarded as they are from the DSP tier.

  • lh5_tables (Iterable[str] | None) – tables to consider in the input file. if None, tables with name dsp will be searched for in the file, even nested by one level.

  • lh5_tables_config (str | Mapping[str, Mapping] | None) – dictionary or JSON file defining the mapping between LH5 tables in infile and hit configuration. Table names can be directly mapped to configuration blocks or to JSON files containing them. This option is mutually exclusive with hit_config and lh5_tables.

  • n_max (int) – maximum number of rows to process

  • wo_mode (str) – forwarded to lh5.io.core.write().