Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@

Small and thin Python interface to read [Les Houches Event (LHE)](https://inspirehep.net/literature/725284) files

## Why pylhe?

A small script can parse the basic particle records in a simple LHE file, but production files contain LHE3 weights and weight groups, scale and generator metadata, optional attributes and comments, compression, and generator-specific variations.
`pylhe` provides event-generator users and analysts with a maintained and tested implementation of these details, exposed through a common typed data model.
It supports streaming, writing, conversion between LHE and LHEH5, and integration with Awkward Array.

## Tested Monte Carlo Generators' LHE output

Expand Down
8 changes: 6 additions & 2 deletions src/pylhe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class LHEXMLFormat:
"""indentation string for XML output"""
compress: bool = False
"""compress as gzip"""
compresslevel: int = 9 # default as in the gzip library
"""gzip compression level"""
Comment thread
APN-Pucky marked this conversation as resolved.
Resolved

weights: LHEWeightFormat = LHEWeightFormat.RWGT

Expand Down Expand Up @@ -156,7 +158,9 @@ class LHEHDF5Format:
"""Output format with no WEIGHTS weights block and (default) plain text file format."""
HDF5_FORMAT = LHEHDF5Format()
"""Output format for HDF5-based LHEH5 files."""
HDF5_GZ_FORMAT = LHEHDF5Format(compression="gzip", compression_opts=4, shuffle=True)
HDF5_GZ_FORMAT = LHEHDF5Format(
compression="gzip", compression_opts=4, shuffle=True
) # HDF5 gzip compress level default is 4
"""Output format for HDF5-based LHEH5 files with gzip-compressed datasets."""


Expand Down Expand Up @@ -1359,5 +1363,5 @@ def _open_write_file(filepath: PathLike, lheformat: LHEXMLFormat) -> TextIO:
lheformat: The LHEXMLFormat to use for writing.
"""
if lheformat.compress:
return gzip.open(filepath, "wt")
return gzip.open(filepath, mode="wt", compresslevel=lheformat.compresslevel)
Comment thread
APN-Pucky marked this conversation as resolved.
Resolved
return open(filepath, "w")
Loading