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

add feature: change first event/run number #96

Merged
merged 1 commit into from
Jan 10, 2024
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
27 changes: 26 additions & 1 deletion panama/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ def convert(self, value: int | str, param: Any, ctx: Any) -> int | dict[int, int
is_flag=True,
help="Save CORSIKAs std_out to a log file in output directory.",
)
@click.option(
"--first_run_number",
"-fr",
default=0,
help="Sets the first run number, for multiple output files, the number increments from that number.",
type=int,
)
@click.option(
"--first_event_number",
"-fe",
default=1,
help="Sets the first event number in each produced DAT file.",
type=int,
)
@click.option("--debug", "-d", default=False, is_flag=True, help="Enable debug output")
def run(
template: Path,
Expand All @@ -114,6 +128,8 @@ def run(
seed: int,
tmp: Path,
save_std: bool,
first_run_number: int,
first_event_number: int,
debug: bool,
) -> None:
"""
Expand Down Expand Up @@ -149,6 +165,15 @@ def run(
)

runner = CorsikaRunner(
primary, jobs, template, Path(output), corsika, p, seed, save_std
primary,
jobs,
template,
Path(output),
corsika,
p,
seed,
save_std,
first_run_number,
first_event_number,
)
runner.run()
11 changes: 7 additions & 4 deletions panama/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ def __init__(
corsika_tmp_dir: Path,
seed: None | int = None,
save_std: bool = False,
first_run_number: int = 0,
first_event_number: int = 1,
) -> None:
"""
TODO: Good Docstring, Types
TODO: Docstring

Parameters
----------
Expand All @@ -208,6 +210,8 @@ def __init__(
self.corsika_executable = Path(corsika_executable)
self.corsika_tmp_dir = Path(corsika_tmp_dir)
self.save_std = save_std
self.first_run_number = first_run_number
self.first_event_number = first_event_number

# we always need at least n_showers if we want to run n_jobs
if not all(n_jobs <= n_showers for n_showers in primary.values()):
Expand Down Expand Up @@ -301,11 +305,10 @@ def _get_corsika_config(
run_idx: int,
n_show: int,
primary_corsikaid: int,
first_event_idx: int = 1,
) -> dict[str, str]:
return {
"run_idx": f"{run_idx}",
"first_event_idx": f"{first_event_idx}",
"run_idx": f"{run_idx+self.first_run_number}",
"first_event_idx": f"{self.first_event_number}",
"n_show": f"{n_show}",
"dir": str(self.output.absolute()) + "/",
"seed_1": f"{randrange(1, 900_000_000)}",
Expand Down
47 changes: 47 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,53 @@ def test_cli_fast(
assert "DEBUG" in caplog.text


def test_cli_first_number(
tmp_path,
caplog,
test_file_path=Path(__file__).parent / "files" / "example_corsika_low_energy.template",
corsika_path=Path(__file__).parent.parent
/ CORSIKA_VERSION
/ "run"
/ CORSIKA_EXECUTABLE,
compare_files=Path(__file__).parent / "files" / "compare" / "DAT*",
):
runner = CliRunner()
result = runner.invoke(
cli,
[
"--debug",
"run",
f"{test_file_path}",
"--primary",
"2212", # proton
"-n",
"1",
"--corsika",
f"{corsika_path}",
"--output",
f"{tmp_path}",
"--seed",
"137",
"--jobs",
"1",
"--debug",
"-fr",
"42",
"-fe",
"420"
],
catch_exceptions=False
)

assert result.exit_code == 0

run_header_2, event_header_2, ps_2 = read_DAT(glob=f"{tmp_path}/DAT*")

assert event_header_2.shape[0] == 1
assert "DEBUG" in caplog.text
assert event_header_2.index[0] == (42, 420)


def test_cli_double_arg(
tmp_path,
caplog,
Expand Down
Loading