Skip to content

Commit

Permalink
feat: allow create_ntuples utility to accept an output directory from…
Browse files Browse the repository at this point in the history
… a CLI (#508)

* Allow `create_ntuples` util script to accept output directory from CLI.
  • Loading branch information
MoAly98 authored Feb 28, 2025
1 parent 0ede4d9 commit 19ce6a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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()

0 comments on commit 19ce6a1

Please sign in to comment.