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

feat: allow create_ntuples utility to accept an output directory from a CLI #508

Merged
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
4 changes: 3 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from click.testing import CliRunner
import numpy as np
import pytest

Expand All @@ -22,7 +23,8 @@ def test_integration(tmp_path, ntuple_creator, caplog):
"""The purpose of this integration test is to check whether the
steps run without error and whether the fit result is as expected.
"""
ntuple_creator(str(tmp_path))
runner = CliRunner()
runner.invoke(ntuple_creator, ["--output_directory", str(tmp_path)])

cabinetry_config = cabinetry.configuration.load("config_example.yml")

Expand Down
16 changes: 12 additions & 4 deletions utils/create_ntuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os

import click
import matplotlib.pyplot as plt
import numpy as np
import uproot
Expand Down Expand Up @@ -151,7 +152,17 @@ def plot_distributions(data, weights, labels, pseudodata, bins):
plt.close()


@click.command()
@click.option(
"--output_directory",
type=str,
default="inputs/",
help="Output directory for ntuples used in simple example, useful for development.",
)
def run(output_directory, *, visualize=False):
# Create the output directory
if not os.path.exists(output_directory):
os.mkdir(output_directory)
# configuration
num_events = 5000
yield_s = 125
Expand Down Expand Up @@ -202,7 +213,4 @@ def run(output_directory, *, visualize=False):


if __name__ == "__main__":
output_directory = "inputs/"
if not os.path.exists(output_directory):
os.mkdir(output_directory)
run(output_directory)
run()