Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1220 filter and handle missing entries in the validation module #1223

Merged
Show file tree
Hide file tree
Changes from 4 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
25 changes: 23 additions & 2 deletions Validation/src/Validation/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
parser.add_argument('--param',
nargs='+',
help='parameter(s) in filename to use as file labels')
parser.add_argument('--input-file-filter', type=str,
help="""Filter which root files in the input data directory to
use using a regular expression""")
parser.add_argument('--input-files', nargs='+', type=str,
help="""Specify the name of the root files directly (either
full/relative path or name of files in the input data directory)""")

arg = parser.parse_args()

Expand Down Expand Up @@ -79,8 +85,23 @@

logging.debug(f'Deduced Args: label = {label} out_dir = {out_dir}')

root_files = [ File.from_path(os.path.join(data,f), legendlabel_parameter = arg.param)
for f in os.listdir(data) if f.endswith('.root') ]
if arg.input_files:
input_files = [os.path.join(data, f)
if not f.startswith(data)
else f
for f in arg.input_files
]
root_files = [File.from_path(f, legendlabel_parameter=arg.param)
for f in input_files]
else:
root_files = [ File.from_path(os.path.join(data,f), legendlabel_parameter = arg.param)
for f in os.listdir(data) if f.endswith('.root') ]

if arg.input_file_filter:
# Not sure if this can be done in one step so doing it in two
filtered_files = [f for f in root_files
if re.search(arg.input_file_filter, f.path) ]
root_files = filtered_files

logging.debug(f'ROOT Files: {root_files}')

Expand Down
7 changes: 6 additions & 1 deletion Validation/src/Validation/_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# external dependencies
import matplotlib.pyplot as plt
import matplotlib
import uproot
# us
from ._file import File

Expand Down Expand Up @@ -110,7 +111,11 @@ def plot1d(self, column, xlabel,
ax = fig.subplots()

for f in self.files :
weights, bins, patches = f.plot1d(ax, column, **hist_kwargs)
try:
weights, bins, patches = f.plot1d(ax, column, **hist_kwargs)
except uproot.KeyInFileError:
f.log.warn(f"Key {column} doesn't exist in {self}, skipping")
continue

ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
Expand Down
1 change: 1 addition & 0 deletions Validation/src/Validation/_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, filepath, colmod = None, hist_kwargs = dict(), **open_kwargs)
self.__file = uproot.open(filepath, **open_kwargs)
self.__colmod = colmod
self.__df = None
self.path = filepath
tomeichlersmith marked this conversation as resolved.
Show resolved Hide resolved

if 'histtype' not in hist_kwargs :
hist_kwargs['histtype'] = 'step'
Expand Down
Loading