Skip to content

Commit

Permalink
Merge pull request #31 from FAST-HEP/BK_add_postproc_module
Browse files Browse the repository at this point in the history
Postproc: CLI option to control the column names used for values
  • Loading branch information
benkrikler authored Apr 20, 2020
2 parents da9fc0e + c1663d3 commit d8dcb17
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.1] - 2020-04-20
### Added
- Option to specify which columns contain bin values rather than labels, PR #31 [@benkrikler](github.com/benkrikler)

### Fixed
- Report package version number properly, PR #31

## [0.6.0] - 2020-04-17
### Added
- Proper support for non-constant interval widths
Expand Down
5 changes: 4 additions & 1 deletion fast_plotter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-

from .version import __version__, version_info


__all__ = ["__version__", "version_info"]
__author__ = """Ben Krikler"""
__email__ = 'fast-hep@cern.ch'
__version__ = '0.3.0'
2 changes: 2 additions & 0 deletions fast_plotter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import matplotlib
matplotlib.use('Agg')
from .version import __version__ # noqa
from .utils import read_binned_df, weighting_vars # noqa
from .utils import decipher_filename, mask_rows # noqa
from .plotting import plot_all, add_annotations # noqa
Expand Down Expand Up @@ -42,6 +43,7 @@ def arg_parser(args=None):
help="Scale the MC yields by this lumi")
parser.add_argument("-y", "--yscale", default="log", choices=["log", "linear"],
help="Use this scale for the y-axis")
parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)

def split_equals(arg):
return arg.split("=")
Expand Down
5 changes: 4 additions & 1 deletion fast_plotter/postproc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def make_parser():
help="A yaml to configure the post-processing step")
parser.add_argument("-o", "--outdir", default=".",
help="The name of the output directory")
parser.add_argument("-V", "--value-cols", default=r"(.*sumw2?|n)",
help="A regular expression to control which columns are"
" identified as values and not bin labels")
parser.add_argument("files", nargs="+",
help="Input dataframes that need merging together")
return parser
Expand Down Expand Up @@ -50,7 +53,7 @@ def main(args=None):
if args.debug_dfs:
logger.setLevel(logging.DEBUG)

dfs = open_many(args.files)
dfs = open_many(args.files, value_columns=args.value_cols)
sequence = read_processing_cfg(args.post_process, args.outdir)

for stage in sequence:
Expand Down
5 changes: 3 additions & 2 deletions fast_plotter/postproc/functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import six
import re
import numpy as np
import pandas as pd
import logging
Expand Down Expand Up @@ -365,15 +366,15 @@ def normalise_group(df, groupby_dimensions, apply_if=None, use_column=None):
return normed


def open_many(file_list, return_meta=True):
def open_many(file_list, value_columns=r"(.*sumw2?|n)", return_meta=True):
""" Open a list of dataframe files
"""
dfs = []
for fname in file_list:
df = pd.read_csv(fname, comment='#')
drop_cols = [col for col in df.columns if "Unnamed" in col]
df.drop(drop_cols, inplace=True, axis="columns")
index_cols = [col for col in df.columns if "sumw" not in col and col != "n"]
index_cols = [col for col in df.columns if not re.match(value_columns, col)]
df.set_index(index_cols, inplace=True, drop=True)
if return_meta:
name = fname
Expand Down
2 changes: 1 addition & 1 deletion fast_plotter/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ def split_version(version):
return tuple(result)


__version__ = '0.6.0'
__version__ = '0.6.1'
version_info = split_version(__version__) # noqa
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.6.0
current_version = 0.6.1
commit = True
tag = False

Expand Down

0 comments on commit d8dcb17

Please sign in to comment.