pythiaplotter.utils package¶
Submodules¶
pythiaplotter.utils.common module¶
Some common functions used throughout, like opening PDFs, file checking.
-
pythiaplotter.utils.common.
check_dir_exists_create
(filepath)[source]¶ Check if directory exists. If not, create it.
-
pythiaplotter.utils.common.
check_file_exists
(filepath)[source]¶ Check if file exists. Can do absolute or relative file paths.
-
pythiaplotter.utils.common.
check_module_exists
(module)[source]¶ Test if Python module exists.
Parameters: module (str) – Name of module to check Returns: Whether module exists Return type: bool
-
pythiaplotter.utils.common.
check_program_exists
(program)[source]¶ Test if external program can be found.
Parameters: program (str) – Program name Returns: Whether program is in PATH Return type: bool
-
pythiaplotter.utils.common.
check_representation_str
(representation, variable='representation')[source]¶ Check the representation string is valid, if not raise KeyError
-
pythiaplotter.utils.common.
cleanup_filepath
(filepath)[source]¶ Resolve any env vars, ~, return absolute path.
-
pythiaplotter.utils.common.
generate_repr_str
(obj, ignore=None)[source]¶ Generate a generic string for use in __repr__, with object fields and their value.
Can optionally ignore chosen fields.
Parameters: - obj (object) – Object to create repr string for
- ignore (list[str], optional) – Optional list of object field names to ignore
Returns: The repr string
Return type: str
-
pythiaplotter.utils.common.
get_directory
(filepath)[source]¶ Return absolute, full directory of file.
Resolve any environment vars, ~, sym links(?)
-
pythiaplotter.utils.common.
get_terminal_width
()[source]¶ Get the width of the user’s terminal. Requires tput.
-
pythiaplotter.utils.common.
map_columns_to_dict
(fields, line, delim=None)[source]¶ Split up line into fields, storing them in a dict.
Note that entreis are assumed to start at line[0], and thus any extra entries in the line are ignored.
>>> line = "123:police:999:Higgs" >>> fields = ["id", "name", "phone"] >>> map_columns_to_dict(fields, line, ":") {'id': '123', 'name': 'abc', 'phone': '999'}
Parameters: - fields (list[str]) – List of field names, MUST be in same order as the entries in line.
- line (str) – Line to be split and mapped into dict.
- delim (str, optional) – Optional delimiter to separate columns. Default is greedy whitespace, like for split(). For non-greedy whitepsace, use ‘ ‘.
Returns: dict {str – Dict of field names: values
Return type: str}
pythiaplotter.utils.logging_config module¶
Setup logging module here
We use a custom formatter which formats different severity levels differently.
-
class
pythiaplotter.utils.logging_config.
LevelFormatter
(fmt=None, datefmt=None, level_fmts=None)[source]¶ Bases:
logging.Formatter
Custom message formatter for different severity levels
Taken from: https://stackoverflow.com/questions/28635679/python-logging-different-formatters-for-the-same-log-file
pythiaplotter.utils.pdgid_converter module¶
Functions to provide TeX and normal (“raw”) particle names for a given PDGID.
Uses the PDGID for TeX names, and Pythia8 for normal names.
TODO: what if pdgid doesn’t exist?
TODO: deal with tex entries like: 25 h^0 / H_1^0
-
pythiaplotter.utils.pdgid_converter.
check_pdgid
(pdgid)[source]¶ Check if entry corresponding to given pdgid. If not, throw KeyError.
-
pythiaplotter.utils.pdgid_converter.
load_pdgid_dict
()[source]¶ Generate dictionary with PDGIDs and corresponding names e.g.
\pi^0, pi0
For each PDGID key, we store the tex and “raw” string names, for both particle and antiparticle
- Tex names taken from http://cepa.fnal.gov/psm/stdhep/numbers.shtml
Although based on 2006 PDG, so bit out of date! To add new particles, either add above or in pdg_all.tex
- String names use the ParticleData.xml file from Pythia8/xmldoc.
Have copied it into repo, although should probably ask user to link to it. Although the original
- it has lots of standard text crap before it
- there are typos where <particle ... ends with />, not > giving error !
So stick with mine for now...